import Debug.Trace
import Control.Monad
import Data.Maybe
import qualified Data.List as List
import qualified Data.Map as Map

base :: Int
base = 0

type Node = Int
type Score = Int
type Graph = Map.Map Int [Int]
type Dict = Map.Map Int Int

dfs :: Score -> Node -> Graph -> Dict -> Dict
dfs score curnode graph dict
  | List.null nextlist = last_dict
  | otherwise = foldl (\a b -> dfs score b graph a) last_dict nextlist
  where nextlist = fromMaybe [] $ Map.lookup curnode graph
        notyet = base == (fromMaybe base $ Map.lookup curnode dict)
        last_dict = if notyet then Map.insert curnode score dict else dict

search :: Score -> Node -> Graph -> Int -> Dict -> Dict
search score curnode graph maxnode dict
  | curnode == maxnode + 1 = dict
  | otherwise = search next_score next_nord graph maxnode next_dict
  where
    next_dict = dfs score curnode graph dict
    next_nord = curnode + 1
    next_score = score + 1

normalize :: Map.Map Int [Int] -> Int -> [Int]
normalize dict n = if List.null res then [] else res
                where res = fromMaybe [] (Map.lookup n dict)

makegraph :: Int -> [[Int]] -> Graph
makegraph n sorted_input = graph
  where g = List.groupBy (\a b -> (a !! 0) == (b !! 0)) sorted_input
        normed = map (\x -> ((x !! 0) !! 0, foldl (\a b -> (b !! 1):a) [] x)) g
        temp = Map.fromList normed
        graph = Map.fromList $ map (\x -> (x, normalize temp x)) [1..n]

ans :: [(Int, (Int, Int))] -> Dict -> Dict
ans tuplist dict = foldl (\a b -> Map.insert b l a) dict ind_list
            where l = length tuplist
                  ind_list = map fst tuplist

main = do
  n:k:l:[] <- (map read . words) <$> getLine :: IO [Int]

  input_k <- replicateM k $ (map read . words) <$> getLine :: IO [[Int]]
  let sorted_input_k = List.sort input_k

  input_l <- replicateM l $ (map read . words) <$> getLine :: IO [[Int]]
  let sorted_input_l = List.sort input_l

  let graph_k = makegraph n sorted_input_k
  let graph_l = makegraph n sorted_input_l

  let base_dict = Map.fromList []

  let tuple_k = Map.toList $ search (base + 1) 1 graph_k n base_dict
  let tuple_l = Map.toList $ search (base + 1) 1 graph_l n base_dict

  let tuple_ikl = List.zipWith (\a b -> (fst a, (snd a, snd b))) tuple_k tuple_l

  let sorted_tuple_ikl = List.sortBy (\a b -> compare (snd a) (snd b)) tuple_ikl
  let grouped_tuple_ikl = List.groupBy (\a b -> (==) (snd a) (snd b)) sorted_tuple_ikl

  let ans_dict = foldl (\a b -> ans b a) base_dict grouped_tuple_ikl
  let ans_list = map snd $ Map.toList ans_dict

  putStrLn $ unwords $ map show ans_list
