There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.  We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly.  For each city, find the number of the cities connected to that city by both roads and railways.
def root(x,d):
    if d[x]==x:
        return x
    x=d[x]
    return root(d[x],d)
def unite(x,y,h,d):
    x=root(x,h)
    y=root(y,h)
    if x!=y:
        if h[x]<h[y]:
            h[x]=y
            d[y]+=1
        else:
            h[y]=x
            d[x]+=1
from collections import Counter
n,k,l=map(int,input().split())
a=[i for i in range(n+1)]
b=[i for i in range(n+1)]
u=[1]*(n+1)
r=[1]*(n+1)
for i in range(k):
    s,t=map(int,input().split())
    unite(s,t,a,u)
for i in range(l):
    s,t=map(int,input().split())
    unite(s,t,b,r)
k=list(zip(a,b))[1:]
d=Counter(k)
l=""
for i in range(n):
    l+=str(d[k[i]])+" "
print(l[:-1])
def root(x,d):
    if d[x]!=x:
        d[x]=root(d[x],d)
    return d[x]
def unite(x,y,h):
    x=root(x,h)
    y=root(y,h)
    if x!=y:
        h[x]=min(x,y)
        h[y]=h[x]
from collections import defaultdict
n,k,l=map(int,input().split())
a=[i for i in range(n+1)]
b=[i for i in range(n+1)]
for i in range(k):
    s,t=map(int,input().split())
    unite(s,t,a)
for i in range(l):
    s,t=map(int,input().split())
    unite(s,t,b)
d=defaultdict(int)
l=""
for i in range(1,n+1):
    d[(root(a[i],a),root(b[i],b))]+=1
for i in range(1,n+1):
    l+=str(d[(root(a[i],a),root(b[i],b))])+" "
print(l[:-1])