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