#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long int x, y;
    cin >> x >> y;
    if (pow(y, 2) > x)
      cout << "NO\n";
    else if (x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0)
      cout << "YES\n";
    else {
      cout << "NO\n";
    }
  }
  return 0;
}
