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