#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(long long x);

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long x, k;
        cin >> x >> k;

        if (k == 1) {
            if (isPrime(x)) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } 
        else if (x == 1 && k == 2) {
            cout << "YES" << endl;
        } 
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

bool isPrime(long long x) {
    if (x < 2) return false;
    for (long long i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}