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

public class attacks_bm_wa {
    FastScanner in;
    PrintWriter out;

    class Event {
        int where, when;

        public Event(int when, int where) {
            super();
            this.where = where;
            this.when = when;
        }

    }

    ArrayList<Integer>[] g;
    boolean[] was;
	ArrayList<Integer> topsort;

    void go(int v) {
        if (was[v])
            return;
        was[v] = true;
        for (int x : g[v]) {
            go(x);
        }
        topsort.add(v);
    }

    void solve() {
        int testN = in.nextInt();
        for (int t = 0; t < testN; t++) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();
            g = new ArrayList[m];
            for (int i = 0; i < m; i++)
                g[i] = new ArrayList<>();
            Event[] events = new Event[m];
            for (int i = 0; i < m; i++) {
                events[i] = new Event(in.nextInt(), in.nextInt() - 1);
            }
            int[][] d = new int[n][n];
            for (int i = 0; i < n; i++) {
                Arrays.fill(d[i], Integer.MAX_VALUE / 3);
                d[i][i] = 0;
            }
            for (int i = 0; i < k; i++) {
                int fr = in.nextInt() - 1;
                int to = in.nextInt() - 1;
                int cost = in.nextInt();
                d[fr][to] = Math.min(d[fr][to], cost);
                d[to][fr] = Math.min(d[to][fr], cost);
            }
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    for (int k1 = 0; k1 < n; k1++) {
                        int dd = d[j][i] + d[i][k1];
                        if (d[j][k1] > dd) {
                            d[j][k1] = dd;
                        }
                    }
            for (int i = 0; i < m; i++)
                for (int j = 0; j < m; j++)
                    if (d[events[i].where][events[j].where] < Integer.MAX_VALUE / 3) {
                        int dd = d[events[i].where][events[j].where];
                        if (events[j].when - events[i].when > dd) {
                            g[i].add(j);
                        }
                    }
            was = new boolean[m];
            topsort = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                go(i);
            }
            int res = 0;
			was = new boolean[m];
			int[] topsortPos = new int[m];
			for (int i = 0; i < m; i++) {
				topsortPos[topsort.get(i)] = i;
			}
			for (int i = topsort.size() - 1; i >= 0; i--) {
				int v = topsort.get(i);
				if (was[v])
					continue;
				res++;
				while (v != -1) {
					was[v] = true;
					int next = -1;
					for (int j : g[v]) {
						if (!was[j])
							if (next == -1 || topsortPos[j] > topsortPos[j])
								next = j;
					}
					v = next;
				}
			}
            out.println(res);
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("attacks.in"));
            out = new PrintWriter(new File("attacks.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

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