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