Scanf.scanf "%d %d %d" (fun n k l ->
    let rec root arr x =
        if x = arr.(x) then x else (
            let r = root arr arr.(x) in
            arr.(x) <- r;
            r
        )
    in

    let merge arr count x y =
        if root arr x <> root arr y then (
            count.(arr.(x)) <- count.(arr.(x)) + count.(arr.(y));
            arr.(arr.(y)) <- arr.(x);
        )
    in

    let road        = Array.init n (fun i -> i) in
    let train       = Array.init n (fun i -> i) in
    let road_count  = Array.make n 1 in
    let train_count = Array.make n 1 in
            
    for i = 1 to k do
        Scanf.scanf " %d %d" (fun p q ->
            let p = p - 1 in
            let q = q - 1 in
            merge road road_count p q
        )
    done;
    for i = 1 to l do
        Scanf.scanf " %d %d" (fun p q ->
            let p = p - 1 in
            let q = q - 1 in
            merge train train_count p q
        )
    done;
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let rec loop i map =
        if i = n then map else
            let r = root road  i in
            let t = root train i in
            let key = r * n + t in
            let map = M.add key (1 + try M.find key map with _ -> 0) map in
            loop (i + 1) map
    in
    let map = loop 0 M.empty in

    for i = 0 to n - 1 do
        let r = root road  i in
        let t = root train i in
        let key = r * n + t in
        Printf.printf "%d " @@ M.find key map
    done;
    print_newline ()
)