#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int t;
    long long a, b, x, y;
    cin >> t;
    while (t--){
        cin >> a >> b;
        bool found = false;

        if(a == 0){
            cout << "0 " << b << '\n';
        } else if(a-b == 1){
            cout << "1 " << a << '\n';
        } else {
            for(long long i = 3;i <= sqrt(a);i+=2){
                if(a%i == 0){
                    y = a/i;
                    x = i^y;
                    if(x == b){
                        found = true;
                        x = i;
                        break;
                    }
                }
            }
            if(found){
            cout << x << " " << y << '\n';
            } else {
            cout << "-1" << '\n';
            }
        }
    }
    return 0;
}