import Control.Monad (replicateM)
import Data.List (intersperse, intersect)

main :: IO ()
main = do
  [n, k, l] <- fmap (map rInt . words) $ getLine
  ks <- fmap (map (map rInt . words)) $ getNLine_ k
  ls <- fmap (map (map rInt . words)) $ getNLine_ l
  (putStrLn . concat . intersperse " " . map show) $
    zipWith (\a b -> length $ intersect a b) (groupCity n ks) (groupCity n ls) 

groupCity :: Int -> [[Int]] -> [[Int]]
groupCity n [] = map (: []) [1..n]
groupCity n ([a,b]:xs) = if elem b (done !! (a-1))
                         then done
                         else foldr (\k dn -> myReplace k doneab dn) done doneab
  where done = groupCity n xs
        doneab = (done !! (a-1)) ++ (done !! (b-1))
        myReplace a l ls = take (a-1) ls ++ l : drop a ls

-- 複数行入力
getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine

-- 文字列を整数に
rInt :: String -> Int
rInt str = read str :: Int
