#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  for (int w = 1; w <= t; w++) {
    long long int n, k;
    cin >> n >> k;
    if ((n % 2 == 0 && k % 2 != 0) || k * k > n || (n % 2 != 0 && k % 2 == 0))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
