#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
int t;
int main(int argc, char** argv) {
  scanf("%d", &t);
  long long a, b;
  while (t--) {
    scanf("%lld %lld", &a, &b);
    if (a - b != 1) {
      puts("NO");
      continue;
    }
    a += b;
    bool prime = true;
    for (long long i = 2; i * i <= a; i++) {
      if (a % i == 0) {
        prime = false;
        break;
      }
    }
    puts((prime) ? "YES" : "NO");
  }
  return 0;
}
