#include <bits/stdc++.h>
using namespace std;
long long int M = 1000000007;
long long int sum[10000001];
int main() {
  long long int odd = 3;
  sum[0] = 1;
  for (long i = 1; i < 10000001; i++) {
    sum[i] = sum[i - 1] + odd;
    odd += 2;
  }
  int t;
  long n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    if ((n % 2 != 0 && k % 2 == 0) || (n % 2 == 0 && k % 2 != 0))
      cout << "NO" << endl;
    else if (n >= sum[k - 1])
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
