#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int z = power(a, b / 2);
  if (b % 2 == 0) return z * z;
  return a * z * z;
}
long long int search(long long int n) {
  long long int low = 1, high = 1000000, mid = (low + high) / 2;
  while (high >= low) {
    mid = (low + high) / 2;
    if (mid * mid * mid == n)
      return mid;
    else if (mid * mid * mid > n)
      high = mid - 1;
    else
      low = mid + 1;
  }
  return mid;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    int flag = 0;
    long long int z = search(a * b);
    if ((z * z * z) != a * b) flag = 1;
    long long int lol = z;
    if (flag == 0 && a % lol == 0 && b % lol == 0)
      printf("YES\n");
    else
      printf("NO\n");
  }
}
