#include #define mst(a,b) memset(a,b,sizeof(a)) #define lowbit(x) ((x)&(-x)) #define X first #define Y second #define lc o<<1 #define rc o<<1|1 using namespace std; typedef long long LL; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pdd; typedef pair pll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 1000000+10; const int maxm = 100000+10; const int mod = 998244353; const double eps = 1e-8; bool notPrime[maxn]; int prime[maxn], cnt; void init() { notPrime[1] = true; cnt = 0; int limit = sqrt(1e9) + 1; for (int i = 2; i <= limit; ++i) { if (!notPrime[i]) { for (int j = i * i; j <= limit; j += i) { notPrime[j] = true; } prime[cnt++] = i; } } } int cal(int val) { if (val == 1) { return val; } for (int i = 0; i < cnt; ++i) { if (val % prime[i] == 0) { return prime[i]; } } return val; } int main() { #ifdef local freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); init(); int T; cin >> T; while (T--) { int a, b; cin >> a >> b; if (a < b) { swap(a, b); } if (a == b) { if (a == 1) { cout << -1 << " " << -1 << "\n"; } else { cout << 2 << " " << a << "\n"; } continue; } int mx = a - b; int mn = cal(a - b); if (mx < 2 || mn < 2) { mx = mn = -1; } cout << mn << " " << mx << "\n"; } return 0; }