#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void io() {}
long long fast_exp(long long base, int exp, int m) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % m;
    }
    base = (base * base) % m;
    exp /= 2;
  }
  return res % m;
}
long long dp[2001][2001];
long long arr[200005];
long long val[200005];
long long siz[200005];
map<long long, long long> mp;
long long ans, cnt, tmp;
long long vis[200005];
vector<long long> adj[200005];
long long n, m, k;
bool check(long long n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  io();
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a - b == 1) {
      if (check(a + b)) {
        cout << "YES" << '\n';
      } else {
        cout << "NO" << '\n';
      }
    } else {
      cout << "NO" << '\n';
    }
  }
}
