#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  long long x, y, s, x1, y1, l, m;
  bool flag1, flag2;
  cin >> t;
  while (t--) {
    cin >> x >> y;
    s = gcd(x, y);
    x1 = x / s;
    y1 = y / s;
    if (x % (x1 * x1) == 0) {
      x /= (x1 * x1);
      if (x % y1 == 0) {
        x /= y1;
        l = cbrt(x);
        if ((l * l * l) == x)
          flag1 = true;
        else
          flag1 = false;
      } else
        flag1 = false;
    } else
      flag1 = false;
    if (y % (y1 * y1) == 0) {
      y /= (y1 * y1);
      if (y % x1 == 0) {
        y /= x1;
        m = cbrt(y);
        if ((m * m * m) == y)
          flag2 = true;
        else
          flag2 = false;
      } else
        flag2 = false;
    } else
      flag2 = false;
    if (flag1 && flag2)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}
