#include <bits/stdc++.h>
using namespace std;
bool solve(long long n, long long k) {
  if (n >= (k * (k + 1)) / 2) {
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tests = 1;
  cin >> tests;
  while (tests--) {
    long long n;
    cin >> n;
    long long k;
    cin >> k;
    if ((n - k) % 2) {
      cout << "NO" << '\n';
      ;
      continue;
    } else {
      if (solve((n - k) / 2, k - 1)) {
        cout << "YES" << '\n';
        ;
      } else
        cout << "NO" << '\n';
      ;
    }
  }
  return 0;
}
