#include <bits/stdc++.h>
using namespace std;
int check_prime(long long int a) {
  long long int temp = sqrt(a), i;
  for (i = 2; i <= temp; i++) {
    if (a % i == 0ll) return 0;
  }
  return 1;
}
int main() {
  long long int t, a, b, temp;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &a, &b);
    if ((a - b) == 1) {
      if (check_prime(a + b) == 1) {
        cout << "YES\n";
      } else
        cout << "NO\n";
    } else
      cout << "NO\n";
  }
  return 0;
}
