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