from collections import deque, Counter



N, K, L = [int(s) for s in input().split()]

edge_road = [[int(s) - 1 for s in input().split()] for _ in range(K)]

edge_train = [[int(s) - 1 for s in input().split()] for _ in range(L)]

graph_road = [[] for _ in range(N)]

graph_train = [[] for _ in range(N)]



for i, j in edge_road:

    graph_road[i].append(j)

    graph_road[j].append(i)



for i, j in edge_train:

    graph_train[i].append(j)

    graph_train[j].append(i)



group_road = [0] * N

group_num = 0



visited = [False]*N



for i in range(N):

    if visited[i]:

        continue

    dq = deque([i])

    group_road[i] = group_num

    visited[i] = True

    while(dq):

        search_obj = dq.pop()

        for candidate_obj in graph_road[search_obj]:

            if not visited[candidate_obj]:

                group_road[candidate_obj] = group_num

                dq.appendleft(candidate_obj)

                visited[candidate_obj] = True

    group_num += 1





group_train = [0] * N

group_num = 0



visited = [False]*N



for i in range(N):

    if visited[i]:

        continue

    dq = deque([i])

    group_train[i] = group_num

    visited[i] = True

    while(dq):

        search_obj = dq.pop()

        for candidate_obj in graph_train[search_obj]:

            if not visited[candidate_obj]:

                group_train[candidate_obj] = group_num

                dq.appendleft(candidate_obj)

                visited[candidate_obj] = True

    group_num += 1



group_count = Counter(zip(group_road, group_train))



for gr, gt in zip(group_road, group_train):

    print(group_count[(gr, gt)], end=' ')

N, M, L = [int(s) for s in input().split()]

parent_road = list(range(N))

parent_train = list(range(N))

rank_road = [0] * N

rank_train = [0] * N





class UnionFind:

    def __init__(self, n):

        self.parent = list(range(n))

        self.rank = [0] * N



    def find(self, x):

        if x == self.parent[x]:

            return x

        else:

            self.parent[x] = self.find(self.parent[x])

            return self.parent[x]



    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if self.rank[x] < self.rank[y]:

            self.parent[x] = y

        else:

            self.parent[y] = x

            if self.rank[x] == self.rank[y]:

                self.rank[x] += 1





edge_road = [[int(s) - 1 for s in input().split()] for _ in range(M)]

edge_train = [[int(s) - 1 for s in input().split()] for _ in range(L)]



group_road = UnionFind(N)

group_train = UnionFind(N)



for x, y in edge_road:

    group_road.union(x, y)



for x, y in edge_train:

    group_train.union(x, y)



group_count = {}

group_list = []

for i in range(N):

    gr = group_road.find(i)

    gt = group_train.find(i)

    group_list.append((gr, gt))

    if (gr, gt) in list(group_count.keys()):

        group_count[(gr, gt)] += 1

    else:

        group_count[(gr, gt)] = 1



print((' '.join([str(group_count[g]) for g in group_list])))



from collections import deque, Counter

N, K, L = [int(s) for s in input().split()]
edge_road = [[int(s) - 1 for s in input().split()] for _ in range(K)]
edge_train = [[int(s) - 1 for s in input().split()] for _ in range(L)]
graph_road = [[] for _ in range(N)]
graph_train = [[] for _ in range(N)]
for i, j in edge_road:
    graph_road[i].append(j)
    graph_road[j].append(i)
for i, j in edge_train:
    graph_train[i].append(j)
    graph_train[j].append(i)
group_road = [0] * N
group_num = 0
visited = [False] * N
for i in range(N):
    if visited[i]:
        continue
    dq = deque([i])
    group_road[i] = group_num
    visited[i] = True
    while dq:
        search_obj = dq.pop()
        for candidate_obj in graph_road[search_obj]:
            if not visited[candidate_obj]:
                group_road[candidate_obj] = group_num
                dq.appendleft(candidate_obj)
                visited[candidate_obj] = True
    group_num += 1
group_train = [0] * N
group_num = 0
visited = [False] * N
for i in range(N):
    if visited[i]:
        continue
    dq = deque([i])
    group_train[i] = group_num
    visited[i] = True
    while dq:
        search_obj = dq.pop()
        for candidate_obj in graph_train[search_obj]:
            if not visited[candidate_obj]:
                group_train[candidate_obj] = group_num
                dq.appendleft(candidate_obj)
                visited[candidate_obj] = True
    group_num += 1
