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