#include <iostream>
#include <vector>

using namespace std;
vector<long> yueShu(long a)
{
    vector<long> vec;
    vec.push_back(1);
    for (int i = 2; i < a; i++)
    {
        if (a%i == 0)
        {
            vec.push_back(i);
            //cout << i << " ";
        }
    }
    return vec;
}

long sum(vector<long> v)
{
    long s = 0;
    for (int vi : v)
    {
        s += vi;
    }
    return s;
}
int main()
{
    long n,a,b;
    while (cin >> n)
    {
        while (n--)
        {
            cin >> a >> b;
            vector<long> v1 = yueShu(a);
            vector<long> v2 = yueShu(b);
            long s1 = sum(v1);
            long s2 = sum(v2);
            if (s1 == b && s2 == a)
            {
                cout << "YES" << endl;
            }
            else
            {
                cout << "NO" << endl;
            }
        }
    }
}