#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  vector<long long> r = {a, b};
  int i;
  while (true) {
    i = int((r).size()) - 1;
    r.push_back(r[i - 1] % r[i]);
    if (!r.back()) break;
  }
  i = int((r).size()) - 2;
  return r[i];
}
void primefactor(long long n, vector<int>& pf, vector<int>& mult) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      pf.push_back(i);
      mult.push_back(0);
      while (n % i == 0) {
        n /= i;
        mult.back()++;
      }
    }
  }
  if (n > 1) {
    pf.push_back(n);
    mult.push_back(1);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, f, count, t;
  cin >> n;
  long long a, b, c;
  bool possible, flag;
  set<int> triple;
  for (int i = 1; i <= 1000; i++) triple.insert(i * i * i);
  for (int game = 1; game <= n; game++) {
    cin >> a >> b;
    if (a == b && b == 1) {
      cout << "Yes" << '\n';
      continue;
    }
    if (a == 1 || b == 1) {
      cout << "No" << '\n';
      continue;
    }
    c = gcd(a, b);
    if (a > b) swap(a, b);
    if (c * c < a || c * c < b) {
      cout << "No" << '\n';
      continue;
    }
    a /= c;
    b /= c;
    if (a == b) {
      if (triple.find(c) == triple.end()) {
        cout << "No" << '\n';
        continue;
      }
      cout << "Yes" << '\n';
      continue;
    }
    vector<int> pf, mult;
    primefactor(a, pf, mult);
    flag = true;
    for (int i = 0; i <= int((pf).size()) - 1; i++) {
      f = pf[i];
      count = 0;
      while (!(c % f)) {
        c /= f;
        count++;
      }
      possible = false;
      if (mult[i] <= count) {
        t = count - mult[i];
        if (!(t % 3)) {
          if (t / 3 * 2 <= count) possible = true;
        }
      }
      flag = possible;
      if (!flag) break;
    }
    if (!flag) {
      cout << "No" << '\n';
      continue;
    }
    pf.resize(0);
    mult.resize(0);
    primefactor(b, pf, mult);
    for (int i = 0; i <= int((pf).size()) - 1; i++) {
      f = pf[i];
      count = 0;
      while (!(c % f)) {
        c /= f;
        count++;
      }
      possible = false;
      if (mult[i] <= count) {
        t = count - mult[i];
        if (!(t % 3)) {
          if (t / 3 * 2 <= count) possible = true;
        }
      }
      flag = possible;
      if (!flag) break;
    }
    if (!flag) {
      cout << "No" << '\n';
      continue;
    }
    if (triple.find(c) == triple.end()) {
      cout << "No" << '\n';
      continue;
    }
    cout << "Yes" << '\n';
  }
  return 0;
}
