#include <bits/stdc++.h>
using namespace std;
void online_judge() {}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  online_judge();
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool flag = 1;
    set<long long int> s;
    for (long long int i = 0; i < n; ++i) {
      long long int index = 0;
      while (1) {
        if (a[i] == 0) {
          break;
        }
        long long int temp = 1;
        long long int cnt = 0;
        while ((temp * k) <= a[i]) {
          temp *= k;
          cnt++;
        }
        if (s.count(cnt)) {
          flag = 0;
          break;
        }
        s.insert(cnt);
        a[i] -= temp;
      }
    }
    if (flag) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}
