#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int T, i, j, k, n, t, f, a, b;
  cin >> T;
  for (t = 0; t < T; t++) {
    cin >> n >> k;
    long long int arr[n];
    map<long long int, long long int> fre;
    f = 1;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (i = 0; i < n; i++) {
      vector<long long int> rem;
      while (arr[i] > 0) {
        rem.push_back(arr[i] % k);
        arr[i] = arr[i] / k;
      }
      for (j = 0; j < rem.size(); j++) {
        if (rem[j] != 0 && rem[j] != 1) {
          f = 0;
          break;
        }
      }
      if (!f) break;
      for (j = 0; j < rem.size(); j++) {
        if (rem[j] == 1) {
          if (fre.find(j) != fre.end()) {
            f = 0;
            break;
          }
          fre[j] = 1;
        }
      }
      if (!f) break;
    }
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
