#include <bits/stdc++.h>
using namespace std;
long long int N = 1e6;
vector<bool> isprime(N + 1, true);
map<long long int, int> m;
long long int k;
void seive() {
  isprime[0] = false;
  isprime[1] = false;
  for (int i = 2; i * i <= 1e6; i++) {
    if (isprime[i]) {
      for (int j = i * i; j <= 1e6; j += i) {
        isprime[j] = false;
      }
    }
  }
}
int findfrnd(bitset<32> x, bitset<32> y, int q) {
  int p = 0;
  for (int i = 0; i < 32; i++) {
    if (x[i] != y[i]) {
      p++;
      if (p > q) return 0;
    }
  }
  return 1;
}
int powk(long long int x) {
  int ind = 0;
  while (x) {
    if (x % k > 1) {
      return 0;
    }
    if (x % k == 1 && m.find(ind) != m.end()) return 0;
    if (x % k) m[ind]++;
    x /= k;
    ind++;
  }
  return 1;
}
void solve() {
  m.clear();
  long long int n;
  cin >> n >> k;
  long long int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int i = 0;
  while (a[i] == 0) {
    i++;
  }
  if (i == n) {
    cout << "YES" << endl;
    return;
  }
  long long int q = i;
  for (; i < n; i++) {
    if (a[i] == a[i - 1]) {
      cout << "NO" << endl;
      return;
    }
  }
  for (; q < n; q++) {
    if (!powk(a[q])) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  seive();
  int test;
  cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}
