#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n == 1) return false;
  for (long long d = 2; d * d <= n; d++)
    if (n % d == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  long long a, b;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cout << ((isPrime(a + b) and (a - b == 1)) ? "YES" : "NO") << '\n';
  }
  return 0;
}
