#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
void solve();
const int N = 1e5 + 10, P = 998244353;
int pw_2[N], pw_5[N];
signed main() {
fast
pw_2[0] = pw_5[0] = 1;
for (int i = 1; i <= 30; i++)pw_2[i] = pw_2[i - 1] * 2, pw_5[i] = pw_5[i - 1] * 5;
int t = 1;
cin >> t;
while (t--) solve();
}
void solve() {
int a, b, ansc(1e9), ansd(0);
cin >> a >> b;
ansc = b - a;
ansd = b;
int nb(b);
while (nb % 2 == 0)nb /= 2;
while (nb % 5 == 0)nb /= 5;
if (nb == 1) {
cout << 0 << " " << 1 << '\n';
return;
}
for (int i = 0; i <= 30; i++) {
for (int j = 0; j <= 12; j++) {
if (pw_2[i] * pw_5[j] * b <= 1000000000) {
int c(nb - (pw_2[i] * pw_5[j] * a) % nb);
if (ansc > c / (gcd(c, pw_2[i] * pw_5[j] * b))) {
ansc = c / (gcd(c, pw_2[i] * pw_5[j] * b));
ansd = pw_2[i] * pw_5[j] * b / (gcd(c, pw_2[i] * pw_5[j] * b));
}
}
}
}
cout << ansc << " " << ansd << '\n';
return;
}
/*
4
1 2
2 3
3 7
19 79
*/