local mmi, mma = math.min, math.max
local mfl = math.floor
local xor = bit.bxor
-- local function xor(x, y) return x end

local n = io.read("*n")
local ar, br = {}, {}
for i = 1, n do
  ar[i] = io.read("*n")
end
for i = 1, n do
  br[i] = io.read("*n")
end
local as, bs = {}, {}
for i = 1, n - 1 do
  as[i], bs[i] = xor(ar[i], ar[i + 1]), xor(br[i], br[i + 1])
end
as[n], bs[n] = xor(ar[n], ar[1]), xor(br[n], br[1])
local idx = {}
local v = {}
for i = 1, n do
  idx[i] = i
  v[i] = as[i]
end
-- stage 1
table.sort(idx, function(a, b) return v[a] < v[b] end)
do
  local cur = 1
  local v_nxt = {}
  for i = 1, n do v_nxt[i] = 0 end
  v_nxt[idx[1]] = 1
  for i = 2, n do
    if v[idx[i]] ~= v[idx[i - 1]] then
      cur = cur + 1
    end
    v_nxt[idx[i]] = cur
  end
  for i = 1, n do v[i] = v_nxt[i] end
end
local step = 1
local vd = {}
while step < n do
  local stepdst = {}
  for i = 1, n do
    local dst = i + step
    if n < dst then dst = dst - n end
    stepdst[i] = dst
  end
  local left, major = 1, v[idx[1]]
  local minor_min = v[stepdst[idx[1]]]
  local minor_max = minor_min
  local cur = 0
  for i = 1, n do
    local isend = i == n or major ~= v[idx[i + 1]]
    if isend then
      local right = i
      if minor_min ~= minor_max then
        local t = {}
        for j = left, right do
          t[j - left + 1] = idx[j]
        end
        table.sort(t, function(x, y) return v[stepdst[x]] < v[stepdst[y]] end)
        local v_prv = 0
        for j = left, right do
          idx[j] = t[j - left + 1]
          local v_nxt = v[stepdst[idx[j]]]
          if j == left or v_nxt ~= v_prv then
            cur = cur + 1
          end
          vd[idx[j]] = cur
          v_prv = v_nxt
        end
      else
        cur = cur + 1
        for j = left, right do
          vd[idx[j]] = cur
        end
      end
      if i < n then
        left, major = i + 1, v[idx[i + 1]]
        minor_min = v[stepdst[idx[i + 1]]]
        minor_max = minor_min
      end
    else
      local minor = v[stepdst[idx[i]]]
      minor_min, minor_max = mmi(minor_min, minor), mma(minor_max, minor)
    end
  end
  for i = 1, n do v[i] = vd[i] end
  step = step * 2
end

local function comp_l(offset)
  for i = 1, n do
    local ai = offset - 1 + i
    if n < ai then ai = ai - n end
    if as[ai] < bs[i] then return true
    elseif bs[i] < as[ai] then return false
    end
  end
  return false
end

local function comp_u(offset)
  for i = 1, n do
    local ai = offset - 1 + i
    if n < ai then ai = ai - n end
    if bs[i] < as[ai] then return true
    elseif as[ai] < bs[i] then return false
    end
  end
  return false
end

local function lower_bound(ary)
  local num = #ary
  if num == 0 then return 1 end
  if not comp_l(ary[1]) then return 1 end
  if comp_l(ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp_l(ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local function upper_bound(ary)
  local num = #ary
  if num == 0 then return 1 end
  if comp_u(ary[1]) then return 1 end
  if not comp_u(ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp_u(ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local lb = lower_bound(idx)
local ub = upper_bound(idx)
local t = {}
for i = lb, ub - 1 do
  table.insert(t, idx[i])
end
table.sort(t)
for i = 1, #t do
  local k = t[i] - 1
  local v = xor(ar[t[i]], br[1])
  print(k .. " " .. v)
end
-- print(os.clock())
