#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int inf = 1e9;
bool isprime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long val = n - k;
  long long val2 = n + k;
  if (val == 1 && isprime(val2)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
