#include <bits/stdc++.h>
using namespace std;
long long int power(long long int k, long long int x) {
  long long int c = 1;
  for (long long int i = 0; i < x; i++) {
    c = c * k;
  }
  return c;
}
signed main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    vector<long long int> a;
    for (long long int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      a.push_back(x);
    }
    set<long long int> s;
    sort(a.begin(), a.end());
    long long int p = 0;
    for (long long int i = n - 1; i >= 0; i--) {
      while (a[i] > 0) {
        long long int x = -1;
        long long int b = a[i];
        while (b > 0) {
          b = b / k;
          x++;
        }
        if (s.find(x) == s.end()) {
          s.insert(x);
          a[i] = a[i] - power(k, x);
        } else {
          p++;
          break;
        }
      }
      if (p > 0) {
        break;
      }
    }
    if (p > 0) {
      cout << "NO" << endl;
      continue;
    } else {
      cout << "YES" << endl;
    }
  }
}
