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