#include <vector>
#include <algorithm>

using namespace std;

void scc_dfs(int at, int &cnt, vector<int> &inum, vector<bool> &used, const vector<vector<int>> &graph)
{
    used[at] = true;
    for (int ne : graph[at]) {
        if (!used[ne]) scc_dfs(ne, cnt, inum, used, graph);
    }
    inum[cnt] = at;
    cnt++;
}

#include <iostream>
void scc_rdfs(int at, vector<int> &cs, vector<bool> &used, const vector<vector<int>> &inv)
{
    used[at] = true;
    cs.push_back(at);
    for (int ne : inv[at]) {
        if (!used[ne]) scc_rdfs(ne, cs, used, inv);
    }
}


vector<vector<int>> strongly_connected_components(const vector<vector<int>> &graph)
{
    const int V = graph.size();

    int cnt = 0;
    vector<int> inum(V);
    vector<bool> used(V);
    for (int i = 0; i < V; i++) {
        if (!used[i]) scc_dfs(i, cnt, inum, used, graph);
    }

    vector<vector<int>> inv(V);
    for (int i = 0; i < V; i++){
        for (int v : graph[i]) {
            inv[v].push_back(i);
        }
    }
    fill(used.begin(), used.end(), false);
    vector<vector<int>> ret;
    for (int i = V - 1; i >= 0; i--) {
        vector<int> cs;
        if (!used[inum[i]]) scc_rdfs(inum[i], cs, used, inv);
        ret.push_back(cs);
    }
    return ret;
}

#include <iostream>

int main()
{
    ios::sync_with_stdio(false);

    int V, E;
    cin >> V >> E;
    vector<vector<int>> graph(V);
    int s, t;
    for (int i = 0; i < E; i++) {
        cin >> s >> t;
        graph[s].push_back(t);
    }

    auto res = strongly_connected_components(graph);
    vector<int> num(V);
    for (int i = 0; i < res.size(); i++) {
        for (int v : res[i]) {
            num[v] = i;
        }
    }

    int Q;
    cin >> Q;
    int u, v;
    for (int i = 0; i < Q; i++) {
        cin >> u >> v;
        cout << (num[u] == num[v]) << endl;
    }
}
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


void bfs(int s, vector<vector<int>>& g, vector<int>& visited){
	queue<int> q;
	q.push(s);
	visited[s] = s;
	while (!q.empty()){
		int u = q.front(); q.pop();
		for (int v : g[u]){
			if (visited[v] < 0){
				visited[v] = s;
				q.push(v);
			}
		}
	}
}

signed main(){

	int N, K, L;
	vector<vector<int>> road, train;
	cin >> N >> K >> L;
	road.assign(N, vector<int>());
	train.assign(N, vector<int>());
	for (int i = 0; i < K; i++){
		int p, q;
		cin >> p >> q; p--; q--;
		road[p].push_back(q);
		road[q].push_back(p);
	}
	for (int i = 0; i < L; i++){
		int p, q;
		cin >> p >> q; p--; q--;
		train[p].push_back(q);
		train[q].push_back(p);
	}

	vector<int> visited_road(N), visited_train(N);
	visited_road.assign(N, -1);
	visited_train.assign(N, -1);

	for (int i = 0; i < N; i++){
		if (visited_road[i] < 0) bfs(i, road, visited_road);
		if (visited_train[i] < 0) bfs(i, train, visited_train);
	}

	map<pair<int, int>, int> cnt;
	for (int i = 0; i < N; i++){
		cnt[pair<int, int>(visited_road[i], visited_train[i])]++;
	}

	for (int i = 0; i < N; i++){
		cout << cnt[pair<int, int>(visited_road[i], visited_train[i])] << " ";
	}


	return 0;
}
