#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, k, x;
  cin >> t;
  bool ok;
  while (t--) {
    cin >> n >> k;
    if (n < (k * k))
      ok = false;
    else {
      x = n - (k * k);
      if (x == 0)
        ok = true;
      else {
        if (x % 2 == 0)
          ok = true;
        else
          ok = false;
      }
    }
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
