#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
using LL = int_fast64_t;
LL n, k;
void solve() {
  cin >> n >> k;
  LL tot = (1 + 2 * k - 1) * k / 2;
  if (k & 1 and !(n & 1)) {
    cout << "NO" << endl;
    return;
  }
  if (!(k & 1) and (n & 1)) {
    cout << "NO" << endl;
    return;
  }
  if (tot <= n)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  ____();
  int T;
  for (cin >> T; T; T--) solve();
  return 0;
}
