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

int main()
{
    int t;
    bool flag;
    cin >> t;
    unsigned long long a[t];
    unsigned long long b[t];
    for (int i=0; i<t; i++){
            cin >> a[i] >> b[i];
    }
    for (int i=0; i<t; i++){
                if ((b[i] & 1) == false){
                    if ((1 ^ a[i]) == b[i]){
                        cout << 1 << " " << a[i] << "\n";
                    }else{
                    flag = false;
                    if (floor(floor(sqrt(a[i])) /2)-(floor(sqrt(a[i])) /2) == 0){
                        for (int j=floor(sqrt(a[i]))+1; j>=3; j-=2){
                            if (a[i] % j == 0){
                                if ((j ^ (a[i]/j)) == b[i]){
                                    cout << j << " " <<  a[i]/j << "\n";
                                    flag = true;
                                    break;
                                }
                            }

                        }
                    }else{
                        for (int j=floor(sqrt(a[i])); j>=3; j-=2){
                            if (a[i] % j == 0){
                                if ((j ^ (a[i]/j)) == b[i]){
                                    cout << j << " " <<  a[i]/j << "\n";
                                    flag = true;
                                    break;
                                }
                            }
                    }
                    if (!flag){
                        cout << -1 << "\n";
                    }
                  }

                }
               } else cout << -1 << "\n";


    }
    return 0;
}