/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	
	public static int[] parent = new int[10000];
	public static int[] sz = new int[10000];

	public static void make(int i){
		parent[i] = i;
		sz[i] = 1;
	}
	
	public static int find(int i){
		if(parent[i] == i){
			return i;
		}else{
			return (parent[i] = find(parent[i]));
		}
	}
	
	public static void unite(int a, int b){
		int root1 = find(a);
		int root2 = find(b);
		
		if(root1 == root2){
			
		}else{
			if(sz[root1] < sz[root2]){
				int temp = root1;
				root1 = root2;
				root2 = temp;
			}
			parent[root2] = root1;
			sz[root1] = sz[root2] + sz[root1];
		}
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 1; i <= N; i++){
			make(i);
		}
		int E = sc.nextInt();
		int Q = sc.nextInt();
		int[] ans = new int[Q];
		
		int[][] edges = new int[E][3];
		for(int i = 0; i < E; i++){
			int u = sc.nextInt();
			edges[i][1] =  u;
			int v = sc.nextInt();
			edges[i][2] = v;
			int w = sc.nextInt();
			edges[i][0] = w;
			sc.nextLine();
		}
		
		Arrays.sort(edges, (a,b) -> Integer.compare(a[0], b[0]));
		
		int[][] queries = new int[Q][4];
		for(int i = 0; i < Q; i++){
			queries[i][3] = i;
			int u = sc.nextInt();
			queries[i][1] =  u;
			int v = sc.nextInt();
			queries[i][2] = v;
			int w = sc.nextInt();
			queries[i][0] = w;
		}
		Arrays.sort(queries, (a,b) -> Integer.compare(a[0], b[0]));
		
		int j = 0;
		for(int i = 0; i < E; i++){
			int w = edges[i][0];
			int u = edges[i][1];
			int v = edges[i][2];
			unite(u, v);
			if(i == E-1 || edges[i][0] != edges[i+1][0]){
				int left = edges[i][0];
				int right;
				if(i==E-1){
					right = 10000;
				}else{
					right = edges[i+1][0] - 1;
				}
				while(j <= Q - 1 && queries[j][0] <= right){
					if(queries[j][0] < left){
						
					}else{
						int node1 = queries[j][1];
						int node2 = queries[j][2];
						int idx = queries[j][3];
						
						if(find(node1) == find(node2)){
							ans[idx] = 1;
						}
					}
					j++;
				}
			}else{
				
			}
		}
		for(int x : ans){
			System.out.println(x);
		}
	}
}