import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskF {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }
        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = in.nextInt();
        }

        ArrayList<Integer> aMoves = new ArrayList<Integer>();
        int[] aBase = gauss(A, aMoves);

        ArrayList<Integer> bMoves = new ArrayList<Integer>();
        int[] bBase = gauss(B, bMoves);

        ArrayList<Integer> changeMoves = new ArrayList<Integer>();
        int[] aux = new int[N];
        boolean ok = true;
        for (int i = 0; i < N && ok; i++) {
            int p = 0;
            int b = bBase[i];
            int a = 0;
            for (int j = i; j < N && aBase[j] != 0 && a != b; ) {
                int bit = Integer.bitCount(Integer.lowestOneBit(aBase[j]) - 1);
                if ((b & (1 << bit)) != (a & (1 << bit))) {
                    a ^= aBase[j];
                    aux[p++] = j;
                }
                else {
                    j++;
                }
            }

            if (a == b) {
                if (p > 0) {
                    if (aux[0] != i) {
                        addSwapMoves(aux[0], i, changeMoves);
                        int ax = aBase[0];
                        aBase[0] = aBase[aux[0]];
                        aBase[aux[0]] = ax;
                    }
                    for (int j = 1; j < p; j++) {
                        changeMoves.add(i); changeMoves.add(aux[j]);
                    }
                }
                else {
                    changeMoves.add(i); changeMoves.add(i);
                }
            }
            else {
                ok = false;
            }
        }

        if (!ok) {
            out.println(-1);
        }
        else {
            int totalMoves = (aMoves.size() + bMoves.size() + changeMoves.size()) / 2;
            out.println(totalMoves);
            for (int i = 0; i < aMoves.size(); i += 2) {
                out.println((aMoves.get(i) + 1) + " " + (aMoves.get(i + 1) + 1));
            }
            for (int i = 0; i < changeMoves.size(); i += 2) {
                out.println((changeMoves.get(i) + 1) + " " + (changeMoves.get(i + 1) + 1));
            }
            for (int i = bMoves.size() - 2; i >= 0; i -= 2) {
                out.println((bMoves.get(i) + 1) + " " + (bMoves.get(i + 1) + 1));
            }
        }
    }

    private int[] gauss(int[] A, ArrayList<Integer> moves) {
        int N = A.length;
        int[] base = new int[N];
        System.arraycopy(A, 0, base, 0, N);
        int k = 0;
        for (int j = 0; j < 30; j++) {
            int i = k;
            while (i < N && (base[i] & (1 << j)) == 0) {
                i++;
            }
            if (i == N) {
                continue;
            }

            if (i != k) {
                int aux = base[i];
                base[i] = base[k];
                base[k] = aux;
                addSwapMoves(i, k, moves);
            }

            for (int p = k + 1; p < N; p++) {
                if ((base[p] & (1 << j)) > 0) {
                    base[p] ^= base[k];
                    moves.add(p);
                    moves.add(k);
                }
            }

            k++;
        }

        return base;
    }

    private void addSwapMoves(int a, int b, ArrayList<Integer> moves) {
        moves.add(a); moves.add(b);
        moves.add(b); moves.add(a);
        moves.add(a); moves.add(b);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(ll i = (1ll << lg); i >= 1; i >>= 1)
			if(x & i) return i;
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, idx));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else x.to_do_list.pb(pii(p, j));
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list) cout<<p.fi + 1<<' '<<p.se + 1<<'\n';
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi + 1<<' '<<p.se + 1<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(int i = (1<<21); i >= 1; i /= 2){
			if(x & i) return i;
		}
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i);
	}
	x.sort();
	y.sort();
	//for(pii p : y.to_do_list) cout<<p.fi + 1<<' '<<p.se + 1<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list) cout<<p.fi + 1<<' '<<p.se + 1<<'\n';
