#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int x) {
  for (long long int d = 2; d * d <= x and d < x; d++)
    if (x % d == 0) return false;
  return true;
}
int cases;
int main() {
  cin >> cases;
  for (int cas = 0; cas < cases; cas++) {
    long long int a, b;
    cin >> a >> b;
    if (b + 1 < a or not isprime(a + b))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
