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