#include <bits/stdc++.h>
using namespace std;
const int maxn = 80;
int f[maxn][maxn];
vector<int> primes;
map<int, int> get(int n) {
  map<int, int> mp;
  for (int i = 0; i < primes.size() && primes[i] * primes[i] <= n; i++) {
    while (n % primes[i] == 0) {
      mp[primes[i]]++;
      n /= primes[i];
    }
  }
  if (n > 1) {
    mp[n]++;
  }
  return mp;
}
void calcPrimes() {
  for (int i = 2; i <= 1000; i++) {
    if (get(i).size() == 1) {
      primes.push_back(i);
    }
  }
}
bool go(int a, int b) {
  if (a < 0 || b < 0) {
    return false;
  }
  if (f[a][b] != -1) {
    return f[a][b] == 1;
  }
  if (a == 0 && b == 0 || go(a - 2, b - 1) || go(a - 1, b - 2)) {
    f[a][b] = 1;
  } else {
    f[a][b] = 2;
  }
  return f[a][b] == 1;
}
bool solve(int a, int b) {
  for (int i = 0; i < primes.size() && primes[i] * primes[i] <= a; i++) {
    int cntA = 0, cntB = 0;
    while (a % primes[i] == 0) {
      a /= primes[i];
      cntA++;
    }
    while (b % primes[i] == 0) {
      b /= primes[i];
      cntB++;
    }
    if (f[cntA][cntB] != 1) {
      return false;
    }
  }
  int cntA = 0;
  int cntB = 0;
  if (b < a) {
    swap(a, b);
  }
  if (a > 1) {
    while (b % a == 0) {
      cntB++;
      b /= a;
    }
    cntA = 1;
  }
  return f[cntA][cntB] == 1 && b == 1;
}
int main() {
  memset(f, -1, sizeof(f));
  calcPrimes();
  for (int i = 0; i < 80; i++) {
    for (int j = 0; j < 80; j++) {
      go(i, j);
    }
  }
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    scanf("%d %d", &a, &b);
    bool ok = true;
    ok = ((long long)a * (long long)a == (long long)b ||
          (long long)b * (long long)b == (long long)a) ||
         solve(a, b);
    if (ok) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}
