#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long int x) {
  for (long long int i = 2; i <= (long long int)sqrt(x); i++) {
    if (x % i == 0) return false;
  }
  return true;
}
int main() {
  long long int m[5][2];
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> m[i][0];
    cin >> m[i][1];
  }
  long long int sub;
  for (int i = 0; i < t; i++) {
    sub = abs(m[i][0] - m[i][1]);
    if (sub == 1) {
      if (isPrime(m[i][0] + m[i][1])) {
        cout << "YES";
      } else {
        cout << "NO";
      }
    } else {
      cout << "NO";
    }
    cout << endl;
  }
  return 0;
}
