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