#include <bits/stdc++.h>
using namespace std;
int t, n, k;
int a[1000];
long long inp[100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < 1000; i++) {
      a[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> inp[i];
    }
    bool fl = 0;
    for (int i = 0; i < n; i++) {
      int j = 0;
      while (inp[i] > 0) {
        int de = inp[i] % k;
        if (de == 1) {
          if (a[j]) {
            cout << "NO" << endl;
            fl = 1;
            break;
          } else
            a[j] = de;
        } else if (de > 1) {
          cout << "NO" << endl;
          fl = 1;
          break;
        }
        j++;
        inp[i] /= k;
      }
      if (fl) break;
    }
    if (!fl) cout << "YES" << endl;
  }
  return 0;
}
