#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MAXN = 2e5 + 1;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int prs[1000];
void solve() {
  int n, k;
  cin >> n >> k;
  unsigned long long a[n];
  set<int> ms;
  int s0 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int b[65], cnt = 0;
  for (int i = 0; i <= 60; i++) {
    b[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cnt = 0;
    while (a[i] >= 1) {
      if (a[i] % k == 0) {
        cnt++;
        a[i] /= k;
      } else if ((a[i] - 1) % k == 0 && a[i] != 1) {
        if (b[cnt] == 0) {
          b[cnt] = 1;
        } else {
          cout << "NO" << endl;
          return;
        }
        a[i] -= 1;
      } else {
        if (a[i] == 1 && b[cnt] == 0) {
          b[cnt] = 1;
          break;
        } else {
          cout << "NO" << endl;
          return;
        }
      }
    }
  }
  cout << "YES" << endl;
}
int main() {
  int n = 1;
  cin >> n;
  while (n--) {
    solve();
  }
}
