#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long a[n + 1];
    for (int i = 0; i <= n - 1; i++) cin >> a[i];
    sort(a, a + n);
    vector<long long> v;
    long long s = 1;
    while (s <= 1e17) {
      v.push_back(s);
      s = s * k;
    }
    int f = 0;
    int w = v.size();
    vector<bool> vis(w + 1, false);
    for (int i = 0; i < n; i++) {
      if (a[i] == 0) continue;
      for (int j = v.size() - 1; j >= 0; j--) {
        if (a[i] >= v[j] && vis[j] == false) {
          vis[j] = true;
          a[i] = a[i] - v[j];
        }
      }
      if (a[i] != 0) {
        cout << "NO\n";
        f = 1;
        break;
      }
    }
    if (f == 0) cout << "YES\n";
  }
  return 0;
}
