#include <bits/stdc++.h>
using namespace std;
long long isprime(long long a) {
  long long sq = sqrt(a);
  for (long long i = 2; i <= sq; i++) {
    if (a % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a != b + 1)
      cout << "NO\n";
    else if (isprime(2 * a - 1)) {
      cout << "YES\n";
    } else
      cout << "NO\n";
  }
  return 0;
}
