#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int flag[63];
  memset(flag, 0, sizeof(flag));
  for (int i = 0; i < n; i++) {
    int j = 0;
    long long int val = 1;
    while (val < a[i]) {
      val *= k;
      j++;
    }
    while (val != 0) {
      if (a[i] >= val && flag[j] == 0) {
        a[i] -= val;
        flag[j] = 1;
      }
      j--;
      val /= k;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) {
      cout << "NO\n";
      return;
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
