#include <bits/stdc++.h>
using namespace std;
const int n = 10000000;
bitset<n> b;
vector<int> v;
void sieve() {
  b.set();
  b[0] = 0;
  b[1] = 0;
  for (long long i = 2; i <= n; i++) {
    if (b[i]) {
      v.push_back(i);
      for (long long j = i * i; j <= n; j = j + i) {
        b[j] = 0;
      }
    }
  }
}
bool large_prime(long long no) {
  if (no <= n) {
    if (b[no]) {
      return true;
    } else {
      return false;
    }
  }
  for (long long i = 0; v[i] * (long long)v[i] <= no; i++) {
    if (no % v[i] == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  sieve();
  long long a, b;
  while (t--) {
    cin >> a >> b;
    if (a - b == 1) {
      long long ans = (a - b) * (a + b);
      if (large_prime(ans)) {
        cout << "YES"
             << "\n";
      } else {
        cout << "NO"
             << "\n";
      }
    } else {
      cout << "NO"
           << "\n";
    }
  }
}
