#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};



int main(){
    ll n;cin >> n;
    vl v(n),t(n);
    rep(i,n)cin >> v[i];
    rep(i,n)cin >> t[i];
    rep(i,n)t.pb(t[i]);
    vector<RollingHash> st,so,sa;
    rep(i,30){
        string l;
        rep(j,2*n){
            if(t[j]&(1<<i))l+='1';
            else  l+='0';
        }
        RollingHash rh(l);
        st.pb(rh);
    }
    rep(i,30){
        string l,a;
        rep(j,n){
            if(v[j]&(1<<i))l+='1';
            else  l+='0';
        }
        rep(j,n){
            if(v[j]&(1<<i))a+='0';
            else  a+='1';
        }
        RollingHash rh(l),rrh(a);
        so.pb(rh);sa.pb(rrh);
    } 
    vector<pl> ans;
    per(i,n){
        ll ret=0;
        rep(j,30){
            if(st[j].get(i,n+i)==so[j].get(0,n)){
            }
            else if(st[j].get(i,n+i)==sa[j].get(0,n)){
                ret+=1<<j;
            }
            else {
                ret=-1;break;
            };
        }
        if(ret==-1)continue;
        ans.pb({(n-i)%n,ret});
    }
    sort(all(ans));
    for(auto p:ans)cout << p.fi <<" " << p.se <<endl;
}

Measured memory_bytes: 774884