#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    long long n, k;
    cin >> n >> k;
    long long sum = k * k;
    if (sum > n)
      cout << "NO" << '\n';
    else {
      if (n % 2 == 0) {
        if (k & 1)
          cout << "NO" << '\n';
        else
          cout << "YES" << '\n';
      } else {
        if (k & 1)
          cout << "YES" << '\n';
        else
          cout << "NO" << '\n';
      }
    }
  }
  return 0;
}
