#include <bits/stdc++.h>
using namespace std;
template <typename T>
T getint() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') p = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * p;
}
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {
  if (x > y) return x = y, true;
  return false;
}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {
  if (x < y) return x = y, true;
  return false;
}
const int maxn = (int)(1 << 10) + 10;
const int inf = (int)1e9 + 5;
const int mod = 1e9 + 7;
const long long llinf = (long long)1e18 + 5;
const long double pi = acos(-1.0);
int a[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    auto prime = [](long long x) {
      for (long long i = 2; i * i <= x; ++i) {
        if (x % i == 0) return false;
      }
      return true;
    };
    if (a - b > 1 || !prime(a + b)) {
      cout << "NO\n";
    } else
      cout << "YES\n";
  }
  return 0;
}
