#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e3 + 5;
const long long mod = (long long)1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long b, a;
    cin >> b >> a;
    if (b - a > 1)
      cout << "NO\n";
    else {
      long long res = 0;
      long long chk = b + a;
      for (long long i = 1; i * i <= chk; i++) {
        if (chk % i == 0) {
          if (i == chk / i)
            res += 1;
          else
            res += 2;
        }
      }
      cout << (res == 2 ? "YES\n" : "NO\n");
    }
  }
  return 0;
}
