#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<pair<int,int>> solve(vector<int>&A, vector<int>& B) {
        int n = A.size();
        int MX = 0;
        for (int i = 0; i < n; ++i) {
            MX = max(MX, A[i]);
            MX = max(MX, B[i]);
        }
        int m = 0;
        while (1LL << (m + 1) <= MX) {
            ++m;
        }


        auto search = [&](string S, string& T) {
            vector<int> res;
            int n = S.length();
            S += S;
            // cout << S << " " << T << endl;
            int m = T.length();
            vector<int> next(m + 1, -1);
            for (int i = 0, j = -1; i < m; ++i) {
                while (j != -1 && T[j] != T[i]) {
                    j = next[j];
                }
                next[i + 1] = ++j;
            }

            for (int i = 0, j = 0; i < S.length(); ++i) {
                if (S[i] == T[j]) {
                    if (++j == m) {
                        int beg = i - m + 1;
                        if (beg < n) {
                            res.push_back(beg);
                        }
                        j = next[j];
                    }
                } else {
                    while (j != -1 && T[j] != S[i]) {
                        j = next[j];
                    }
                    if (j == -1) {
                        j = 0;
                        if (i + 1 >= n) {
                            break;
                        }
                    } else {
                        --i;
                    }
                }
            }
            return res;
        };

        vector<vector<int>> ok(n, vector<int>(m + 1, 0));

        string S(n, '0');
        string T(n, '0');
        for (int b = 0; b <= m; ++b) {
            for (int i = 0; i < n; ++i) {
                T[i] = '0' + ((B[i] >> b) & 1);
            }
            for (int j = 0; j < 2; ++j) {
                for (int i = 0; i < n; ++i) {
                    S[i] = '0' + (((A[i] >> b) & 0x1) ^ j);
                }
                auto P = search(S, T);
                for (auto p : P) {
                    ok[p][b] |= 1 << j;
                    // cout << p << " " << b << " " << j << endl;
                }
            }
        }

        vector<pair<int,int>> res;
        for (int i = 0; i < n; ++i) {
            int p = 1;
            for (int j = 0; j <= m; ++j) {
                p *= ok[i][j];
            }
            if (p == 0) {
                continue;
            }
            int X = 0;
            for (int j = 0; j <= m; ++j) { 
                if (ok[i][j] & 0x2) {
                    X |= 1 << j;
                }
            }
            res.emplace_back(i, X);
        }

        return res;
    } 
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n; 
    vector<int> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> B[i];
    }
    Solution sol;

    auto res = sol.solve(A, B);
    for (auto& p : res) {
        cout << p.first << " " << p.second << "\n";
    }

    return 0;
}

Measured memory_bytes: 35024