#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
const long long maxm = 1e3 + 5;
inline void qread() {}
template <class T1, class... T2>
inline void qread(T1 &IEE, T2 &...ls) {
  register T1 __ = 0, ___ = 1;
  register char ch;
  while (!isdigit(ch = getchar())) ___ = (ch == '-') ? -___ : ___;
  do {
    __ = (__ << 1) + (__ << 3) + (ch ^ 48);
  } while (isdigit(ch = getchar()));
  __ *= ___;
  IEE = __;
  qread(ls...);
  return;
}
long long n, m;
int main() {
  long long t;
  qread(t);
  while (t--) {
    qread(n, m);
    if (n < m * m) {
      puts("NO");
    } else if (n & 1) {
      if (m & 1) {
        puts("YES");
      } else {
        puts("No");
      }
    } else {
      if (m & 1) {
        puts("NO");
      } else {
        puts("YES");
      }
    }
  }
  return 0;
}
