local UnionFind={}

UnionFind.getroot=function(self,x)
    local rx=self.par[x]
    return rx==x and x or self:getroot(rx)
end

UnionFind.same=function(self,x,y)
    return self:getroot(x)==self:getroot(y)
end

UnionFind.unite=function(self,x,y)
    x=self:getroot(x)
    y=self:getroot(y)
    if x==y then
        return
    end
    if self.rank[x]>self.rank[y] then
        self.par[x]=y
        self.size[y]=self.size[y]+self.size[x]
    else
        if self.rank[x]==self.rank[y] then
            self.rank[x]=self.rank[x]+1
        end
        self.par[y]=x
        self.size[x]=self.size[x]+self.size[y]
    end
end

UnionFind.getsize=function(self,x)
    return self.size[self:getroot(x)]
end

UnionFind.new=function(self,n)
    local obj={par={},rank={},size={}}
    for i=1,n do
        obj.par[i]=i
        obj.rank[i]=1
        obj.size[i]=1
    end
    setmetatable(obj,{__index=UnionFind})
    return obj
end

----------

local n,k,l=io.read("n","n","n")
local road=UnionFind:new(n)
local rail=UnionFind:new(n)

for i=1,k do
    local p,q=io.read("n","n")
    road:unite(p,q)
end

for i=1,l do
    local r,s=io.read("n","n")
    rail:unite(r,s)
end

local counter={}
for i=1,n do
    local key=road:getroot(i).." "..rail:getroot(i)
    counter[key]=(counter[key] or 0)+1
end

for i=1,n do
    local key=road:getroot(i).." "..rail:getroot(i)
    io.write(counter[key].." ")
end
print()