#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, ar[103];
  cin >> t;
  set<int> st;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    sort(ar, ar + n);
    bool flg = true;
    for (int i = 0; i < n; i++) {
      if (ar[i] == 0) continue;
      long long int tmp = 0, tmp2 = 0;
      while (ar[i]) {
        long long int fuck = 1, myar = ar[i], tmp = 0;
        bool ok = false;
        while (myar >= k) {
          myar /= k;
          ok = true;
          tmp++;
          fuck *= k;
        }
        if (ok) {
          if (st.count(tmp) > 0)
            flg = false;
          else
            st.insert(tmp);
          ar[i] -= fuck;
        }
        if (ar[i] < k && ar[i] != 0) {
          if (ar[i] == 1) {
            if (st.count(0) > 0)
              flg = false;
            else
              st.insert(0);
            ar[i] -= 1;
          } else
            flg = false;
        }
        if (!flg) break;
      }
      if (!flg) break;
    }
    if (flg)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    st.clear();
  }
}
