#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long t;
  cin >> t;
  while (t--) {
    long long n, k;
    bool f = true;
    cin >> n >> k;
    vector<long long> a(n);
    for (long i = 0; i < n; ++i) cin >> a[i];
    int res[100] = {0};
    for (int i = 0; f && i < n; ++i) {
      if (a[i] != 0) {
        long long tmp = a[i];
        for (int j = 0; f && tmp > 0; ++j) {
          long long b = tmp % k;
          if (b > 1) {
            f = false;
            break;
          }
          if (b == 1) {
            if (res[j] != 0)
              f = false;
            else
              res[j]++;
          }
          tmp /= k;
        }
      }
    }
    if (f)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
