#include <bits/stdc++.h>
using namespace std;
const long long mod = 10e9 + 7;
const int maxN = 10001;
vector<unsigned long long> trialDivision(unsigned long long n) {
  vector<unsigned long long> primeFactors;
  while (n % 2 == 0) {
    primeFactors.push_back(2);
    n /= 2;
  }
  unsigned long long factor = 3;
  while (factor * factor <= n) {
    if (n % factor == 0) {
      primeFactors.push_back(factor);
      n /= factor;
    } else {
      factor += 2;
    }
  }
  if (n != 1) primeFactors.push_back(n);
  return primeFactors;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  unsigned long long a, b;
  string ans[5];
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    if (a - b != 1) {
      ans[i] = "NO";
    } else {
      unsigned long long area = (a + b) * (a - b);
      vector<unsigned long long> v = trialDivision(area);
      ans[i] = v.size() == 1 ? "YES" : "NO";
    }
  }
  for (int i = 0; i < t; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
