#include <bits/stdc++.h>
using namespace std;
const char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                        'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                        's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int inline max3(int a, int b, int c) { return max(a, max(b, c)); }
int n;
long long ab, a, b;
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%lld", &a);
    scanf("%lld", &b);
    ab = a * 1LL * b;
    int l = 1, r = 1e6, mid;
    while (l < r) {
      mid = l + (r - l + 1) / 2;
      if (1LL * mid * mid * mid <= ab)
        l = mid;
      else
        r = mid - 1;
    }
    if (1LL * r * r * r == ab && a % r == 0 && b % r == 0)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
