#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long x) {
  for (int i = 2; i <= sqrt(x); i++)
    if (x % i == 0) return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    long long x = (a + b);
    cout << (is_prime(x) && a - b == 1 ? "YES" : "NO") << endl;
  }
}
