#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int q[31709], tot;
bool b[31709];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
  for (int i = 2; i <= 31700; i++)
    if (!b[i]) {
      q[++tot] = i;
      for (int a = i + i; a <= 31700; a += i) b[a] = true;
    }
  int T = read();
  while (T--) {
    int a = read(), b = read(), c = gcd(a, b);
    bool F = true;
    if (c == 1 && a + b != 2) {
      puts("No");
      continue;
    }
    if (c == a && a == b) {
      for (int o = 1; o <= tot; o++)
        if (q[o] > 1000)
          break;
        else if (a % q[o] == 0 && b % q[o] == 0) {
          int aa = 0, bb = 0;
          while (a % q[o] == 0) a /= q[o], aa++;
          while (b % q[o] == 0) b /= q[o], bb++;
          if (aa < bb) swap(aa, bb);
          int tmp = aa - bb;
          aa -= tmp + tmp, bb -= tmp;
          if (aa < 0 || aa % 3 != 0) {
            F = false;
            break;
          }
        } else if ((a % q[o] == 0) != (b % q[o] == 0)) {
          F = false;
          break;
        } else if ((a == 1) != (b == 1)) {
          F = false;
          break;
        } else if ((a == 1) && (b == 1))
          break;
      if (a != 1 || b != 1) F = false;
      puts(F ? "Yes" : "No");
      continue;
    }
    for (int o = 1; o <= tot; o++)
      if (a % q[o] == 0 && b % q[o] == 0) {
        int aa = 0, bb = 0;
        while (a % q[o] == 0) a /= q[o], aa++;
        while (b % q[o] == 0) b /= q[o], bb++;
        if (aa < bb) swap(aa, bb);
        int tmp = aa - bb;
        aa -= tmp + tmp, bb -= tmp;
        if (aa < 0 || aa % 3 != 0) {
          F = false;
          break;
        }
      } else if ((a % q[o] == 0) != (b % q[o] == 0)) {
        F = false;
        break;
      } else if ((a == 1) != (b == 1)) {
        F = false;
        break;
      } else if ((a == 1) && (b == 1))
        break;
    if (a != 1 || b != 1) F = false;
    puts(F ? "Yes" : "No");
  }
  return 0;
}
