import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Validate {
	final int MAXN = 500;
	final int MAXTEST	= 100;
	final int MAXK = 100000;
	final int MAXM = 500;
        final int MAXT = 1000000;


	public void run() {
		StrictScanner inf = new StrictScanner(System.in);
		int test = inf.nextInt();
		inf.nextLine();
		ensureLimits(test, 1, MAXTEST, "incorrect t");
		int sumN = 0, sumK = 0, sumM = 0;
		for (int testN = 0; testN < test; testN++) {
			int n = inf.nextInt();
			int m = inf.nextInt();
			int k = inf.nextInt();
			inf.nextLine();
			sumN += n; sumK += k; sumM += m;
			ensureLimits(n, 1, MAXN, "incorrect n");
			ensureLimits(k, 1, MAXK, "incorrect k");
			ensureLimits(m, 1, MAXM, "incorrect m");
			ensureLimits(sumN, 1, MAXN, "incorrect sumn");
			ensureLimits(sumK, 1, MAXK, "incorrect sumk");
			ensureLimits(sumM, 1, MAXM, "incorrect summ");
			for (int i = 0; i < m; i++) {
				int t = inf.nextInt();
				int v = inf.nextInt();
				ensureLimits(t, 1, MAXT, line(i + 2));
				ensureLimits(v, 1, n, line(i + 1));
				inf.nextLine();
			}
			for (int i = 0; i < k; i++) {
				int a = inf.nextInt();
				int b = inf.nextInt();
				int c = inf.nextInt();
				ensureLimits(a, 1, n, line(i + 2 + m));
				ensureLimits(b, 1, n, line(i + 2 + m));
				ensure(a != b, line(i + 2 + m));
				ensureLimits(c, 1, MAXT, line(i + 2 + m));
					inf.nextLine();
			}
		}
		inf.close();
	}

	public static void main(String[] args) {
		new Validate().run();
	}

	public class StrictScanner {
		private final BufferedReader in;
		private String line = "";
		private int pos;
		private int lineNo;

		public StrictScanner(InputStream source) {
			in = new BufferedReader(new InputStreamReader(source));
			nextLine();
		}

		public void close() {
			ensure(line == null, "Extra data at the end of file");
			try {
				in.close();
			} catch (IOException e) {
				throw new AssertionError("Failed to close with " + e);
			}
		}

		public void nextLine() {
			ensure(line != null, "EOF");
			ensure(pos == line.length(), "Extra characters on line " + lineNo);
			try {
				line = in.readLine();
			} catch (IOException e) {
				throw new AssertionError("Failed to read line with " + e);
			}
			pos = 0;
			lineNo++;
		}

        	public String getNextLine() {
        	       String st = "";
			while (!isEoln()) {
				st = st + next();
			}
			return st;
		}


		public boolean isEoln() {
			return (pos == line.length());
		}

		public String next() {
			ensure(line != null, "EOF");
			ensure(line.length() > 0, "Empty line " + lineNo);
			if (pos == 0)
				ensure(line.charAt(0) > ' ', "Line " + lineNo
						+ " starts with whitespace");
			else {
				ensure(pos < line.length(), "Line " + lineNo + " is over");
				ensure(line.charAt(pos) == ' ', "Wrong whitespace on line "
						+ lineNo);
				pos++;
				ensure(pos < line.length(), "Line " + lineNo + " is over");
				ensure(line.charAt(0) > ' ', "Line " + lineNo
						+ " has double whitespace");
			}
			StringBuilder sb = new StringBuilder();
			while (pos < line.length() && line.charAt(pos) > ' ')
				sb.append(line.charAt(pos++));
			return sb.toString();
		}

		public int nextInt() {
			String s = next();
			ensure(s.length() == 1 || s.charAt(0) != '0',
					"Extra leading zero in number " + s + " on line " + lineNo);
			ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
					+ " on line " + lineNo);
			try {
				return Integer.parseInt(s);
			} catch (NumberFormatException e) {
				throw new AssertionError("Malformed number " + s + " on line "
						+ lineNo);
			}
		}

		public long nextLong() {
			String s = next();
			ensure(s.length() == 1 || s.charAt(0) != '0',
					"Extra leading zero in number " + s + " on line " + lineNo);
			ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
					+ " on line " + lineNo);
			try {
				return Long.parseLong(s);
			} catch (NumberFormatException e) {
				throw new AssertionError("Malformed number " + s + " on line "
						+ lineNo);
			}
		}

		public double nextDouble() {
			String s = next();
			ensure(s.length() == 1 || s.startsWith("0.") || s.charAt(0) != '0',
					"Extra leading zero in number " + s + " on line " + lineNo);
			ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
					+ " on line " + lineNo);
			try {
				return Double.parseDouble(s);
			} catch (NumberFormatException e) {
				throw new AssertionError("Malformed number " + s + " on line "
						+ lineNo);
			}
		}
	}

	public static class Geometry {
		/**
		 * Distance between two points (x1; y1) and (x2; y2)
		 * @param x1
		 * @param y1
		 * @param x2
		 * @param y2
		 * @return
		 */
		public static double dist(int x1, int y1, int x2, int y2) {
			long x3 = x1;
			long y3 = y1;
			long x4 = x2;
			long y4 = y2;
		       return Math.sqrt((x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4));
		}
	}
	
	public static class Graph {
		/**
		 * Adjacency matrix
		 * 0 or -1 if edge is empty
		 * other positive int if not
		 * @param e
		 * @return
		 */
		private static boolean dfsCheckForTree(int k, int p, boolean[] f, int[][] e) {
			f[k] = true;
			for (int i = 0; i < f.length; i++) {
				if (e[k][i] > 0 && !f[i]) {
					dfsCheckForTree(i, k, f, e);
				} else {
					if (e[k][i] > 0 && f[i] && i != p) {
						return false;
					}
				}
			}
			return true;
		}
		
		public static boolean isTree(int[][] e) {
			for (int i = 0; i < e.length; i++) {
				ensure(e[i].length == e.length, "Bad adjacency matrix given to class Graph");
			}
			ensure(e.length != 0, "Empty adjacency matrix given to class Graph");
			boolean[] visited = new boolean[e.length];
			if (!dfsCheckForTree(0, -1, visited, e)) ;
			boolean ans = true;
			for (int i = 0; i < e.length; i++) {
				ans &= visited[i]; 
			}
			return ans;
		}
	}

	static void ensure(boolean b, String message) {
		if (!b) {
			throw new AssertionError(message);
		}
	}

	void ensureString(String s, String alph, String text) {
		for (int i = 0; i < s.length(); i++) {
			ensure(alph.indexOf(s.charAt(i)) != -1, text);
		}
	}

	void ensureLimits(long n, long from, long to, String name) {
		ensure(from <= n && n <= to, name + " must be from " + from + " to "
				+ to);
	}

	void ensureLimits(int n, int from, int to, String name) {
		ensure(from <= n && n <= to, name + " must be from " + from + " to "
				+ to);
	}

	String line(int x) {
		return "Problem in line #" + Integer.toString(x);
	}

}

