#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const long long N = 1e6 + 5;
vector<long long> sieve(N);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 2; i < N; i++) {
    if (sieve[i]) continue;
    sieve[i] = i;
    for (long long j = 2 * i; j < N; j += i) sieve[j] = i;
  }
  long long t = 1;
  cin >> t;
  long long a, b, L, R, cRoot, mid, val, req, j, g, ans, cnt1, cnt2, tmpA, tmpB;
  long long chux, chuy;
  vector<long long> tmp(1000);
  while (t--) {
    cRoot = -1;
    L = 1;
    R = (long long)1e6;
    cin >> a >> b;
    req = a * b;
    while (L <= R) {
      mid = (L + R) / 2;
      val = mid * mid * mid;
      if (val == req) {
        cRoot = mid;
        break;
      }
      if (val < req)
        L = mid + 1;
      else
        R = mid - 1;
    }
    if (cRoot == -1) {
      cout << "No\n";
      continue;
    }
    j = 0;
    while (cRoot != 1) {
      tmp[j] = sieve[cRoot];
      g = tmp[j];
      j++;
      while (cRoot % g == 0) cRoot /= g;
    }
    ans = 1;
    for (long long i = 0; i < j; i++) {
      tmpA = a;
      tmpB = b;
      cnt1 = 0;
      cnt2 = 0;
      while (tmpA % tmp[i] == 0) {
        cnt1++;
        tmpA /= tmp[i];
      }
      while (tmpB % tmp[i] == 0) {
        cnt2++;
        tmpB /= tmp[i];
      }
      chux = (2 * cnt2 - cnt1) / 3;
      chuy = (cnt1 - chux) / 2;
      if (chux >= 0 and chuy >= 0) {
        if (chux + 2 * chuy == cnt1 and 2 * chux + chuy == cnt2) continue;
      }
      ans = 0;
      break;
    }
    if (ans)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
