N = gets.to_i
As, Bs = readlines.map{|l| l.split.map(&:to_i)}

f = ->(a){a.cycle.each_cons(2).take(N).map{|x, y| x^y}}
(0 ... N).select{|k| f[As].rotate(k) == f[Bs]}.each{|k| puts "#{k} #{Bs[0]^As[k]}"}