#include <bits/stdc++.h>
using namespace std;
int MAX_INT = numeric_limits<int>::max();
int MIN_INT = numeric_limits<int>::min();
long long MAX_LL = numeric_limits<long long>::max();
long long MIN_LL = numeric_limits<long long>::min();
bool prime(long long n) {
  if (n == 1) return false;
  if (n == 2) return true;
  for (long long i = 2; i < 4 * sqrt(n); i++) {
    if (i < n && n % i == 0) return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long a, b;
    cin >> a >> b;
    if (a - b > 1) {
      cout << "NO" << '\n';
      continue;
    }
    if (prime((a + b))) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
