import java.io.*;
import java.util.*;

public class attacks_av {

	final int INF = Integer.MAX_VALUE / 2;

	public void solve() {
		int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(a[i], INF);
			a[i][i] = 0;
		}

		int[] time = new int[m], vertex = new int[m];
		for (int i = 0; i < m; i++) {
			time[i] = in.nextInt();
			vertex[i] = in.nextInt() - 1;
		}

		for (int i = 0; i < k; i++) {
			int from = in.nextInt() - 1, to = in.nextInt() - 1, cost = in
					.nextInt();
			a[from][to] = a[to][from] = Math.min(a[from][to], cost);
		}

		floyd(a);

		graph = new List[m];
		for (int i = 0; i < m; i++) {
			graph[i] = new ArrayList<>();
			for (int j = 0; j < m; j++) {
				if (time[j] - time[i] > a[vertex[i]][vertex[j]]) {
					graph[i].add(j);
				}
			}
		}

		int result = m - matching();
		out.println(result);
	}

	int[] match;
	boolean[] vis;

	private int matching() {
		int n = graph.length;
		match = new int[n];
		vis = new boolean[n];
		Arrays.fill(match, -1);

		int size = 0;
		for (int i = 0; i < n; i++) {
			Arrays.fill(vis, false);
			if (dfs(i)) {
				size++;
			}
		}
		return size;
	}

	private boolean dfs(int u) {
		if (vis[u]) {
			return false;
		}
		vis[u] = true;
		for (int t = 0; t < graph[u].size(); t++) {
			int v = graph[u].get(t);
			if (match[v] == -1 || (dfs(match[v]))) {
				match[v] = u;
				return true;
			}
		}
		return false;
	}

	List<Integer>[] graph;

	private void floyd(int[][] a) {
		for (int k = 0; k < a.length; k++) {
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < a.length; j++) {
					a[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);
				}
			}
		}
	}

	FastScanner in;
	PrintWriter out;

	public void run() {
		try {
			in = new FastScanner("attacks.in");
			out = new PrintWriter("attacks.out");
			int t = in.nextInt();
			for (int i = 0; i < t; i++) {
				solve();
			}
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String name) {
			try {
				br = new BufferedReader(new FileReader(name));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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