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