#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  vector<long long> powers;
  long long z = 1;
  powers.push_back(1);
  while (z * k <= 1e16) powers.push_back(z * k), z = z * k;
  set<long long> used;
  for (long long i = 0; i < n; i++) {
    long long tp = v[i];
    for (long long i = powers.size() - 1; i >= 0; i--) {
      if (tp >= powers[i]) {
        if (used.find(i) != used.end()) {
          cout << "NO" << '\n';
          return;
        }
        tp -= powers[i];
        used.insert(i);
      }
    }
    if (tp) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
