//* Problem  : SLICICE
//* Origin   : COCI 2008-2009. Contest 6
//* Type     : Judge
//* Date     : 2009.10.11
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 9.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include "testlib.h"

using namespace std;

#define VI vector<int>

#define FOR(i,n) for (int i = 0; i < (int)(n); i++)

#define PB push_back
#define SZ(a) a.size()
#define MP make_pair
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<VI >

int res;

int n, m;

int a[128];

map<PII, int> mp;

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);

	n = inf.readInt();
	m = inf.readInt();
	for (int i = 1; i <= n; i++)
		a[i] = inf.readInt();
	FOR(i,m)
	{
		int p = inf.readInt();
		int q = inf.readInt();
		if (p > q) swap(p, q);
		mp[MP(p, q)]++;
	}
	int k = ouf.readInt();
	if (k < 0 || k > 1000)
		quitf(_wa, "Wrong total number of purchases: %d", k);
	FOR(i,k)
	{
		int p = ouf.readInt();
		int q = ouf.readInt();
		int w = ouf.readInt();
		a[p] -= w;
		a[q] -= 2-w;
		if (w < 0 || w > 2)
			quitf(_wa, "Wrong number of cards got by first child (%d) in line %d", w, i + 1);
		if (p > q) swap(p, q);
		mp[MP(p, q)]--;
	}
	for (int i = 1; i <= n; i++)
		if (a[i])
			quitf(_wa, "Wrong number of cards child %d = %d", i, a[i]);
	for (map<PII, int>::const_iterator it = mp.begin(); it != mp.end(); it++)
		if (it->second > 0)
			quitf(_wa, "Partial list not filled %d, %d", it->first.first, it->first.second);
	quitf(_ok, "OK chidren = %d, partial = %d, total = %d", n, m, k);
}