#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ri register signed #define RI register signed #define cf cout.flush(); #define lson (rt<<1|1) #define rson (rt<<1) #define lson1 (rt1<<1) #define rson1 (rt1<<1|1) #define lson2 (rt2<<1) #define rson2 (rt2<<1|1) #define mid ((l+r)>>1) #define mid1 ((l1+r1)>>1) #define mid2 ((l2+r2)>>1) #define mes(x) memset(x,0,sizeof x) typedef long long LL; typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef pairP; typedef pair PP; typedef pair PPll; //#define int long long //#define double long double #define ri register signed #define il inline #define deb(...) logger(#__VA_ARGS__,__VA_ARGS__) template void logger(string vars, Args&&... values) { cout << vars << " = "; string delim = ""; //(..., (cout << delim << values, delim = ", ")); } inline string toString(int x) { string ans = ""; bool negtive = x < 0; x = abs(x); while (x)ans.push_back(x % 10 + '0'), x /= 10; if (ans.size() == 0)ans = "0"; if (negtive)ans.push_back('-'); for (int i = 0; i < ans.size() / 2; i++) swap(ans[i], ans[ans.size() - 1 - i]); return ans; } inline int toInt(const string&str) { int ans = 0; bool negtive = str[0] == '-'; for (int i = negtive; i < str.size(); i++) ans = ans * 10 + str[i] - '0'; if (negtive)ans *= -1; return ans; } inline int gcd(int x, int y) { return x ? gcd(y%x, x) : y; } ll exgcd(ll a, LL b, LL &x, LL &y) { LL d = a; if (b == 0) x = 1, y = 0; else { d = exgcd(b, a%b, y, x), y -= a / b * x; } return d; } const int mod = 998244353; inline int read() { int ans = 0; char last = ' ', ch = getchar(); while (!(ch >= '0' && ch <= '9'))last = ch, ch = getchar(); while (ch >= '0' && ch <= '9')ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar(); return ans; } inline int QPow(ll a, ll b) { LL ans = 1; if (b < 0)return 0; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } inline int QPow(LL a, LL b, const int&mod) { LL ans = 1; while (b) { if (b & 1)ans = ans * a%mod; a = a * a%mod; b >>= 1; } return ans; } const double PI = 3.141592653589793115997963468544185161590576171875; const double e = 2.718281828459045; void ask(int x) { cout << '?' << ' ' << x << endl; cf; } void decide(int x) { cout << "! " << x << endl; cf; } short _min(short a, short b) { return a < b ? a : b; } const int inf = 1+(1 << 30); const int inf2 = 10000; const double eps = 1e-10; int db_cmp(double x, double y) { if (fabs(x - y) < eps)return 0; if (x > y)return 1; return -1; } double distance(P p1, P p2) { return sqrt((p1.first - p2.first)*(p1.first - p2.first) + (p2.second - p1.second)*(p2.second - p1.second)); } const int maxn = 400002; LL inv[maxn]; LL fac[maxn], fac_1[maxn]; LL QPow(LL a, LL b, LL md) { LL ans = 1; while (b) { if (b & 1)ans = ans * a%md; a = a * a%md; b >>= 1; } return ans; } void getInv() { inv[1] = 1; for (int i = 2; i < maxn; i++) inv[i] = (mod - mod / i)*inv[mod%i] % mod; } void init() { fac[0] = fac_1[0] = 1; for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i%mod, fac_1[i] = fac_1[i - 1] * inv[i] % mod; } LL C(int n, int m) { if (n < m || n < 0 || m < 0)return 0; return fac[n] * fac_1[n - m] % mod*fac_1[m] % mod; } #define N 101 struct matrix { int m[N][N]; }; matrix b, ans; char str[101]; int len; void init1() { int i; memset(b.m, 0, sizeof(b.m)); for (i = 1; i < len; i++) b.m[i][i] = b.m[i][i - 1] = 1; b.m[0][0] = b.m[0][len - 1] = 1;//第一个字符与最后一个结合 } matrix mul(matrix a, matrix b) { int i, j, k; matrix c; for (i = 0; i < len; i++) for (j = 0; j < len; j++) { c.m[i][j] = 0; for (k = 0; k < len; k++) c.m[i][j] += (a.m[i][k] * b.m[k][j]); } return c; } void mpow(matrix ma, int n) { int i; memset(ans.m, 0, sizeof(ans.m)); for (i = 0; i < len; i++) ans.m[i][i] = 1; for (; n; n >>= 1) { if (n & 1) ans = mul(ans, ma); ma = mul(ma, ma); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //getInv(); //init(); int t, n, k, m; cin >> t; while (t--) { cin >> n >> m; int tmp = abs(n - m); int Min = max(n, m); int ans1 = inf, ans2 = 0; int sq = sqrt(tmp); for (int i = 1; i <= Min && i <= sq; i++) { if (tmp%i == 0) { if(i>1) ans1 = min(ans1, i), ans2 = max(ans2, i); if (tmp / i <= Min&&tmp/i>1) ans1 = min(ans1, tmp / i), ans2 = max(ans2, tmp / i); } } if (n == m) { if(n>1) cout << 2 << ' ' << n << '\n'; else cout << "-1 -1\n"; } else if (ans1 == inf) cout << "-1 -1\n"; else cout << ans1 << ' ' << ans2 << '\n'; } //system("pause"); return 0; }