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