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