#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    int f = 0;
    long long area = a * a - b * b;
    if ((a - b) != 1)
      cout << "NO";
    else {
      area = a + b;
      for (int i = 2; i <= sqrt(a + b); i++) {
        if (area % i == 0) {
          cout << "NO";
          f = 1;
          break;
        }
      }
      if (f == 0) cout << "YES";
    }
    cout << endl;
  }
}
