#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; ++i) solve();
  cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}
void solve() {
  long long n, k;
  cin >> n >> k;
  std::vector<unsigned long long> a(n);
  unsigned long long sum = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sum = max(sum, a[i]);
  }
  unsigned long long cur = 1;
  long long i = 0;
  std::vector<unsigned long long> v(100);
  v[0] = cur;
  while (cur * k <= sum) {
    cur *= k;
    i++;
    v[i] = cur;
  }
  std::vector<long long> vis(100, 0);
  for (long long kk = 0; kk < n; ++kk) {
    for (long long j = i; j >= 0; --j) {
      if (vis[j]) continue;
      if (a[kk] >= v[j]) {
        a[kk] -= v[j];
        vis[j] = 1;
      }
    }
    if (a[kk]) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
}
