#include <bits/stdc++.h>
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()


#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{	rtn
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2], brr[N], a1[N], b1[N];

//mafia-->: hash_it
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l, int r) {
	uniform_int_distribution<int> uid(l, r);
	return uid(rang);
}
#define pii pair<int,int>

const int MAX_LEN = (int)1e6 + 7; // check it
pii p_pwr[MAX_LEN];
int p1 = 40, p2 = 34, mod1 = (int)1e9 + 9, mod2 = (int)1e7 + 79; // --> check it
int mxp = MAX_LEN - 1;

void pre()
{
	p_pwr[0].ff = 1; for (int i = 1; i < MAX_LEN; i++) p_pwr[i].ff = (1LL * p_pwr[i - 1].ff * p1) % mod1;
	p_pwr[0].ss = 1; for (int i = 1; i < MAX_LEN; i++) p_pwr[i].ss = (1LL * p_pwr[i - 1].ss * p2) % mod2;
}

inline int add(int a, int b, int &mod) {
	int res = (a + b);
	if ( res < 0 ) return res + mod;
	if ( res >= mod ) return res - mod;
	return res;

	res = a + b; if (res < 0) res += mod; return res >= mod ? res - mod : res;
}
inline int mul(int a, int b, int &mod) { int res = (1LL * a * b) % mod;   return res; }
inline int getval(int x) {    return  x + 1;    } // check  it( x-'a'+1)

class hash_it {
public:
	static int cnt;
	int len, d; vector<pii> hashes;

	void init(int *s, int d1, int l)
	{
		len = l; d = d1;
		hashes.resize(len + 1);
		for (int i = 0, val1 = 0, val2 = 0; i < len; i++)
		{
			val1 = add(val1, mul( getval(s[i]), p_pwr[i].ff, mod1), mod1);       hashes[i].ff = val1;
			if (d) val2 = add(val2, mul( getval(s[i]), p_pwr[i].ss, mod2), mod2);         hashes[i].ss = val2;
		}
	}

	// return hash_multiplied by p^mxp, if want actual hash use h1.
	pii  get(int i,  int j)
	{
		pii v1 = {0, 0};
		v1.ff = mul( add(hashes[j].ff, -(i ? hashes[i - 1].ff : 0), mod1), p_pwr[mxp - i].ff, mod1);
		if (d)v1.ss = mul( add(hashes[j].ss, -(i ? hashes[i - 1].ss : 0), mod2), p_pwr[mxp - i].ss, mod2);
		return v1;
	}

};


void prepre() {
	p1 = rng(31, 100), p2 = rng(31, 100); // check rangeb
	// p1 = 96;
	// // bug(p1);
	if ( p1 > 50 ) swap(mod1, mod2);
	mxp = MAX_LEN - 3;
	pre();
}


int rotate(int x2, int i)
{
	x2 = add(x2, -mul(getval(b1[n - i]), p_pwr[n - 1].ff, mod1), mod1);
	x2 = mul(x2, p1, mod1);
	x2 = add(x2, getval(b1[n - i]) % mod1, mod1);
	return x2;
}

void solve()
{
	cin >> n;
	lop(i, 0, n) cin >> arr[i];
	lop(i, 0, n) cin >> brr[i];

	lop(i, 0, n) a1[i] = (arr[i] ^ arr[ (i + 1) % n]);
	lop(i, 0, n) b1[i] = (brr[i] ^ brr[ (i + 1) % n]);

	// prarr(a1, 0, n);
	// prarr(b1, 0, n);
	hash_it h1, h2;
	h1.init(a1, 0, n);
	h2.init(b1, 0, n);

	int x1 = h1.hashes[n - 1].ff;
	int x2 = h2.hashes[n - 1].ff;
	// bug(x1, x2);

	vector<pii> vec;
	if ( x1 == x2 ) vec.pb({0, -1});
	for (int i = 1; i <= n; i++)
	{
		x2 = rotate(x2, i);
		if ( i < n and x2 == x1 ) vec.pb({i, -1});
	}
	// bug(x1, x2);
	for (auto &i : vec)
	{
		int x = (arr[i.ff] ^ brr[0]);
		i.ss = x;
	}

	for (auto &i : vec) cout << i.ff << " " << i.ss << endl;
	// cout << n << " " << vec.size() << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
	prepre();

#ifndef ONLINE_JUDGE
	// freopen("/Users/mafia/Downloads/random_03.txt",  "r",  stdin);
	// freopen("output.txt", "w", stdout);
#endif
	int test = 1;
	// cin >> test;
	while (test--)solve();


}





Measured memory_bytes: 35508