#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  map<long long, long long> cnt;
  while (t--) {
    cnt.clear();
    long long n, k;
    cin >> n >> k;
    bool flag = 1;
    for (long long i = 0; i < n; ++i) {
      long long x;
      cin >> x;
      for (long long i = 54; i >= 0; --i) {
        if (x >= pow(k, i)) {
          x -= pow(k, i);
          cnt[i]++;
        }
      }
      if (x > 0) flag = 0;
    }
    for (long long i = 54; i >= 0; --i) {
      if (cnt[i] > 1) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
