#include <bits/stdc++.h>
using namespace std;
bool isP(unsigned long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    unsigned long long a, b;
    cin >> a >> b;
    if (isP(a + b) && a - b == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
