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