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