#include <bits/stdc++.h>
using namespace std;
const long long INFLL = 2 * (long long)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = 1e3 + 7;
const int MOD = 1e9 + 7;
const int NMAX = 1e3 + 5;
int t;
long long a, b;
bool is_prime(long long x) {
  if (x <= 1) return 0;
  if (x == 2) return 1;
  if (x % 2 == 0) return 0;
  for (long long i = 3; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
void solve() {
  cin >> a >> b;
  if (a - b != 1) {
    cout << "NO\n";
    return;
  }
  if (is_prime(a + b))
    cout << "YES\n";
  else
    cout << "NO\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int i = 1; i <= t; i++) solve();
  return 0;
}
