#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long num) {
  if (num == 1) return false;
  if (num == 2 || num == 3) return true;
  if (num % 6 != 1 && num % 6 != 5) return false;
  for (long long i = 5; i * i <= num; i += 6)
    if (num % i == 0 || num % (i + 2) == 0) return false;
  return true;
}
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    long long temp1, temp2;
    cin >> temp1 >> temp2;
    if (abs(temp2 - temp1) != 1) {
      cout << "NO" << endl;
      continue;
    } else {
      if (isPrime(temp1 + temp2))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
