#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
long long top, prime[N], f[N];
void init() {
  memset(f, 0, sizeof(f));
  for (long long i = 2; i < 100005; i++) {
    if (!f[i]) prime[top++] = i;
    for (long long j = 0; j < top && prime[j] * i < 100005; j++) {
      f[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
int n;
pair<long long, int> C[N];
int main() {
  init();
  scanf("%d", &n);
  while (n--) {
    long long a, b, c;
    scanf("%lld%lld", &a, &b);
    long long x = a * b;
    long long l = 1, r = 1e6;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (mid * mid * mid >= x)
        r = mid;
      else
        l = mid + 1;
    }
    c = l;
    if (c * c * c != x) {
      printf("No\n");
      continue;
    }
    int tot = 0;
    for (int i = 0; i < top && 1LL * prime[i] * prime[i] <= c; i++) {
      if (c % prime[i] == 0) {
        int cnt = 0;
        while (c % prime[i] == 0) {
          c /= prime[i];
          cnt++;
        }
        C[tot++] = make_pair(prime[i], cnt);
      }
    }
    if (c > 1) C[tot++] = make_pair(c, 1);
    int flag = 1;
    for (int i = 0; i < tot; i++) {
      long long p = C[i].first;
      int cnta = 0, cntb = 0;
      while (a % p == 0) a /= p, cnta++;
      while (b % p == 0) b /= p, cntb++;
      if (cnta > cntb) swap(cnta, cntb);
      if ((cnta + cntb) % 3 == 0 && cnta >= (cnta + cntb) / 3)
        ;
      else {
        flag = 0;
        break;
      }
    }
    if (flag)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
