#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 31;
int d[N][N];
vector<int> p;
bool check(int a) {
  for (int i = 2; 1ll * i * i <= a; ++i) {
    if (a % i == 0) return 0;
  }
  return 1;
}
set<int> sq;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  memset(d, 0, sizeof(d));
  d[0][0] = 1;
  for (int i = int(2); i < int(1000); ++i) {
    if (check(i)) {
      p.push_back(i);
    }
  }
  for (int i = int(0); i < int(N); ++i) {
    for (int j = int(0); j < int(N); ++j) {
      if (!d[i][j]) continue;
      for (int k = int(0); k < int(N); ++k) {
        if (i + 2 * k < N && j + k < N) {
          d[i + 2 * k][j + k] = N;
        }
        if (i + k < N && j + 2 * k < N) {
          d[i + k][j + 2 * k] = N;
        }
      }
    }
  }
  for (int i = 1; i * i <= 1000000000; ++i) {
    if (check(i)) sq.insert(i * i);
  }
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    bool ok = 1;
    for (auto prime : p) {
      int kola = 0, kolb = 0;
      while (a % prime == 0) {
        a /= prime, kola++;
      }
      while (b % prime == 0) {
        b /= prime, kolb++;
      }
      if (!d[kola][kolb]) {
        ok = 0;
        break;
      }
    }
    if (ok &&
        ((a == b && a == 1) || (sq.find(a) != sq.end() && 1ll * b * b == a) ||
         (sq.find(b) != sq.end() && 1ll * a * a == b))) {
      puts("Yes");
    } else {
      puts("No");
    }
  }
  return 0;
}
