#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
class CMP {
 public:
  bool operator()(long long int a, long long int b) { return !(a <= b); }
};
void add(map<long long int, long long int> &m, long long int x) {
  map<long long int, long long int>::iterator jt;
  jt = m.find(x);
  if (jt == m.end())
    m.insert(make_pair(x, 1));
  else
    jt->second++;
}
void del(map<long long int, long long int> &m, long long int x) {
  map<long long int, long long int>::iterator jt;
  jt = m.find(x);
  if (jt->second == 1)
    m.erase(jt);
  else
    jt->second--;
}
bool cmp(const pair<long long int, long long int> &a,
         const pair<long long int, long long int> &b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
const long long int mod = 1000000007L;
long long int T, n, i, m, j, k, in, cnt, l, r;
long long int a, b;
vector<long long int>::iterator it;
string s;
bool isPrime(long long int n) {
  for (long long int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> T;
  while (T--) {
    cin >> a >> b;
    if (a != b + 1 || isPrime(a + b) == false) {
      cout << "NO"
           << "\n";
    } else {
      cout << "YES"
           << "\n";
    }
  }
  aryanc403();
  return 0;
}
