#include <iostream>
#include <queue>
#include <math.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    int64_t p,x,umn;
    while(t--){
        cin>>p>>x;
        umn=1;
        while(p%4==0 && x%2==0){
            p/=4;
            x/=2;
            umn*=2;
        }
        bool bad = true;
        for(int i=(int)(sqrt(p)+1);i>=1;i--){
            if((p%i)==0 && (i^(p/i))==x){
                cout<<i*umn<<" "<<p/i*umn<<endl;
                bad = false;
                break;
            }
        }
        if(bad) cout<<-1<<endl;
    }
    return 0;
}