#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    map<int, int> p;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool ans = true;
    auto f = [&](long long g) {
      int l = 0;
      while (g > 0) {
        if (g % k > 1) {
          ans = false;
        }
        if (g % k == 1) {
          p[l] += 1;
        }
        g /= k;
        l++;
      }
    };
    for (int i = 0; i < n; i++) {
      f(a[i]);
    }
    for (auto& i : p) {
      if (i.second > 1) {
        ans = false;
      }
    }
    cout << (ans ? "YES" : "NO") << "\n";
  }
  return 0;
}
