#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int up = 65;
long long findMax(long long &a, long long k) {
  long long res = 1;
  long long cnt = 0;
  while (res < a) {
    res *= k;
    cnt++;
  }
  if (res > a) res /= k, cnt--;
  a -= res;
  return cnt;
}
void C() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> cnt(up, 0);
  for (int i = 0; i < n; i++) {
    while (a[i]) {
      long long tmp = findMax(a[i], k);
      cnt[tmp]++;
      if (cnt[tmp] > 1) {
        cout << "NO\n";
        return;
      }
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    C();
  }
  return 0;
}
