#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k, p, i, c = 0, flag = 0, cc = 1e16, mp = 1ll;
    cin >> n >> k;
    p = k;
    vector<long long int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    while (mp < cc) {
      mp = mp * k;
      c++;
    }
    while (c) {
      sort(a.begin(), a.end());
      long long int po = pow(p, c);
      if (po <= a[n - 1]) a[n - 1] -= po;
      c--;
    }
    sort(a.begin(), a.end());
    if (a[n - 1] == 1) a[n - 1] -= 1;
    for (i = 0; i < n; i++) {
      if (a[i] != 0) {
        cout << "NO\n";
        flag = 1;
        break;
      }
    }
    if (!flag) cout << "YES\n";
  }
  return 0;
}
