#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long n, k;
long long a[maxn];
map<int, int> mp;
bool check(long long x) {
  while (x) {
    long long base = 1;
    long long cnt = 0;
    while (x >= base) {
      base *= k;
      ++cnt;
    }
    base /= k;
    --cnt;
    ++mp[cnt];
    if (mp[cnt] > 1) return 1;
    x -= base;
  }
  return 0;
}
void solve() {
  mp.clear();
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  if (k == 1) {
    cout << "YES" << endl;
    return;
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i]) {
      if (check(a[i]) == 1) {
        cout << "NO" << endl;
        return;
      }
    }
  }
  cout << "YES" << endl;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
