#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b;
bool prime(long long x) {
  if (x == 2) return 1;
  if (x % 2 == 0 || x <= 1) return 0;
  for (long long i = 3; i * i <= x; i += 2)
    if (x % i == 0) return 0;
  return 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a == b + 1 && prime(a + b))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
