#include <bits/stdc++.h>
using namespace std;
bool prime(long long x) {
  if (x == 2) return 1;
  if (x % 2 == 0) return 0;
  for (long long j = 3; j * j <= x; j += 2) {
    if (x % j == 0) return 0;
  }
  return 1;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (n - m > 1) {
      cout << "NO" << endl;
    } else {
      if (prime(n + m)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}
