#include <bits/stdc++.h>
using namespace std;
bool change_base(int64_t x, int64_t k, vector<int64_t>& res) {
  if (x == 0) {
    res.push_back(0);
    return true;
  }
  while (x != 0) {
    if (x % k > 1) {
      return false;
    }
    res.push_back(x % k);
    x /= k;
  }
  return true;
}
bool good(int64_t x, int64_t k, int64_t n, vector<bool>& v) {
  vector<int64_t> res;
  res.reserve(n);
  auto okay = change_base(x, k, res);
  if (!okay) {
    return false;
  } else {
    int64_t len = res.size();
    for (int64_t i = 0; i < len; i++) {
      if (i >= v.size()) {
        v.push_back(true);
      }
      if (res[i] == 1) {
        if (!v[i]) {
          return false;
        } else {
          v[i] = false;
        }
      }
    }
    return true;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int64_t tc;
  cin >> tc;
  for (int64_t tt = 0; tt < tc; tt++) {
    int64_t n;
    int64_t k;
    cin >> n >> k;
    vector<bool> v(n, true);
    vector<int64_t> res(n);
    bool okay = true;
    for (int64_t i = 0; i < n; i++) {
      cin >> res[i];
      if (okay && good(res[i], k, n, v)) {
        continue;
      } else {
        okay = false;
      }
    }
    if (!okay) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
  return 0;
}
