import sys



sys.setrecursionlimit(10**6)

def bps(gr,p,s,num):

    if gr[s]!=-1:

        return

    gr[s]=num

    for x in p[s]:

        bps(gr,p,x,num)



N,K,L=list(map(int,input().split()))

dic={}

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

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



for i in range(K):

    p,q=list(map(int,input().split()))

    road[p-1].append(q-1)

    road[q-1].append(p-1)



for i in range(L):

    r,s=list(map(int,input().split()))

    rail[r-1].append(s-1)

    rail[s-1].append(r-1)





roadG=[-1 for _ in range(N)]

num=0

for i in range(N):

    if roadG[i]==-1:

        bps(roadG,road,i,num)

        num+=1



railG=[-1 for _ in range(N)]

num=0

for i in range(N):

    if railG[i]==-1:

        bps(railG,rail,i,num)

        num+=1

dic={}

arr=[]

for i in range(N):

    key=roadG[i]*N+railG[i]

    arr.append(key)

    dic[key]=dic.setdefault(key,0)+1

print(dic[arr[0]],end='')

for x in arr[1:]:

    print(' {}'.format(dic[x]),end='')

print('')

import sys



sys.setrecursionlimit(10**6)

def dps(gr,p,s,num):

    if gr[s]!=-1:

        return

    gr[s]=num

    for x in p[s]:

        dps(gr,p,x,num)



N,K,L=list(map(int,input().split()))

dic={}

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

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



for i in range(K):

    p,q=list(map(int,input().split()))

    road[p-1].append(q-1)

    road[q-1].append(p-1)



for i in range(L):

    r,s=list(map(int,input().split()))

    rail[r-1].append(s-1)

    rail[s-1].append(r-1)





roadG=[-1 for _ in range(N)]

num=0

for i in range(N):

    if roadG[i]==-1:

        dps(roadG,road,i,num)

        num+=1



railG=[-1 for _ in range(N)]

num=0

for i in range(N):

    if railG[i]==-1:

        dps(railG,rail,i,num)

        num+=1

dic={}

arr=[]

for i in range(N):

    key=(roadG[i],railG[i])

    arr.append(key)

    dic[key]=dic.setdefault(key,0)+1

print((' '.join([str(dic[x]) for x in arr])))
import sys

sys.setrecursionlimit(10**6)


def bps(gr, p, s, num):
    if gr[s] != -1:
        return
    gr[s] = num
    for x in p[s]:
        bps(gr, p, x, num)


N, K, L = list(map(int, input().split()))
dic = {}
road = [[] for _ in range(N)]
rail = [[] for _ in range(N)]
for i in range(K):
    p, q = list(map(int, input().split()))
    road[p - 1].append(q - 1)
    road[q - 1].append(p - 1)
for i in range(L):
    r, s = list(map(int, input().split()))
    rail[r - 1].append(s - 1)
    rail[s - 1].append(r - 1)
roadG = [-1 for _ in range(N)]
num = 0
for i in range(N):
    if roadG[i] == -1:
        bps(roadG, road, i, num)
        num += 1
railG = [-1 for _ in range(N)]
num = 0
for i in range(N):
    if railG[i] == -1:
        bps(railG, rail, i, num)
        num += 1
dic = {}
arr = []
for i in range(N):
    key = roadG[i] * N + railG[i]
    arr.append(key)
    dic[key] = dic.setdefault(key, 0) + 1
print(dic[arr[0]], end="")
for x in arr[1:]:
    print(" {}".format(dic[x]), end="")
print("")

import sys

sys.setrecursionlimit(10**6)


def dps(gr, p, s, num):
    if gr[s] != -1:
        return
    gr[s] = num
    for x in p[s]:
        dps(gr, p, x, num)


N, K, L = list(map(int, input().split()))
dic = {}
road = [[] for _ in range(N)]
rail = [[] for _ in range(N)]
for i in range(K):
    p, q = list(map(int, input().split()))
    road[p - 1].append(q - 1)
    road[q - 1].append(p - 1)
for i in range(L):
    r, s = list(map(int, input().split()))
    rail[r - 1].append(s - 1)
    rail[s - 1].append(r - 1)
roadG = [-1 for _ in range(N)]
num = 0
for i in range(N):
    if roadG[i] == -1:
        dps(roadG, road, i, num)
        num += 1
railG = [-1 for _ in range(N)]
num = 0
for i in range(N):
    if railG[i] == -1:
        dps(railG, rail, i, num)
        num += 1
dic = {}
arr = []
for i in range(N):
    key = (roadG[i], railG[i])
    arr.append(key)
    dic[key] = dic.setdefault(key, 0) + 1
print((" ".join([str(dic[x]) for x in arr])))

-def bps(gr, p, s, num): +def dps(gr, p, s, num): -        bps(gr, p, x, num) +        dps(gr, p, x, num) -        bps(roadG, road, i, num) +        dps(roadG, road, i, num) -        bps(railG, rail, i, num) +        dps(railG, rail, i, num) -    key = roadG[i] * N + railG[i] +    key = (roadG[i], railG[i]) -print(dic[arr[0]], end="") -for x in arr[1:]: -    print(" {}".format(dic[x]), end="") -print("") +print((" ".join([str(dic[x]) for x in arr])))