#include <bits/stdc++.h>
using namespace std;
void fileio() {}
vector<vector<long long int>> g;
long long int cube_root(long long int x) {
  long long int lo = 0, hi = 1e6 + 10;
  while (lo <= hi) {
    long long int m = (lo + hi) / 2;
    long long int val = m * m * m;
    if (val == x) return m;
    if (val > x) {
      hi = m - 1;
    } else {
      lo = m + 1;
    }
  }
  return -1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fileio();
  long long int t;
  cin >> t;
  while (t-- > 0) {
    long long int a, b;
    cin >> a >> b;
    long long int x = a * b;
    long long int c = cube_root(x);
    if (c == -1) {
      cout << "NO";
      cout << '\n';
      continue;
    }
    if (a % c != 0 or b % c != 0) {
      cout << "NO";
      cout << '\n';
      continue;
    }
    cout << "YES";
    cout << '\n';
  }
  return 0;
}
