#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1e9 + 7;
long long MOD = 998244353;
unsigned long long ncr(long long n, long long k) {
  if (k > n) return 1ll * 0;
  unsigned long long res = 1;
  if (k > n - k) k = n - k;
  for (long long i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
    res = res;
  }
  return res;
}
bool prime(unsigned long long num) {
  bool flag = true;
  for (unsigned long long i = 2; i * i <= num; i++) {
    if (num % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
long long ipow(long long base, long long exp) {
  if (exp == 0) return 1ll * 1;
  long long result = 1;
  for (;;) {
    if (exp & 1) {
      result *= base;
      result = result % MOD;
    }
    exp >>= 1;
    if (!exp) break;
    base *= base;
    base = base % MOD;
  }
  return result % MOD;
}
long long abs(long long a, long long b) {
  if ((a - b) > 0)
    return (a - b);
  else
    return (b - a);
}
long long add(long long a, long long b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
  else if (a < 0)
    a += MOD;
  return a;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long der(long long k) {
  long long res = 0;
  long long fact = 1;
  for (long long i = 2; i <= k; i++) fact *= i;
  long long s = 1;
  long long j = 1;
  for (long long i = 2; i <= k; i++) {
    j = j * i;
    long long first = (fact / j) * s;
    res += first;
    s = s * (-1);
  }
  return res;
}
vector<long long> p;
vector<long long> _prime(long long a) {
  vector<long long> v;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      v.push_back(i);
      while (a % i == 0) a /= i;
    }
  }
  if (a != 1) v.push_back(a);
  return v;
}
long long cubic_root(long long x) {
  long long l = 0, r = 1000000;
  while (l != r) {
    long long m = (l + r + 1) / 2;
    if (m * m * m > x)
      r = m - 1;
    else
      l = m;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  while (n--) {
    long long a, b;
    cin >> a >> b;
    long long c = a * b;
    long long k = cubic_root(c);
    bool flag = false;
    if (k * k * k == c && a % k == 0 && b % k == 0) flag = true;
    if (flag == true) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
