#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)2e6 + 1, inf = (int)2e9 + 1, mod = (int)1e9 + 7;
int n, k, ans, pos, cur, cnt;
long long a[maxn], b[maxn], y;
double x;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (int i = 1; i <= n; i++) {
    y = a[i] * b[i];
    if (y > 1) {
      long long l, r;
      if (y > 1000000)
        r = 1000000;
      else
        r = y;
      l = 0;
      while (l != r) {
        long long m = (l + r + 1) / 2;
        if (m * m * m <= y) l = m;
        if (m * m * m > y) r = m - 1;
      }
      if (l * l * l == y) ans++;
      if (ans == 1 && b[i] % l == 0 && a[i] % l == 0)
        cout << "YES" << '\n';
      else
        cout << "NO" << '\n';
      ans = 0;
    } else
      cout << "YES" << '\n';
  }
  return 0;
}
