#include <bits/stdc++.h>
int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
using namespace std;
long long power(long long a, long long p, long long M) {
  long long r = 1;
  a = a % M;
  while (p > 0) {
    if (p % 2) r = (r * a) % M;
    a = (a * a) % M;
    p /= 2;
  }
  return r;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int t;
  scanf("%d", &t);
  long long x, y;
  for (int i = 0; i < t; i++) {
    scanf("%lld%lld", &x, &y);
    long long mul = x * y;
    long long croot = cbrt(mul) + 1e-9;
    if (x % croot == 0 && y % croot == 0 && croot * croot * croot == mul) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
