#include <bits/stdc++.h>
const int maxh = 1e5 + 10, maxn = 350010;
using namespace std;
long long n, m, k, ps, pr[maxh];
vector<long long> p;
map<pair<int, int>, int> mp;
void sieve() {
  for (long long i = 2; i < maxh; i++) {
    if (pr[i]) continue;
    p.push_back(i);
    for (long long j = i * i; j < maxh; j += i) {
      pr[j] = 1;
    }
  }
  ps = p.size();
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
bool solve(long long a, long long b) {
  if (mp[make_pair(a, b)]) return mp[make_pair(a, b)] - 1;
  int c = gcd(a, b);
  for (long long i = 0; p[i] * p[i] <= c; i++) {
    if (c % p[i] == 0) {
      int x = 0, y = 0;
      while (c % p[i] == 0) c /= p[i];
      while (a % p[i] == 0) a /= p[i], x++;
      while (b % p[i] == 0) b /= p[i], y++;
      if (2 * x - y < 0 || 2 * y - x < 0) return 0;
      if ((2 * x - y) % 3 || (2 * y - x) % 3) return 0;
      if (a > b) swap(a, b);
      if (a * a == b) return 1;
    } else if (a % p[i] == 0 || b % p[i] == 0)
      return 0;
  }
  if (c > 1) {
    int i = c;
    int x = 0, y = 0;
    while (a % i == 0) a /= i, x++;
    while (b % i == 0) b /= i, y++;
    if (2 * x - y < 0 || 2 * y - x < 0) return 0;
    if ((2 * x - y) % 3 || (2 * y - x) % 3) return 0;
  }
  if (a > 1 || b > 1) return 0;
  return 1;
}
int main() {
  sieve();
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) {
    long long a, b;
    scanf("%I64d %I64d", &a, &b);
    int as = solve(a, b);
    mp[make_pair(a, b)] = as + 1;
    if (as)
      printf("Yes\n");
    else
      printf("NO\n");
  }
  return 0;
}
