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