#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e3 + 5;
const int N = (int)2e5 + 5;
const int INF = (int)1e9 + 228;
const long long LLINF = (long long)1e18 + 228;
const int MOD = (int)1e9 + 7;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    if (n % 2 != k % 2) {
      cout << "NO\n";
      continue;
    }
    long long fst = 1, lst = fst + 2 * (k - 1);
    if ((fst + lst) * k / 2 <= n)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
