/* this code is given by adiittya 0v0 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
// to find the power of number in case of high / large input values
int power(int i,int j,int p){
if(j==0){
return 1;
}
if(j==1){
return i;
}
long long ans=power(i,j/2,p);
ans=(ans*ans)%p;
if(j%2==1){
ans=(ans*i)%p;
}
return ans;
}
// pow exponentiation--> used to prevent the use of pow(a , n) method
double myPow(double x, int n) {
long long nn=n;
double ans=1.0;
if(nn<0)
nn=-1*nn;
while(nn)
{
if(nn%2)
{
ans=ans*x;
nn=nn-1;
}
else
{
x=x*x;
nn=nn/2;
}
}
if(n<0)
return (double)(1.0)/(double)(ans);
else
return ans;
}
// Prime func. in sqrt(n) - time
bool isprime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------
bool fun(int n, int m)
{
if(n%3!=0)
return false;
if(n/3==m || 2*(n/3)==m)
return true;
else
{
if(fun(n/3 , m))
return true;
if(fun(2*(n/3) , m))
return true;
}
return false;
}
// solve func. to write any program.
void solve()
{
ll n, m;
cin>>n>>m;
if(n==m)
{
cout<<"YES"<<endl;
return;
}
if(n%3!=0 || m>n)
{
cout<<"NO"<<endl;
return;
}
if(fun(n, m))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a;
cin>>a;
while(a--)
{
solve();
}
}
// 11
// 6 4
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// YES
// 1 1
// NO
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
// 11
// 6 4
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// NO
// 1 1
// YES
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
// YES
// 9 4
// YES
// 4 2
// NO
// 18 27
// NO
// 27 4
// YES
// 27 2
// YES
// 27 10
// NO
// 1 1
// YES
// 3 1
// YES
// 5 1
// NO
// 746001 2984004
// NO
402. Remove K Digits | 97. Interleaving String |
543. Diameter of Binary Tree | 124. Binary Tree Maximum Path Sum |
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | 501A - Contest |
160A- Twins | 752. Open the Lock |
1535A - Fair Playoff | 1538F - Interesting Function |
1920. Build Array from Permutation | 494. Target Sum |
797. All Paths From Source to Target | 1547B - Alphabetical Strings |
1550A - Find The Array | 118B - Present from Lena |
27A - Next Test | 785. Is Graph Bipartite |
90. Subsets II | 1560A - Dislike of Threes |
36. Valid Sudoku | 557. Reverse Words in a String III |
566. Reshape the Matrix | 167. Two Sum II - Input array is sorted |
387. First Unique Character in a String | 383. Ransom Note |
242. Valid Anagram | 141. Linked List Cycle |
21. Merge Two Sorted Lists | 203. Remove Linked List Elements |