//	cout<<"_____________"<<endl;
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi + 1<<' '<<p.se + 1<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int id[20];
	int bv[20];
	int m;
	int get_left(int x){
		for(ll i = (1ll << 20); i >= 1; i >>= 1)
			if(x & i) return i;
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, id[i]));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(id[i], idx));
			}
		bv[m] = x;
		id[m++] = idx;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(id[i], id[i + 1]));
				to_do_list.pb(pii(id[i + 1], id[i]));
				to_do_list.pb(pii(id[i], id[i + 1]));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i + 1);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i + 1);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(y.get_left(_y) == x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else x.to_do_list.pb(pii(x.id[p], x.id[j]));
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(x.id[i], x.id[i]));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list){
		cout<<p.fi<<' '<<p.se<<'\n';
	}
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi<<' '<<p.se<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 21;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
//	y.to_do_list.pb(pii(-1, -1));
//	x.to_do_list.pb(pii(-1, -1));
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
				}
				else {
					cout<<"@\n";
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort(x.m);
	y.sort(y.m);
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
				}
				else{
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort(x.m);
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 21;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort(x.m);
	y.sort(y.m);
//	y.to_do_list.pb(pii(-1, -1));
//	x.to_do_list.pb(pii(-1, -1));
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
				}
				else {
					cout<<"@\n";
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort(x.m);
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;

inline get_right(int x){
	return x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(int i = (1<<21); i >= 1; i /= 2){
			if(x & i) return i;
		}
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 21;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
//	y.to_do_list.pb(pii(-1, -1));
//	x.to_do_list.pb(pii(-1, -1));
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		cout<<"@"<<_y<<endl;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
					cout<<"@"<<j<<endl;
				}
				else {
					cout<<"@\n";
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(ll i = (1ll << lg); i >= 1; i >>= 1)
			if(x & i) return i;
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, idx));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i + 1);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i + 1);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else x.to_do_list.pb(pii(p, j));
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list){
		cout<<p.fi<<' '<<p.se<<'\n';
	}
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi<<' '<<p.se<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int id[lg + 1];
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(ll i = (1ll << lg); i >= 1; i >>= 1)
			if(x & i) return i;
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, id[i]));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(id[i], idx));
			}
		bv[m] = x;
		id[m++] = idx;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(id[i], id[i + 1]));
				to_do_list.pb(pii(id[i + 1], id[i]));
				to_do_list.pb(pii(id[i], id[i + 1]));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i + 1);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i + 1);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else x.to_do_list.pb(pii(x.id[p], x.id[j]));
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(x.id[i], x.id[i]));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list){
		cout<<p.fi<<' '<<p.se<<'\n';
	}
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi<<' '<<p.se<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(int i = (1<<21); i >= 1; i /= 2){
			if(x & i) return i;
		}
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int id[lg + 1];
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(ll i = (1ll << lg); i >= 1; i >>= 1)
			if(x & i) return i;
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, id[i]));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(id[i], idx));
			}
		bv[m] = x;
		id[m++] = idx;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(id[i], id[i + 1]));
				to_do_list.pb(pii(id[i + 1], id[i]));
				to_do_list.pb(pii(id[i], id[i + 1]));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	fastIO;
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		x.add(a, i + 1);
	}
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		y.add(a, i + 1);
	}
	x.sort();
	y.sort();
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(y.get_left(_y) == x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else x.to_do_list.pb(pii(x.id[p], x.id[j]));
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			cout<<-1<<endl;
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(x.id[i], x.id[i]));

		}
	}
	x.sort();
	cout<<x.to_do_list.size() + y.to_do_list.size()<<endl;
	for(pii p : x.to_do_list){
		cout<<p.fi<<' '<<p.se<<'\n';
	}
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) cout<<p.fi<<' '<<p.se<<'\n';
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 21;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		if(m > lg) cout<<'k'<<endl;
		return 1;
	}
	void sort(int e){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort(x.m);
	y.sort(y.m);
//	y.to_do_list.pb(pii(-1, -1));
//	x.to_do_list.pb(pii(-1, -1));
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
				}
				else {
					cout<<"@\n";
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort(x.m);
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(int i = (1<<21); i >= 1; i >>= 1){
			if(x & i) return i;
		}
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;

inline int get_right(int x){
	return  x == 0 ? (1<<lg) : x & -x;
}

struct space{
	vector<pii> to_do_list;
	int bv[lg];
	int m;
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_right(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_right(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
//		if(m > lg) cout<<'k'<<endl;
		return 1;
	}
	void sort(int e){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(get_right(bv[i]) > get_right(bv[i + 1])){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort(x.m);
	y.sort(y.m);
//	y.to_do_list.pb(pii(-1, -1));
//	x.to_do_list.pb(pii(-1, -1));
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & get_right(x.bv[j])){
				if(p == -1){
					p = j;
				}
				else {
					cout<<"@\n";
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		if(p != -1) mark[p] = true;
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]){
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));
		}
	}
	x.sort(x.m);
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include<bits/stdc++.h>
#define pb push_back
#define sz size
#define all(X) X.begin(),X.end()
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

template<class T>
bool smin(T &_x, T &_y){ return _x <= _y ? false : ((_x = _y), true);}
template<class T>
bool smax(T &_x, T &_y){ return _x >= _y ? false : ((_x = _y), true);}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;
const int inf  = 1e9;
const int mod = 1e9 + 7;
const int lg = 30;

bool mark[maxn];
int n;
struct space{
	vector<pii> to_do_list;
	int bv[lg + 1];
	int m;
	int get_left(int x){
		for(int i = (1<<21); i >= 1; i /= 2){
			if(x & i) return i;
		}
		return 0;
	}
	bool add(int x, int idx){
		for(int i = 0; i < m; i++)
			if(x & get_left(bv[i])){
				x ^= bv[i];
				to_do_list.pb(pii(idx, i));
			}
		if(x == 0) return 0;
		for(int i = 0; i < m; i++)
			if(bv[i] & get_left(x)){
				bv[i] ^= x;
				to_do_list.pb(pii(i, idx));
			}
		bv[m] = x;
		if(idx != m){
			to_do_list.pb(pii(m, idx));
			to_do_list.pb(pii(idx, m));
		}
		m++;
		return 1;
	}
	void sort(int e = n){
		if(e == 0) return;
		for(int i = 0; i < e - 1; i++){
			if(bv[i] < bv[i + 1]){
				to_do_list.pb(pii(i, i + 1));
				to_do_list.pb(pii(i + 1, i));
				to_do_list.pb(pii(i, i + 1));
				swap(bv[i], bv[i + 1]);
			}
		}
		sort(e - 1);
	}

} x, y;

int main(){
	//fastIO;
	scanf("%d", &n);
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		x.add(a, i);
	}
	for(int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		y.add(a, i);
	}
	x.sort();
	y.sort();
	if(n > 9 * 100 * 10) cout<<'g'<<endl;
	for(int i = 0; i < y.m; i++){
		int _y = y.bv[i], p = -1;
		for(int j = 0; j < x.m; j++){
			if(_y & x.get_left(x.bv[j])){
				if(p == -1) p = j;
				else {
					x.to_do_list.pb(pii(p, j));
					x.bv[p] ^= x.bv[j];
				}
				_y ^= x.bv[j];
			}
		}
		if(_y != 0){
			printf("-1\n");
			return 0;
		}
		mark[p] = true;
		x.bv[p] = y.bv[i];
	}
	for(int i = 0; i < x.m; i++){
		if(!mark[i]) {
			x.bv[i] = 0;
			x.to_do_list.pb(pii(i, i));

		}
	}
	x.sort();
	printf("%d\n", x.to_do_list.size() + y.to_do_list.size());
	for(pii p : x.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
	reverse(all(y.to_do_list));
	for(pii p : y.to_do_list) printf("%d %d\n", p.fi + 1, p.se + 1);
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef pair<int, int> pii;
	const int N = 1e4 + 10, M = 1e6 + 10, B = 31;
	bool check(const int a, const int p)
	{
		return a & (1 << p);
	}
	class Linear_Basis
	{
	private:
		int a[B], b[B], msk[B];
	public:
		Linear_Basis()
		{
			memset(a, 0, sizeof(a));
			memset(b, 0, sizeof(b));
			memset(msk, 0, sizeof(msk));
		}
		bool insert(int x, const int id)
		{
			int m = 0;
			for (int i = B - 1; i >= 0; i--)
				if (check(x, i))
				{
					if (b[i])
						x ^= a[i], m ^= msk[i];
					else
					{
						a[i] = x, b[i] = id, msk[i] = (m ^ (1 << i));
						return true;
					}
				}
			return false;
		}
		bool query(int x) const
		{
			for (int i = B - 1; i >= 0; i--)
				if (check(x, i))
				{
					if (b[i])
						x ^= a[i];
					else
						return false;
				}
			return true;
		}
		bool query(int x, vector<int> &v) const
		{
			v.clear();
			int m = 0;
			for (int i = B - 1; i >= 0; i--)
				if (check(x, i))
				{
					if (b[i])
						x ^= a[i], m ^= msk[i];
					else
						return false;
				}
			for (int i = 0; i < B; i++)
				if (check(m, i))
					v.push_back(b[i]);
			return true;
		}
	};
	typedef Linear_Basis LB;
	int n, x[N], y[N], cnt, id[N];
	pii ans[M];
	LB a, b;
	void swp(const int a, const int b)
	{
		if (a == b)
			return;
		ans[cnt++] = pii(a, b);
		ans[cnt++] = pii(b, a);
		ans[cnt++] = pii(a, b);
	}
	int work()
	{
		read(n);
		int p1 = 1, p2 = 1;
		for (int i = 1; i <= n; i++)
		{
			read(x[i]);
			if (a.insert(x[i], p1))
				swp(i, p1), swap(x[i], x[p1++]);
		}
		for (int i = 1; i <= n; i++)
		{
			read(y[i]);
			if (!a.query(y[i]))
			{
				puts("-1");
				return 0;
			}
			if (b.insert(y[i], p2))
				id[p2] = i, swap(y[i], y[p2++]);
		}
		for (int i = 1; i < p2; i++)
		{
			a = LB();
			for (int j = 1; j < i; j++)
				a.insert(y[j], j);
			for (int j = i; j <= p1; j++)
				a.insert(x[j], j);
			vector<int> tmp;
			a.query(y[i], tmp);
			if (find(tmp.begin(), tmp.end(), i) == tmp.end())
				for (auto &j : tmp)
					if (j >= i)
					{
						swp(i, j), swap(x[i], x[j]);
						j = i;
						break;
					}
			for (auto j : tmp)
				if (j != i)
					ans[cnt++] = pii(i, j);
		}
		for (int i = p2; i <= n; i++)
		{
			ans[cnt++] = pii(i, i);
			vector<int> tmp;
			b.query(y[i], tmp);
			for (auto j : tmp)
				ans[cnt++] = pii(i, j);
		}
		for (int i = p2 - 1; i > 0; i--)
			if (id[i])
				swp(i, id[i]);
		write(cnt), putchar('\n');
		for (int i = 0; i < cnt; i++)
			printf("%d %d\n", ans[i].first, ans[i].second);
		return 0;
	}
}
int main()
{
	return zyt::work();
}


#include <cstdio>
#include <vector>

#define MAXN 10009

struct myc {
    int x, y;
};
std::vector < myc > v, u;
int x[MAXN], y[MAXN], a[301], b[301], z[301];

inline void f(int a, int b, std::vector < myc > &v, int x[]) {
    v.push_back({a, b});
    x[a] ^= x[b];
}

inline void myswap(int a, int b, std::vector < myc > &v, int x[]) {
    f(a, b, v, x);
    f(b, a, v, x);
    f(a, b, v, x);
}

inline int gauss(int n, int x[], std::vector < myc > &v, int a[]) {
    int p = 1;
    for (int i = 29; i >= 0; i--) {
        int q = p;
        while (q <= n && (x[q] & (1 << i)) == 0)
            q++;
        if (q <= n) {
            if (p != q)
                myswap(p, q, v, x);
            for (int j = 1; j <= n; j++)
                if (j != p && (x[j] & (1 << i)))
                    f(j, p, v, x);
            a[p++] = i;
        }
    }
    return p - 1;
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
        scanf("%d", &x[i]);

    for (int i = 1; i <= n; i++)
        scanf("%d", &y[i]);

    int m = gauss(n, x, v, a);

    for (int i = 1; i <= m; i++)
        z[i] = y[i];

    int w = gauss(m, z, u, b);

    bool ok = 1;
    for (int i = m + 1; i <= n; i++) {
        for (int p = 1; p <= m; p++)
            if (y[i] & (1 << a[p]))
                f(i, p, v, x);
        if (x[i] != y[i])
            ok = 0;
    }

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++)
            if (i != j && (z[j] & (1 << a[i])) != (x[j] & (1 << a[i])))
                f(j, i, v, x);
        if ((z[i] & (1 << a[i])) != (x[i] & (1 << a[i])))
            f(i, i, v, x);
    }

    for (int i = 1; i <= m; i++)
        if (x[i] != z[i])
            ok = 0;

    if (ok) {
        printf("%u\n", v.size() + u.size());
        for (auto &x : v)
            printf("%d %d\n", x.x, x.y);
        for (int i = u.size() - 1; i >= 0; i--)
            printf("%d %d\n", u[i].x, u[i].y);
    } else
        printf("-1\n");

    return 0;
}


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

