#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int n) {
  if (n == 2) return true;
  for (long long int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    long long int diff;
    diff = a - b;
    if (diff != 1) {
      cout << "NO"
           << "\n";
      continue;
    }
    if (isPrime(a + b))
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
