#include <bits/stdc++.h>
using namespace std;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long int> res;
    res.push_back(1);
    while (res[res.size() - 1] <= 10000000000000001)
      res.push_back(res[res.size() - 1] * k);
    bool flag = false;
    for (int i = 0; i < n; i++) {
      bool done = false;
      for (int j = res.size() - 1; j >= 0; j--) {
        if (a[i] >= res[j]) {
          a[i] -= res[j];
          res[j] = 0;
        }
        if (j == 0 && a[i] > 0) {
          done = true;
          break;
        }
      }
      if (done) {
        flag = true;
        break;
      }
    }
    if (flag)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
