public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int times = Integer.parseInt(line.trim());
			for (int i = 0; i < times; i++) {
				in.readLine();
				int cells = Integer.parseInt(in.readLine().trim());
				Floyd f = new Floyd();
				f.inint(cells + 1);
				int exit = Integer.parseInt(in.readLine().trim());
				int tle = Integer.parseInt(in.readLine().trim());
				int con = Integer.parseInt(in.readLine().trim());
				for (int j = 0; j < con; j++) {
					int[] v = readInts(in.readLine());
					f.d[v[0]][v[1]] = v[2];
				}
				int ans = 0;
				f.floyd();
				for (int j = 1; j < f.d.length; j++)
					if (f.d[j][exit] <= tle)
						ans++;
				if (i != 0)
					out.append("\n");
				out.append(ans + "\n");
			}
		}
		System.out.print(out);
	}