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