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