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