#include <bits/stdc++.h>
int get_int() {
  int x = 0, y = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') y = -1, ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * y;
}
int main() {
  int T = get_int();
  while (T--) {
    int n = get_int(), k = get_int();
    if (n % 2 != k % 2) {
      std::cout << "NO" << std::endl;
      continue;
    }
    long long sum = 1LL * k * k;
    if (n < sum) {
      std::cout << "NO" << std::endl;
      continue;
    }
    if ((n - sum) % 2 == 0) {
      std::cout << "YES" << std::endl;
      continue;
    }
    std::cout << "NO" << std::endl;
  }
  return 0;
}
