#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const long long oo = 1e18;
const long long mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a - b > 1) {
      puts("NO");
      continue;
    }
    long long ans = a + b;
    bool ok = true;
    for (int i = 2; i <= sqrt(double(ans)); i++) {
      if (ans % i == 0) {
        ok = false;
        break;
      }
    }
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
