#include <bits/stdc++.h>
using namespace std;
long long a, b;
bool isprime(long long n) {
  if (n == 2 || n == 3) return 1;
  if (n % 6 != 1 && n % 6 != 5) return 0;
  long long ans = sqrt(n);
  for (int i = 5; i <= ans; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) return 0;
  }
  return 1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    if ((a - b) != 1)
      cout << "NO" << endl;
    else {
      if (isprime(a + b))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
