#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,l;
cin>>n;
while(n--){
cin>>k>>l;
long long res=1;
while(res<l)res*=k;
if(res==l)cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
s
s
s
屎