#include <bits/stdc++.h>
using namespace std;
int n, sum, x, y;
int a[1000], d[1000], A[1000], B[1000], A1[1000], B1[1000];
bool jian(int a, int b) {
  int c;
  if ((a + b) % 3) return 1;
  c = (a + b) / 3;
  if (c > a || c > b) return 1;
  return 0;
}
int main() {
  scanf("%d", &n);
  int bz = 0;
  for (int i = 2; i < 1000; i++) {
    if (!a[i]) d[a[i] = ++d[0]] = i;
    for (int j = 1; j <= a[i]; j++)
      if ((long long)d[j] * i >= 1000)
        break;
      else
        a[d[j] * i] = j;
  }
  while (n--) {
    scanf("%d %d", &x, &y);
    int z = 1;
    A[0] = B[0] = 0;
    while (z <= d[0] && (long long)d[z] * d[z] <= x) {
      if (!(x % d[z])) {
        A[++A[0]] = d[z];
        A1[A[0]] = 0;
        while (!(x % d[z])) {
          A1[A[0]]++;
          x /= d[z];
        }
      }
      z++;
    }
    if (x != 1) {
      if ((int)sqrt(x) != 1 && !(x % (int)sqrt(x)))
        A[++A[0]] = sqrt(x), A1[A[0]] = 2;
      else
        A[++A[0]] = x, A1[A[0]] = 1;
    }
    z = 1;
    while (z <= d[0] && (long long)d[z] * d[z] <= y) {
      if (!(y % d[z])) {
        B[++B[0]] = d[z];
        B1[B[0]] = 0;
        while (!(y % d[z])) {
          B1[B[0]]++;
          y /= d[z];
        }
      }
      z++;
    }
    if (y != 1) {
      if ((int)sqrt(y) != 1 && !(y % (int)sqrt(y)))
        B[++B[0]] = sqrt(y), B1[B[0]] = 2;
      else
        B[++B[0]] = y, B1[B[0]] = 1;
    }
    if (B[0] != A[0]) {
      printf("No");
    } else {
      bool bz = 0;
      for (int i = 1; i <= A[0] && !bz; i++)
        if (A[i] != B[i])
          bz = 1;
        else
          bz = jian(A1[i], B1[i]);
      bz ? printf("No") : printf("Yes");
    }
    if (n) printf("\n");
  }
  return 0;
}
