#include using i64 = long long; std::vector minp, primes, phi, mu; std::vector sphi; void sieve(int n) { minp.assign(n + 1, 0); phi.assign(n + 1, 0); sphi.assign(n + 1, 0); mu.assign(n + 1, 0); primes.clear(); phi[1] = 1; mu[1] = 1; for (int i = 2; i <= n; i++) { if (minp[i] == 0) { minp[i] = i; phi[i] = i - 1; mu[i] = -1; primes.push_back(i); } for (auto p : primes) { if (i * p > n) { break; } minp[i * p] = p; if (p == minp[i]) { phi[i * p] = phi[i] * p; break; } phi[i * p] = phi[i] * (p - 1); mu[i * p] = -mu[i]; } } for (int i = 1; i <= n; i++) { sphi[i] = sphi[i - 1] + phi[i]; mu[i] += mu[i - 1]; } } std::pair get(int N, int x, int y) { if (x > y) { auto [lt, le] = get(N, y, x); std::tie(lt, le) = std::pair(2 * sphi[N] - 1 - le, 2 * sphi[N] - 1 - lt); return {lt, le}; } i64 le = 0, lt; for (int i = 1; i <= N; i++) { le += 1LL * x * i / y * mu[N / i]; } lt = le - (x <= N && y <= N && std::gcd(x, y) == 1); return {lt, le}; } void solve() { int N; i64 K; std::cin >> N >> K; K--; if (K >= 2 * sphi[N] - 1) { std::cout << -1 << "\n"; return; } int lox = 0, loy = 1, hix = 1, hiy = 0; while (true) { auto [lt, le] = get(N, lox + hix, loy + hiy); if (lt <= K && le > K) { std::cout << lox + hix << " " << loy + hiy << "\n"; return; } if (le <= K) { int t = 1; while (get(N, lox + hix * t, loy + hiy * t).second <= K) { t *= 2; } while (t > 1) { t /= 2; if (get(N, lox + hix * t, loy + hiy * t).second <= K) { lox += hix * t; loy += hiy * t; } } } else { int t = 1; while (get(N, lox * t + hix, loy * t + hiy).first > K) { t *= 2; } while (t > 1) { t /= 2; if (get(N, lox * t + hix, loy * t + hiy).first > K) { hix += lox * t; hiy += loy * t; } } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); sieve(3E5); int t; std::cin >> t; while (t--) { solve(); } return 0; }