#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int cas, m, n;
  cin >> cas;
  while (cas--) {
    cin >> n >> m;
    if (m == 1 && n == 1)
      cout << "YES" << endl;
    else if (m >= n || m * m > n || n % 2 != 0 && m % 2 == 0 ||
             n % 2 == 0 && m % 2 != 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
