#include <bits/stdc++.h>
using namespace std;
long long s[100001], w[31];
int main() {
  long long t, n, k, i, j, pd, zc, sl, zpd;
  cin >> t;
  while (t--) {
    for (i = 1; i <= 30; i++) w[i] = 0;
    for (i = 1; i <= 100000; i++) s[i] = 0;
    cin >> n >> k;
    zc = 1;
    sl = 0;
    while (zc <= 1e16) {
      sl++;
      s[sl] = zc;
      zc *= k;
    }
    for (i = 1; i <= n; i++) cin >> w[i];
    sort(w + 1, w + 1 + n);
    for (i = sl; i >= 1; i--) {
      for (j = n; j >= 1; j--) {
        if (w[j] >= s[i]) {
          w[j] -= s[i];
          break;
        }
      }
    }
    for (i = pd = 1; i <= n; i++) {
      if (w[i] > 0) {
        pd = 0;
        break;
      }
    }
    if (pd == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
