#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k, ans, cnt = 0, f = 0, a, b;
    cin >> n >> k;
    if (k * k > n) {
      cout << "NO" << endl;
    } else if (n % 2 == 0 && k % 2 == 0) {
      cout << "YES" << endl;
    } else if (n % 2 != 0 && k % 2 != 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
