#include <bits/stdc++.h>
using namespace std;
long long int sol(long long int x) {
  long long int l = 1;
  long long int r = 1000005;
  while (l != r) {
    long long int mid = (l + r + 1) / 2;
    if ((mid * mid * mid) > x) {
      r = mid - 1;
    } else
      l = mid;
  }
  return l;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    scanf("%lld %lld", &a, &b);
    long long int temp = sol(a * b);
    if ((temp * temp * temp) != (a * b)) {
      printf("NO\n");
    } else if (a % temp == 0 && b % temp == 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
