#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  int t;
  cin >> t;
  string y = "YES\n", z = "NO\n";
  while (t--) {
    long long int a, b, i, j;
    cin >> a >> b;
    if (a - b != 1)
      cout << z;
    else {
      if (isprime(a + b))
        cout << y;
      else
        cout << z;
    }
  }
}
