#include <bits/stdc++.h>
using namespace std;
long long int a[35], cnt[64], k;
int main() {
  int t, n, i;
  cin >> t;
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    int flag = 1;
    cin >> n >> k;
    for (i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      int c = 0;
      while (a[i]) {
        c++;
        cnt[c] += (a[i] % k);
        a[i] /= k;
        if (cnt[c] > 1) flag = 0;
      }
    }
    if (flag) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
