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