#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  while (N--) {
    int64_t a, b;
    cin >> a >> b;
    int64_t A = 1, hi = sqrt(b) + 1;
    while (A < hi) {
      int64_t mid = (A + hi + 1) / 2;
      if (b * b / (mid * mid * mid) < a) {
        hi = mid - 1;
      } else {
        A = mid;
      }
    }
    if ((b * b) % (A * A * A) == 0 && b % (A * A) == 0 &&
        (b * b) / (A * A * A) == a) {
      int64_t B = b / (A * A);
      if (a % (B * B) == 0 && a / (B * B) == A && (a * a) % (B * B * B) == 0 &&
          (a * a) / (B * B * B) == b) {
        cout << "YES\n";
        continue;
      }
    }
    cout << "NO\n";
  }
}
