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