vector<pair<int, int>> gauss(vector<int>& x) {
    int frow = 0, n = x.size();
    vector<pair<int, int>> ret;
    for (int col = 30; col >= 0; --col) {
        int row = -1;
        for (int i = frow; i < n; ++i) {
            if (x[i] & (1 << col)) {
                row = i;
                break;
            }
        }
        if (row < 0)
            continue;
        if (row != frow) {
            swap(x[row], x[frow]);
            ret.emplace_back(row, frow);
            ret.emplace_back(frow, row);
            ret.emplace_back(row, frow);
        }
        row = frow++;
        for (int i = 0; i < n; ++i) {
            if (i != row && (x[i] & (1 << col))) {
                ret.emplace_back(i, row);
                x[i] ^= x[row];
            }
        }
    }
    return ret;
}

ostream &operator<<(ostream &os, vector<int> const &x) {
    os << '[';
    bool was = 0;
    for (int y : x) {
        if (was)
            os << ", ";
        was = 1;
        os << y;
    }
    return os << ']';
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> x(n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &x[i]);
    vector<int> y(n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &y[i]);
    auto wasx = x, wasy = y;
    auto r1 = gauss(x);
    //cerr << "here x = " << x << '\n';
    if (0) {
        auto xx = wasx;
        for (auto x : r1)
            xx[x.first] ^= xx[x.second];
        cerr << "after this x = " << xx << '\n';
    }
    auto r3 = gauss(y);
    reverse(r3.begin(), r3.end());
    auto all = x;
    all.insert(all.end(), y.begin(), y.end());
    //cerr << "x = " << x << ", y = " << y << ", all = " << all << '\n';
    gauss(all);
    //cerr << "all after gauss: " << all << '\n';
    for (int i = 0; i < n; ++i) {
        if (all[i] != x[i]) {
            cout << "-1\n";
            return 0;
        }
    }
    for (int i = n; i < n + n; ++i) {
        if (all[i] != 0) {
            cout << "-1\n";
            return 0;
        }
    }
    auto ans = r1;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            int v1 = x[i] ^ y[i], v2 = x[i] ^ x[j] ^ y[i];
            if (v1 > v2) {
                ans.emplace_back(i, j);
                x[i] ^= x[j];
            }
        }
    }
    ans.insert(ans.end(), r3.begin(), r3.end());
    cout << ans.size() << '\n';
    for (auto x : ans)
        cout << x.first + 1 << ' ' << x.second + 1 << '\n';
    /*for (auto p : ans) {
        wasx[p.first] ^= wasx[p.second];
    }
    cerr << "result: " << wasx << '\n';
    assert(wasx == wasy);*/
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
using namespace std;
inline int read()
{
	int x = 0, f = 1;
	char ch = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
	return x * f;
}
const int maxn = 10010;
vector<pair<int,int> > g,g1;
int a[maxn],b[maxn],fa[maxn],fb[maxn];
int n;
int main()
{
//	freopen("out.txt","w",stdout);
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) a[i] = read();
	for (int i = 1; i <= n; ++i) b[i] = read();
	for (int i = 1; i <= n; ++i)
	{
		int k = i;
		for (int j = i + 1; j <= n; ++j) k = a[j] > a[k]? j : k;
		if (k != i) g.PB(MP(i,k)),g.PB(MP(k,i)),g.PB(MP(i,k)),swap(a[i],a[k]);
		for (int j = 30; j >= 0; --j)
		if ((a[i] & (1<<j))) {fa[i] = 1<<j; break;}
		for (int j = 1; j <= n; ++j)
		if (i != j && (a[j] & fa[i])) g.PB(MP(j,i)),a[j] ^= a[i];

	}
	for (int i = 1; i <= n; ++i)
	{
		int k = i;
		for (int j = i + 1; j <= n; ++j) k = b[j] > b[k]? j : k;
		if (k != i) g1.PB(MP(i,k)),g1.PB(MP(k,i)),g1.PB(MP(i,k)),swap(b[i],b[k]);
		for (int j = 30; j >= 0; --j)
		if ((b[i] & (1<<j))) {fb[i] = 1<<j; break;}
		for (int j = 1; j <= n; ++j)
		if (i != j && (b[j] & fb[i])) g1.PB(MP(j,i)),b[j] ^= b[i];
	}
	for (int i = 1; i <= n; ++i)
	if (a[i] != b[i])
	{
		if (fa[i] < fb[i]) return puts("-1"),0;
		else if (fa[i] > fb[i])
		{
			g.PB(MP(i,i));
			fa[i] = 0;
			a[i] = 0;
			for (int j = i + 1; j <= n; ++j)
			{
				if (!a[j]) break;
				g.PB(MP(j - 1,j)),g.PB(MP(j,j - 1)), g.PB(MP(j - 1,j));
				swap(a[j],a[j - 1]); swap(fa[j],fa[j - 1]);
			}
			i--;
		}
		else
		{
			for (int j = i + 1; j <= n; ++j)
			{
				if (!a[j]) break;
				if (fa[j] & b[i]) g.PB(MP(i,j)),a[i] ^= a[j];
			}
			if (a[i] != b[i]) return puts("-1"),0;
		}
	}
	reverse(g1.begin(),g1.end());
	printf("%d\n",g.size() + g1.size());
	for (int i = 0; i < g.size(); ++i)
	printf("%d %d\n",g[i].FI,g[i].SE);
	for (int i = 0; i < g1.size(); ++i)
	printf("%d %d\n",g1[i].FI,g1[i].SE);
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
using namespace std;
inline int read()
{
	int x = 0, f = 1;
	char ch = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
	return x * f;
}
const int maxn = 10010;
vector<pair<int,int> > g,g1;
int a[maxn],b[maxn],fa[maxn],fb[maxn];
int n;
int main()
{
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) a[i] = read();
	for (int i = 1; i <= n; ++i) b[i] = read();
	for (int i = 1; i <= n; ++i)
	{
		int k = i;
		for (int j = i + 1; j <= n; ++j) k = a[j] > a[k]? j : k;
		if (k != i) g.PB(MP(i,k)),g.PB(MP(k,i)),g.PB(MP(i,k)),swap(a[i],a[k]);
		for (int j = 30; j >= 0; --j)
		if ((a[i] & (1<<j))) {fa[i] = 1<<j; break;}
		for (int j = 1; j <= n; ++j)
		if (i != j && (a[j] & fa[i])) g.PB(MP(j,i)),a[j] ^= a[i];

	}
	for (int i = 1; i <= n; ++i)
	{
		int k = i;
		for (int j = i + 1; j <= n; ++j) k = b[j] > b[k]? j : k;
		if (k != i) g1.PB(MP(i,k)),g1.PB(MP(k,i)),g1.PB(MP(i,k)),swap(b[i],b[k]);
		for (int j = 30; j >= 0; --j)
		if ((b[i] & (1<<j))) {fb[i] = 1<<j; break;}
		for (int j = 1; j <= n; ++j)
		if (i != j && (b[j] & fb[i])) g1.PB(MP(j,i)),b[j] ^= b[i];
	}
	for (int i = 1; i <= n; ++i)
	if (a[i] != b[i])
	{
		if (fa[i] < fb[i]) return puts("-1"),0;
		else if (fa[i] > fb[i])
		{
			g.PB(MP(i,i));
			fa[i] = 0;
			a[i] = 0;
			for (int j = i + 1; j <= n; ++j)
			{
				if (!a[j]) break;
				g.PB(MP(j - 1,j)),g.PB(MP(j,j - 1)), g.PB(MP(j - 1,j));
				swap(a[j],a[j - 1]); swap(fa[j],fa[j - 1]);
			}
			i--;
		}
		else
		{
			for (int j = i + 1; j <= n; ++j)
			{
				if (!a[j]) break;
				if (fa[j] & b[i]) g.PB(MP(i,j)),a[i] ^= a[j];
			}
			if (a[i] != b[i]) return puts("-1"),0;
		}
	}
	reverse(g1.begin(),g1.end());
	printf("%d\n",g.size() + g1.size());
	for (int i = 0; i < g.size(); ++i)
	printf("%d %d\n",g[i].FI,g[i].SE);
	for (int i = 0; i < g1.size(); ++i)
	printf("%d %d\n",g1[i].FI,g[i].SE);
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
void get(int id , int val , int idx){
    int lol = 1 << LN;
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            if(a[id] & (1 << i)){

            }
            else{
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
        }
        else{
            if(a[id] & (1 << i)){
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
            else{

            }
        }
        lol |= 1 << i;
    }
    if(a[id] != val){
        printf("-1\n");
        exit(0);
    }
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    if(n >= 2 * LN){
        for(int i = 1 ; i <= b2 ; ++i){
            get(n - i + 1 , b[i] , b1);
        }
        for(int i = n - b2 ; i >= 1 ; --i){
            a[i] ^= a[i];
            va.emplace_back(make_pair(i , i));
        }
        int l = n - b2 + 1;
        int r = n;
        while(l < r){
            a[l] ^= a[r];
            a[r] ^= a[l];
            a[l] ^= a[r];
            va.emplace_back(make_pair(l , r));
            va.emplace_back(make_pair(r , l));
            va.emplace_back(make_pair(l , r));
            ++l;
            --r;
        }
        l = 1;
        r = n - b2 + 1;
        if(l != r){
            while(r <= n){
                a[l] ^= a[r];
                a[r] ^= a[l];
                a[l] ^= a[r];
                va.emplace_back(make_pair(l , r));
                va.emplace_back(make_pair(r , l));
                va.emplace_back(make_pair(l , r));
                ++r;
                ++l;
            }
        }
    }
    else{
        for(int i = 1 ; i <= b2 ; ++i){
            get(i , b[i] , b1);
        }
        for(int i = b2 + 1 ; i <= n ; ++i){
            a[i] ^= a[i];
            va.emplace_back(make_pair(i , i));
        }
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
set < int > get(int val){
    int lol = 1 << LN;
    int idx = 1;
    set < int > res;
    res.clear();
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            while(a[idx] & lol){
                ++idx;
            }
            if(a[idx] & (1 << i)){
                val ^= a[idx];
                res.insert(idx);
            }
            else{
                printf("-1\n");
                exit(0);
            }
        }
        lol |= 1 << i;
    }
    return res;
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    for(int i = 1 ; i <= b2 ; ++i){
        auto it = get(b[i]);
        if(it.find(i) == it.end()){
            it.insert(i);
        }
        else{
            it.erase(i);
        }
        for(auto x : it){
            a[i] ^= a[x];
            va.emplace_back(make_pair(i , x));
        }
    }
    for(int i = b2 + 1 ; i <= n ; ++i){
        a[i] ^= a[i];
        va.emplace_back(make_pair(i , i));
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
void get(int id , int val , int idx){
    int lol = 1 << LN;
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            if(a[id] & (1 << i)){

            }
            else{
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
        }
        else{
            if(a[id] & (1 << i)){
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
            else{

            }
        }
        lol |= 1 << i;
    }
    if(a[id] != val){
        printf("-1\n");
        exit(0);
    }
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    for(int i = 1 ; i <= b2 ; ++i){
        get(i , b[i] , b1);
    }
    for(int i = b2 + 1 ; i <= n ; ++i){
        a[i] ^= a[i];
        va.emplace_back(make_pair(i , i));
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
set < int > get(int val){
    int lol = 1 << LN;
    int idx = 1;
    set < int > res;
    res.clear();
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            while(a[idx] & lol){
                ++idx;
            }
            if(a[idx] & (1 << i)){
                val ^= a[idx];
                res.insert(idx);
            }
            else{
                printf("-1\n");
                exit(0);
            }
        }
        lol |= 1 << i;
    }
    return res;
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    for(int i = 1 ; i <= b2 ; ++i){
        auto it = get(b[i]);
        if(it.find(i) == it.end()){
            it.insert(i);
            assert(i == *it.begin());
        }
        else{
            it.erase(i);
        }
        for(auto x : it){
            a[i] ^= a[x];
            va.emplace_back(make_pair(i , x));
        }
    }
    for(int i = b2 + 1 ; i <= n ; ++i){
        a[i] ^= a[i];
        va.emplace_back(make_pair(i , i));
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(!done[j] && arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
void get(int id , int val , int idx){
    int lol = 1 << LN;
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            if(a[id] & (1 << i)){

            }
            else{
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
        }
        else{
            if(a[id] & (1 << i)){
                for(int j = 1 ; j <= idx ; ++j){
                    if(!(lol & a[j])){
                        if(a[j] & (1 << i)){
                            a[id] ^= a[j];
                            va.emplace_back(make_pair(id , j));
                            break;
                        }
                    }
                }
            }
            else{

            }
        }
        lol |= 1 << i;
    }
    if(a[id] != val){
        printf("-1\n");
        exit(0);
    }
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    if(n >= 2 * LN){
        for(int i = 1 ; i <= b2 ; ++i){
            get(n - i + 1 , b[i] , b1);
        }
        for(int i = n - b2 ; i >= 1 ; --i){
            a[i] ^= a[i];
            va.emplace_back(make_pair(i , i));
        }
        int l = n - b2 + 1;
        int r = n;
        while(l < r){
            a[l] ^= a[r];
            a[r] ^= a[l];
            a[l] ^= a[r];
            va.emplace_back(make_pair(l , r));
            va.emplace_back(make_pair(r , l));
            va.emplace_back(make_pair(l , r));
            ++l;
            --r;
        }
        l = 1;
        r = n - b2 + 1;
        if(l != r){
            while(r <= n){
                a[l] ^= a[r];
                a[r] ^= a[l];
                a[l] ^= a[r];
                va.emplace_back(make_pair(l , r));
                va.emplace_back(make_pair(r , l));
                va.emplace_back(make_pair(l , r));
                ++r;
                ++l;
            }
        }
    }
    else{
        for(int i = 1 ; i <= b2 ; ++i){
            get(i , b[i] , b1);
        }
        for(int i = b2 + 1 ; i <= n ; ++i){
            a[i] ^= a[i];
            va.emplace_back(make_pair(i , i));
        }
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


#include "bits/stdc++.h"
using namespace std;
const int N = 1e4 + 4;
const int LN = 30;
int n;
int a[N];
int b[N];
bool done[N];
vector < pair < int , int > > va;
vector < pair < int , int > > vb;
int solve(int arr[] , vector < pair < int , int > > &res){
    for(int i = 1 ; i <= n ; ++i){
        done[i] = 0;
    }
    for(int i = LN - 1 ; i >= 0 ; --i){
        int idx = -1;
        for(int j = 1 ; j <= n ; ++j){
            if(!done[j] && arr[j] & (1 << i)){
                idx = j;
                break;
            }
        }
        if(idx != -1){
            done[idx] = 1;
            for(int j = 1 ; j <= n ; ++j){
                if(!done[j] && (arr[j] & (1 << i))){
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                }
            }
        }
    }
    int idx = 1;
    for(int i = LN - 1 ; i >= 0 ; --i){
        for(int j = idx ; j <= n ; ++j){
            if(arr[j] & (1 << i)){
                if(j != idx){
                    arr[j] ^= arr[idx];
                    arr[idx] ^= arr[j];
                    arr[j] ^= arr[idx];
                    res.emplace_back(make_pair(j , idx));
                    res.emplace_back(make_pair(idx , j));
                    res.emplace_back(make_pair(j , idx));
                }
                ++idx;
                break;
            }
        }
    }
    for(int i = idx ; i <= n ; ++i){
        arr[i] ^= arr[i];
        res.emplace_back(make_pair(i , i));
    }
    return idx - 1;
}
set < int > get(int val){
    int lol = 1 << LN;
    int idx = 1;
    set < int > res;
    res.clear();
    for(int i = LN - 1 ; i >= 0 ; --i){
        if(val & (1 << i)){
            while(a[idx] & lol){
                ++idx;
            }
            if(a[idx] & (1 << i)){
                val ^= a[idx];
                res.insert(idx);
            }
            else{
                printf("-1\n");
                exit(0);
            }
        }
        lol |= 1 << i;
    }
    return res;
}
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , a + i);
    }
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , b + i);
    }
    int b1 = solve(a , va);
    int b2 = solve(b , vb);
    for(int i = 1 ; i <= b2 ; ++i){
        auto it = get(b[i]);
        if(it.find(i) == it.end()){
            it.insert(i);
        }
        else{
            it.erase(i);
        }
        for(auto x : it){
            a[i] ^= a[x];
            va.emplace_back(make_pair(i , x));
        }
    }
    for(int i = b2 + 1 ; i <= n ; ++i){
        a[i] ^= a[i];
        va.emplace_back(make_pair(i , i));
    }
    printf("%d\n" , int(va.size()) + int(vb.size()));
    for(auto it : va){
        printf("%d %d\n" , it.first , it.second);
    }
    reverse(vb.begin() , vb.end());
    for(auto it : vb){
        printf("%d %d\n" , it.first , it.second);
    }
}


# include <iostream>
# include <stdio.h>
# include <stdlib.h>

using namespace std;

char s[10000];

int main()
{
	int sl = 0;
	bool num = true;
	for(char c = getchar(); c != '\n'; c = getchar())
	{
		if (c == ' ')
		{
			num = true;
		}
		else if (c == ',')
		{
			s[sl++] = ',';
			s[sl++] = ' ';
			num = false;
		}
		else if (c == '.')
		{
			if (((sl > 0 && s[sl - 1] != '.') || (sl > 2 && s[sl - 1] == '.' && s[sl - 2] == '.' && s[sl - 3] == '.'))
				&& s[sl - 1] != ' ')
				s[sl++] = ' ';
			s[sl++] = '.';
			num = true;
		}
		else if (isdigit(c))
		{
			if (num && sl > 0 && s[sl - 1] != ' ')
				s[sl++] = ' ';
			num = false;
			s[sl++] = c;
		}
	}

	while (s[sl - 1] == ' ')
		--sl;

	for (int i = 0; i < sl; ++i)
		cout << s[i];
	cout << endl;

	return 0;
}


# include <iostream>
# include <stdio.h>
# include <stdlib.h>

using namespace std;

char s[10000];

int main()
{
	int sl = 0;
	bool num = true;
	for(char c = getchar(); c != '\n'; c = getchar())
	{
		if (c != ' ')
		{
			if (c == ',')
			{
				s[sl++] = ',';
				s[sl++] = ' ';
			}
			else if (c == '.')
			{
				if (sl > 0 && s[sl - 1] != ' ' &&
					(s[sl - 1] != '.' || (sl > 2 && s[sl - 1] == '.' && s[sl - 2] == '.' && s[sl - 3] == '.')))
					s[sl++] = ' ';
				s[sl++] = '.';
			}
			else if (isdigit(c))
			{
				if (!num && s[sl - 1] != ' ')
					s[sl++] = ' ';
				num = true;
				s[sl++] = c;
			}
		}
		else
		{
			num = false;
		}

	}

	while (s[sl] == ' ')
		--sl;

	for (int i = 0; i < sl; ++i)
		cout << s[i];
	cout << endl;

	return 0;
}


# include <iostream>
# include <stdio.h>
# include <stdlib.h>

using namespace std;

char s[10000];

int main()
{
	int sl = 0;
	bool num = false;
	for(char c = getchar(); c != '\n'; c = getchar())
	{
		if (c == ' ')
		{
			num = true;
		}
		else if (c == ',')
		{
			s[sl++] = ',';
			s[sl++] = ' ';
			num = false;
		}
		else if (c == '.')
		{
			if (((sl > 0 && s[sl - 1] != '.') || (sl > 2 && s[sl - 1] == '.' && s[sl - 2] == '.' && s[sl - 3] == '.'))
				&& s[sl - 1] != ' ')
				s[sl++] = ' ';
			s[sl++] = '.';
			num = false;
		}
		else if (isdigit(c))
		{
			if (num)
				s[sl++] = ' ';
			num = false;
			s[sl++] = c;
		}
	}

	while (s[sl - 1] == ' ')
		--sl;

	for (int i = 0; i < sl; ++i)
		cout << s[i];
	cout << endl;

	return 0;
}


# include <iostream>
# include <stdio.h>
# include <stdlib.h>

using namespace std;

char s[10000];

int main()
{
	int sl = 0;
	bool num = true;
	for(char c = getchar(); c != '\n'; c = getchar())
	{
		if (c != ' ')
		{
			if (c == ',')
			{
				s[sl++] = ',';
				s[sl++] = ' ';
			}
			else if (c == '.')
			{
				if (sl > 0 && s[sl - 1] != ' ' && (s[sl - 1] != '.' ||
					(sl > 3 && s[sl - 1] == '.' && s[sl - 2] == '.' && s[sl - 3] == '.')))
					s[sl++] = ' ';
				s[sl++] = '.';
			}
			else if (isdigit(c))
			{
				if (!num && s[sl - 1] != ' ')
					s[sl++] = ' ';
				num = true;
				s[sl++] = c;
			}
		}
		else
		{
			num = false;
		}

	}

	while (s[sl] == ' ')
		--sl;

	for (int i = 0; i < sl; ++i)
		cout << s[i];
	cout << endl;

	return 0;
}


# include <iostream>
# include <stdio.h>
# include <stdlib.h>

using namespace std;

char s[10000];

int main()
{
	int sl = 0;
	bool num = true;
	for(char c = getchar(); c != '\n'; c = getchar())
	{
		if (c == ' ')
		{
			num = false;
		}
		else if (c == ',')
		{
			s[sl++] = ',';
			s[sl++] = ' ';
			num = true;
		}
		else if (c == '.')
		{
			if (((sl > 0 && s[sl - 1] != '.') || (sl > 2 && s[sl - 1] == '.' && s[sl - 2] == '.' && s[sl - 3] == '.'))
				&& s[sl - 1] != ' ')
				s[sl++] = ' ';
			s[sl++] = '.';
			num = true;
		}
		else if (isdigit(c))
		{
			if (!num && sl > 0 && s[sl - 1] != ' ')
				s[sl++] = ' ';
			num = true;
			s[sl++] = c;
		}
	}

	while (s[sl - 1] == ' ')
		--sl;

	for (int i = 0; i < sl; ++i)
		cout << s[i];
	cout << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',') re+=", ",x=0,i++;
       else
         if (s[i]=='.')
         {
            if (x && i) re+=' ';
            re+="...";
            x=1; i+=3;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9')
            {
               if (!i || (s[i-1]>='0' &&s[i-1]<='9')) re+=s[i];
               else
               {
                   if (x<2) re+=s[i], x=2;
               }
            }
            i++;
         }
       //cout << i << " " << re << endl;
    }
    if (re[re.length()-1]==',') re.erase(re.length()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',') re+=", ",x=0;
       else
         if (s[i]=='.')
         {
            if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
            re+="...";
            i+=2;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9') re+=s[i];
            else
               if (!re.empty() && re[re.size()-1]>='0' && re[re.size()-1]<='9')
                  re+=' ';
         }
         i++;
    }
    if (re[re.size()-1]==' ') re.erase(re.size()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',') re+=", ",x=0;
       else
         if (s[i]=='.')
         {
            if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
            re+="...";
            i+=2;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9') re+=s[i];
            else
               if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
         }
         i++;
    }
    if (re[re.size()-1]==' ') re.erase(re.size()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',')
       {
          if (!re.empty() && re[re.size()-1]==' ') re.erase(re.size()-1,1);
          re+=", ",x=0;
       }
       else
         if (s[i]=='.')
         {
            if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
            re+="...";
            i+=2;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9') re+=s[i];
            else
               if (!re.empty() && re[re.size()-1]>='0' && re[re.size()-1]<='9')
                  re+=' ';
         }
         i++;
    }
    if (re[re.size()-1]==' ') re.erase(re.size()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',')
       {
          if (x) re.erase(re.size()-1,1);
          re+=", "; x=0;
       }
       else
         if (s[i]=='.')
         {
            if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
            re+="...";
            i+=2; x=0;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9') re+=s[i],x=0;
            else
               if (!re.empty() && re[re.size()-1]>='0' && re[re.size()-1]<='9')
                  re+=' ',x=1;
         }
         i++;
    }
    if (re[re.size()-1]==' ') re.erase(re.size()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',') re+=", ",x=0,i++;
       else
         if (s[i]=='.')
         {
            if (x && i) re+=' ';
            re+="...";
            x=1; i+=3;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9')
            {
               if (!i || (s[i-1]>='0' &&s[i-1]<='9')) re+=s[i];
               else
               {
                   if (x<2) re+=s[i], x=2;
               }
            }
            i++;
         }
       //cout << i << " " << re << endl;
    }
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',') re+=", ",x=0,i++;
       else
         if (s[i]=='.')
         {
            if (x && i) re+=' ';
            re+="...";
            x=1; i+=3;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9')
            {
               if (!i || (s[i-1]>='0' &&s[i-1]<='9')) re+=s[i];
               else
               {
                   if (x<2) re+=s[i], x=2;
               }
            }
            i++;
         }
       //cout << i << " " << re << endl;
    }
    if (re[re.length()-1]==' ') re.erase(re.length()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#define fr(a,b,c) for(a=b;a<=c;a++)
#define frr(a,b,c) for(a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0,-1,1,1,-1};
      int dy[]={0,1,0,-1,1,1,-1,-1};

string re;
char s[333];

int main()
{
    int n,i=0,x=0;
    gets(s);
    n=strlen(s);
    while (i<n)
    {
       if (s[i]==',')
       {
          if (x) re.erase(re.size()-1,1);
          re+=", "; x=0;
       }
       else
         if (s[i]=='.')
         {
            if (!re.empty() && re[re.size()-1]!=' ') re+=' ';
            re+="...";
            i+=2; x=0;
         }
         else
         {
            if (s[i]>='0' && s[i]<='9') re+=s[i],x=0;
            else
               if (!re.empty() && re[re.size()-1]>='0' && re[re.size()-1]<='9')
                  re+=' ',x=1;
         }
         i++;
    }
    if (re[re.size()-1]==' ') re.erase(re.size()-1,1);
    cout << re << endl;
    //system("pause");
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[300];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[300];

            int cont = 0;
            while(i < strlen(input) && isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            numero[cont] = '\0';
            --i;

            if (lastnum) {
                printf (" %s", numero);
            }
            else printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[300];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[300];

            int cont = 0;
            while(i < strlen(input) && isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            numero[cont] = '\0';
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
	char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
	char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(i < strlen(input) && isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[256];

    gets(input);

    for (int i = 0, lastnum = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
        }
        if (isdigit(input[i])) {
            int numero = 0;

            while(isdigit(input[i])) {
                numero = numero*10 + (input[i] - '0');
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%d", numero);
            lastnum = 1;
        }
    }
    return 0;
}


#include <cstring>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main () {
    char input[256];

    gets(input);

    for (int i = 0, lastnum = 0, lastspace = 0; i < strlen(input); ++i) {
        if (input[i] == ' ') continue;
        if (input[i] == '.') {
            if (i == 0 || lastspace) printf ("...");
            else printf (" ...");
            i += 2;
            lastnum = 0;
            lastspace = 0;
        }
        if (input[i] == ',') {
            if (i + 1 == strlen(input)) printf (",");
            else printf (", ");
            lastnum = 0;
            lastspace = 1;
        }
        if (isdigit(input[i])) {
            char numero[255];

            int cont = 0;
            while(i < strlen(input) && isdigit(input[i])) {
                numero[cont++] = input[i];
                ++i;
            }
            --i;

            if (lastnum) {
                lastnum = 0;
                continue;
            }

            printf ("%s", numero);
            lastnum = 1;
            lastspace = 0;
        }
    }
    return 0;
}