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

class RollingHash
  def initialize(ary)
    @l = ary.size
    @b, @m = 1007, 10**9 + 7
    @h, @p = Array.new(@l + 1, 0), Array.new(@l + 1, 1)
    @l.times do |i|
      @h[i + 1] = (@h[i]*@b + ary[i]) % @m
      @p[i + 1] = (@p[i]* @b) % @m
    end
  end

  def get(l, r)
    (@h[r] - @h[l]*@p[r - l]) % @m
  end

  def lcp(rh, a, b)
    l, h = 0, @l + 1 - [a, b].max
    while h - l > 1
      m = (l + h)/2
      self.get(a, a + m) == rh.get(b, b + m) ? l = m : h = m
    end
    l
  end
end

ha, hb = [As, Bs].map{|ary| RollingHash.new(ary.cycle.each_cons(2).take(2*N).map{|x, y| x^y})}
(0 ... N).each{|k| puts "#{k} #{As[k]^Bs[0]}" if ha.lcp(hb, k, 0) >= N}