#include <bits/stdc++.h>
long long max_value = 1000005;
long long binary_search(long long x) {
  long long l, r;
  l = 0;
  r = max_value;
  while (l != r) {
    long long mid = (l + r + 1) / 2;
    if (mid * mid * mid > x) {
      r = mid - 1;
    } else {
      l = mid;
    }
  }
  return l;
}
int main(void) {
  int n;
  long long a, b;
  while (scanf("%d", &n) != EOF) {
    int i = 0;
    for (i = 0; i < n; i++) {
      scanf("%I64d%I64d", &a, &b);
      long long x = binary_search(a * b);
      if (x * x * x != a * b) {
        printf("NO\n");
      } else if (a % x == 0 && b % x == 0) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    }
  }
  return 0;
}
