#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void Cinioci(long long a, long long b)
{
    int brojac = 0;
	long long second, c = 0;
	for (int i = sqrt(a); i >= 1; i--)
	{
		if (a%i == 0)
		{
			second = a / i;

			c = i ^ second;
			if (c == b)
			{
				cout << i << " " << second << endl;
				return;
			}
		}
		else
		{
			brojac++;
			if (brojac > 73000000)
			{
				cout << -1;
				return;
			}
		}
	}
	cout << -1 << endl;
}
int main()
{
    int t;
    cin >> t;
    long long a[10000][2];

    for(int i = 0; i<t;i++)
    {
        cin >> a[i][0] >> a[i][1];
    }

    for(int i = 0; i<t;i++)
    {
        Cinioci(a[i][0], a[i][1]);
    }

    return 0;
}