#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

struct num {
    static const int MA = 1e9 + 7, MB = 1e9 + 9;

    int a, b;

    num() { }
    num( int x ) : a(x), b(x) { }
    num( int a, int b ) : a(a), b(b) { }

    num operator + ( const num &x ) const { return num((a + x.a) % MA, (b + x.b) % MB); }
    num operator - ( const num &x ) const { return num((a + MA - x.a) % MA, (b + MB - x.b) % MB); }
    num operator * ( int x ) const { return num(((ll)a * x) % MA, ((ll)b * x) % MB); }
    num operator * ( const num &x ) const { return num(((ll)a * x.a) % MA, ((ll)b * x.b) % MB); }
    bool operator == ( const num &x ) const { return a == x.a && b == x.b; }
    bool operator != ( const num &x ) const { return !(a == x.a && b == x.b); }

};

template <class hash_t>
struct StrComparator {
    static const int P;
    static vector<hash_t> deg;

    int n;
    string s;
    hash_t *h;

    StrComparator( int n, string s ) : n(n), s(s) {
        h = new hash_t[n + 1];
        h[0] = 0;
        for (int i = 0; i < n; i++)
          h[i + 1] = h[i] * P + s[i];
        deg.reserve(n);
        while (deg.size() <= n)
          deg.push_back(*deg.rbegin() * P);
    }

    hash_t substr( int i, int len ) const { return h[i + len] - h[i] * deg[len]; }

    int lcp( int i, int j ) {
        int L = 0, R = n - max(i, j);
        while (L < R) {
          int M = (L + R + 1) / 2;
          if (substr(i, M) == substr(j, M))
            L = M;
          else
            R = M - 1;
        }
        return L;
    }

    int cmp( int a, int b ) {
        int LEN = n - max(a, b), L = lcp(a, b);
        return L < LEN ? (int)s[a + L] - s[b + L] : b - a;
    }

    bool operator() ( int i, int j ) { return cmp(i, j) < 0; }
};
template <class hash_t> vector <hash_t> StrComparator<hash_t>::deg(1, hash_t(1));
template <class hash_t> const int StrComparator<hash_t>::P = max(239, rand());

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <int> b(n);
    for (auto &i : a) cin >> i;
    for (auto &i : b) cin >> i;
    vector <bool> nice (n, true);
    for (int i = 0; i < 30; i++) {
        string c, d, e;
        for (int j = 0; j < n; j++) {
            if (a[j] & (1 << i)) {
                c += '0';
                d += '1';
            }
            else {
                c += '1';
                d += '0';
            }
            if (b[j] & (1 << i)) {
                e += '0';
            }
            else e += '1';
        }
        c += c;
        d += d;
        StrComparator<num> C(n + n, c);
        StrComparator<num> D(n + n, d);
        StrComparator<num> E(n, e);
        for (int j = 0; j < n; j++) {
            if (C.substr(j, n) != E.substr(0, n) && D.substr(j, n) != E.substr(0, n)) {
                nice[j] = false;
            }
        }
    }
    vector <pii> ans;
    for (int i = 0; i < n; i++) {
        if (nice[i]) {
            ans.pb({i, a[i] ^ b[0]});
        }
    }
    sort(all(ans));
    for (auto &i : ans) {
        cout << i.x << ' ' << i.y << '\n';
    }
}


Measured memory_bytes: 247800