#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> step(100, 0);
  for (long long i = 0; i < n; i++) {
    long long x = 0;
    while (a[i] > 0) {
      step[x] += a[i] % k;
      a[i] /= k;
      x++;
    }
  }
  for (long long i = 0; i < 100; i++) {
    if (step[i] > 1) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    solve();
  }
}
