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