#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
bool overflow(long long a, long long b) {
  if (a <= LLONG_MAX / b) return 0;
  return 1;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v1(n);
  for (auto& it : v1) cin >> it;
  long long num = 1;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    long long tmp = v1[i];
    int cnt = 0;
    while (tmp) {
      if (tmp % k) {
        if (tmp % k > 1) {
          cout << "NO"
               << "\n";
          return;
        }
        if (mp[cnt]) {
          cout << "NO"
               << "\n";
          return;
        }
        mp[cnt]++;
      }
      cnt++;
      tmp /= k;
    }
  }
  cout << "YES"
       << "\n";
}
int main() {
  file();
  fast();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
