#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long a, b, c, inv, br, br1, br2 = 0;
    cin >> inv;
    long long resenja1[inv], resenja2[inv];
    for(long long i = 0 ; i < inv ; i++){
        cin >> a >> b;
        if(b % 2 != 0 || a % 2 == 0) resenja1[br2] = -1, br2++;
        else{
            br = sqrt(a);
            if(br % 2 == 0) br++;
            bool t = false;
            while(t != true){
                if(a % br == 0){
                    br1 = a / br;
                    c = br1 ^ br;
                    if(c == b) resenja1[br2] = br, resenja2[br2] = br1, t = true, br2++;
                }
                br -= 2;
                if(br <= 0) resenja1[br2] = -1, t = true, br2++;
            }
        }
    }
    for(long long i = 0 ; i < inv ; i++){
        if(resenja1[i] != -1) cout << resenja1[i] << " " << resenja2[i] << endl;
        else cout << -1;
    }
    return 0;
}