#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    long long int a, b;
    cin >> a >> b;
    long long ab = a * b;
    double root = pow(ab, 1.0 / 3);
    int ff = round(root);
    if (root - (ff) > 0.0001 || root - ff < -0.0001) {
      cout << "NO" << '\n';
    } else if (a % ff != 0 || b % ff != 0) {
      cout << "NO" << '\n';
    } else
      cout << "YES" << '\n';
  }
  return 0;
}
