//1.
#include <bits/stdc++.h>
using namespace std;
int main () {
int t, a, b;
cin >> t;
while (t--){
cin >> a >> b;
long long res = 1;
while (res < b) res *= a;
if (res == b) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
//2.
#include <bits/stdc++.h>
using namespace std;
int main () {
int t, a, b;
cin >> t;
while(t--){
cin >> a >> b;
while (b%a == 0)b = b/a;
if(b == 1) cout << "YES";
else cout << "NO";
cout << endl;
}
return 0;
}//🤣