#include <bits/stdc++.h>
using namespace std;
long long arr[61];
long long a[31];
long long n, k;
bool convtok(long long n) {
  long long i = 0;
  while (n > 0) {
    long long x = n % k;
    n = n / k;
    ;
    if ((x == 1 && arr[i] == 0)) {
      arr[i] = x;
    } else if (x != 0)
      return false;
    i++;
  }
  return true;
}
bool chk() {
  for (long long i = 0; i < n; i++) {
    ;
    bool qw = convtok(a[i]);
    if (qw == false) return false;
  }
  return true;
}
signed main() {
  ;
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  long long t = 1;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    memset(arr, 0, sizeof(arr));
    memset(a, 0, sizeof(a));
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool fla = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] != 0) {
        fla = 1;
        break;
      }
    }
    if (fla) {
      bool bla = chk();
      if (bla) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    } else
      cout << "YES\n";
  };
}
