#include <bits/stdc++.h>
using namespace std;
bool sol(long long a, long long b) {
  long long r = (long long)a * b, g = pow(r, 1.0 / 3) - 2;
  while (g * g * g <= r) ++g;
  --g;
  if (g * g * g != r)
    return false;
  else if (a % g == 0 && b % g == 0)
    return true;
  else
    return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  while (n--) {
    long long a, b;
    cin >> a >> b;
    bool f = sol(a, b);
    cout << (f ? "YES\n" : "NO\n");
  }
}
