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