#include <bits/stdc++.h>

using namespace std;

vector<long long> prvaMaska, drugaMaska;

int maska = 0;

void racunajMasku(long long x1, long long A, long long B, long long M)
{
    if ((((x1 * ((x1 ^ B) & M)) ^ A) & M) == 0)
    {
        if (maska == 0) prvaMaska.push_back(x1);
        else drugaMaska.push_back(x1);
    }
}

pair<int, int> pronadji(long long A, long long B)
{
	long long b = 1;
	while ( sqrt(A) >= b )
	{
        maska = (maska + 1) % 2;
		long long M = b | (b - 1);
		(maska)? drugaMaska.resize(0) : prvaMaska.resize(0);
		for (long long x1 : (maska)? prvaMaska : drugaMaska)
        {
            racunajMasku(x1, A, B, M);
            racunajMasku(x1|b, A, B, M);
        }
        b = b << 1;
	}
    maska = (maska + 1) % 2;
	for (long long x1 : (maska)? prvaMaska : drugaMaska)
	{
	    if (!x1)
            continue;
		if (sqrt(A) >= x1)
            if ((long long)x1 * (long long)(x1 ^ B) == A)
			    return make_pair(x1, (x1 ^ B));
	}
	return {-1, -1};
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    short t;
    cin >> t;
    long long a, b;
    while (cin >> a >> b)
    {
        prvaMaska.push_back(0);
        pair<int, int> resenje = pronadji(a, b);
        if (resenje.first == -1 && resenje.second == -1)
            cout << -1 << "\n";
        else cout << resenje.first << " " << resenje.second << "\n";
    }

}