let iota ?(start=0) ?(step=1) cnt =
  let rec doit i acc =
    if i <= 0 then acc
    else doit (i - 1) (start + step*(i - 1) :: acc)
  in doit cnt []

let place_p x qs =
  let rec doit i = function
    | [] -> true
    | y :: _ when x = y + i || x = y - i -> false
    | _ :: ys -> doit (i + 1) ys
  in doit 1 qs

let killer_queen_p rc qs =
  let rec doit i = function
    | ([], _) -> true
    | (((r,_)::_ as rc), _::ys) when r <> i -> doit (i + 1) (rc, ys)
    | ((_,c)::xs, y::ys) when c = y -> doit (i + 1) (xs, ys)
    | _ -> false
  in doit 0 (rc, qs)

let print qs =
  let rec print_row i q =
    if i = 8 then print_newline ()
    else (print_string (if i = q then "Q" else "."); print_row (i + 1) q)
  in List.iter (fun q -> print_row 0 q) qs

let solve rc =
  let rec doit qs = function
    | [] -> if killer_queen_p rc qs then print qs
    | xs -> List.iter (fun x -> if place_p x qs then doit (x :: qs) (List.filter (fun e -> e <> x) xs)) xs
  in doit [] (iota 8)

let () =
  let k = read_int () in
  let rec read i acc =
    if i = k then List.sort (fun a b -> fst a - fst b) acc
    else read (i + 1) (Scanf.scanf "%d %d\n" (fun r c -> (r, c)) :: acc)
  in solve (read 0 [])