import Control.Monad
import Control.Monad.ST
import Data.Array.ST

data UnionFind s = UnionFind {ids:: STUArray s Int Int, szs:: STUArray s Int Int}

newUnionFind :: Int -> ST s (UnionFind s)
newUnionFind n = liftM2 UnionFind (newListArray (1,n) [1..n]) (newArray (1,n) 1)

find :: UnionFind s -> Int -> Int -> ST s Bool
find uf p q = liftM2 (==) (root uf p) (root uf q)

root :: UnionFind s -> Int -> ST s Int
root uf i = do
  ix <- readArray (ids uf) i
  if ix == i
    then return i
    else do
      writeArray (ids uf) i =<< readArray (ids uf) ix
      root uf ix

union :: UnionFind s -> [Int] -> ST s ()
union uf [p,q] = do
  i <- root uf p
  j <- root uf q
  szi <- readArray (szs uf) i
  szj <- readArray (szs uf) j
  if szi < szj
    then do
      writeArray (ids uf) i j
      writeArray (szs uf) j (szi+szj)
      writeArray (szs uf) i 0
    else do
      writeArray (ids uf) j i
      writeArray (szs uf) i (szj+szi)
      writeArray (szs uf) j 0

main = sub =<< get

sub [n,k,l] = sol n <$> replicateM k get <*> replicateM l get >>= put

get = fmap read . words <$> getLine

put = putStrLn . unwords . fmap show

sol n roads rails = runST $ do
  ufroad <- newUnionFind n
  forM roads (union ufroad) 
  ufrail <- newUnionFind n
  forM rails (union ufrail)
  let connected i j = liftM2 (&&) (find ufroad i j) (find ufrail i j)
  forM [1..n] $ (length <$>) . flip filterM [1..n] . connected