#include <bits/stdc++.h>
using namespace std;
long long pf = 1e16;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long a[n];
    long long nax = 0;
    long long hj = 1;
    for (long long i = 0; true; i++) {
      if (hj > pf) break;
      nax++;
      hj *= k;
    }
    long long p[nax];
    p[0] = 1;
    for (int i = 1; i < nax; i++) p[i] = k * p[i - 1];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long gh = 0;
    long long vis[55] = {0};
    for (int i = 0; i < n; i++) {
      while (a[i] != 0) {
        long long pos = -1;
        for (int j = 0; j < nax; j++) {
          if (vis[j] == 1) continue;
          if (p[j] <= a[i]) {
            pos = j;
          }
        }
        if (pos == -1) break;
        vis[pos] = 1;
        a[i] -= p[pos];
      }
      if (a[i] != 0) {
        gh = 1;
        break;
      }
    }
    if (gh == 1)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
