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