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