group_count = Counter(zip(group_road, group_train))
for gr, gt in zip(group_road, group_train):
    print(group_count[(gr, gt)], end=" ")

N, M, L = [int(s) for s in input().split()]
parent_road = list(range(N))
parent_train = list(range(N))
rank_road = [0] * N
rank_train = [0] * N


class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * N

    def find(self, x):
        if x == self.parent[x]:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


edge_road = [[int(s) - 1 for s in input().split()] for _ in range(M)]
edge_train = [[int(s) - 1 for s in input().split()] for _ in range(L)]
group_road = UnionFind(N)
group_train = UnionFind(N)
for x, y in edge_road:
    group_road.union(x, y)
for x, y in edge_train:
    group_train.union(x, y)
group_count = {}
group_list = []
for i in range(N):
    gr = group_road.find(i)
    gt = group_train.find(i)
    group_list.append((gr, gt))
    if (gr, gt) in list(group_count.keys()):
        group_count[(gr, gt)] += 1
    else:
        group_count[(gr, gt)] = 1
print((" ".join([str(group_count[g]) for g in group_list])))

-from collections import deque, Counter +N, M, L = [int(s) for s in input().split()] +parent_road = list(range(N)) +parent_train = list(range(N)) +rank_road = [0] * N +rank_train = [0] * N -N, K, L = [int(s) for s in input().split()] -edge_road = [[int(s) - 1 for s in input().split()] for _ in range(K)] + +class UnionFind: +    def __init__(self, n): +        self.parent = list(range(n)) +        self.rank = [0] * N + +    def find(self, x): +        if x == self.parent[x]: +            return x +        else: +            self.parent[x] = self.find(self.parent[x]) +            return self.parent[x] + +    def union(self, x, y): +        x = self.find(x) +        y = self.find(y) +        if self.rank[x] < self.rank[y]: +            self.parent[x] = y +        else: +            self.parent[y] = x +            if self.rank[x] == self.rank[y]: +                self.rank[x] += 1 + + +edge_road = [[int(s) - 1 for s in input().split()] for _ in range(M)] -graph_road = [[] for _ in range(N)] -graph_train = [[] for _ in range(N)] -for i, j in edge_road: -    graph_road[i].append(j) -    graph_road[j].append(i) -for i, j in edge_train: -    graph_train[i].append(j) -    graph_train[j].append(i) -group_road = [0] * N -group_num = 0 -visited = [False] * N +group_road = UnionFind(N) +group_train = UnionFind(N) +for x, y in edge_road: +    group_road.union(x, y) +for x, y in edge_train: +    group_train.union(x, y) +group_count = {} +group_list = [] -    if visited[i]: -        continue -    dq = deque([i]) -    group_road[i] = group_num -    visited[i] = True -    while dq: -        search_obj = dq.pop() -        for candidate_obj in graph_road[search_obj]: -            if not visited[candidate_obj]: -                group_road[candidate_obj] = group_num -                dq.appendleft(candidate_obj) -                visited[candidate_obj] = True -    group_num += 1 -group_train = [0] * N -group_num = 0 -visited = [False] * N -for i in range(N): -    if visited[i]: -        continue -    dq = deque([i]) -    group_train[i] = group_num -    visited[i] = True -    while dq: -        search_obj = dq.pop() -        for candidate_obj in graph_train[search_obj]: -            if not visited[candidate_obj]: -                group_train[candidate_obj] = group_num -                dq.appendleft(candidate_obj) -                visited[candidate_obj] = True -    group_num += 1 -group_count = Counter(zip(group_road, group_train)) -for gr, gt in zip(group_road, group_train): -    print(group_count[(gr, gt)], end=" ") +    gr = group_road.find(i) +    gt = group_train.find(i) +    group_list.append((gr, gt)) +    if (gr, gt) in list(group_count.keys()): +        group_count[(gr, gt)] += 1 +    else: +        group_count[(gr, gt)] = 1 +print((" ".join([str(group_count[g]) for g in group_list])))