#include <bits/stdc++.h>
using namespace std;
const int p_limit = 447300;
int status[p_limit / 32 + 1];
bool check_status(int &n, int pos) { return (n & (1 << pos)); }
void set_status(int &n, int pos) { n = n | (1 << pos); }
int prime[37506];
int p = 0;
void sieve() {
  prime[p++] = 2;
  int sq = sqrt(p_limit);
  int i;
  for (i = 3; i <= sq; i += 2) {
    if (check_status(status[i >> 5], i & 31) == false) {
      prime[p++] = i;
      for (int j = i * i; j < p_limit; j += i * 2) {
        set_status(status[j >> 5], j & 31);
      }
    }
  }
  for (; i < p_limit; i += 2) {
    if (check_status(status[i >> 5], i & 31) == false) {
      prime[p++] = i;
    }
  }
}
bool isPrime(long long value) {
  int sq = sqrt(value);
  for (int i = 0; prime[i] <= sq && i < p; i++) {
    if (value % prime[i] == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  sieve();
  int t;
  scanf("%d", &t);
  for (int tlc = 1; tlc <= t; tlc++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    if (a - b != 1) {
      printf("NO\n");
      continue;
    }
    if (isPrime(a + b))
      printf("YES\n");
    else
      printf("NO\n");
  }
}
