#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
namespace basic {
using ll = long long int;
const ll inf = 1e9 + 7;
template <class T>
void refresh(T& a, ll n) {
  assert(n >= 0);
  a.clear();
  a.resize(n);
}
template <class X, class Y>
void refresh_with_value(X& a, ll n, Y value) {
  assert(n >= 0);
  a.clear();
  a.resize(n, value);
}
template <class X>
void Unique(X& a) {
  sort((a).begin(), (a).end());
  a.resize(distance(a.begin(), unique((a).begin(), (a).end())));
}
template <class T>
void smin(T& a, T b) {
  a = min(a, b);
}
template <class T>
void smax(T& a, T b) {
  a = max(a, b);
}
}  // namespace basic
using namespace basic;
namespace IO {
void open() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void close() {}
template <class T>
istream& operator>>(istream& cin, vector<T>& a) {
  for (auto& i : a) cin >> i;
  return cin;
}
istream& operator>>(istream& cin, pair<ll, ll>& a) {
  cin >> a.first;
  cin >> a.second;
  return cin;
}
istream& operator>>(istream& cin, pair<int, int>& a) {
  cin >> a.first;
  cin >> a.second;
  return cin;
}
template <class X>
ostream& operator<<(ostream& cout, pair<X, X>& a) {
  cout << a.first << " " << a.second << "\t";
  return cout;
}
template <class X>
ostream& operator<<(ostream& cout, vector<X>& a) {
  for (auto i : a) cout << i << " ";
  return cout;
}
template <class X>
ostream& operator<<(ostream& cout, vector<vector<X>>& a) {
  for (auto& i : a) {
    cout << i << "\n";
  }
  return cout;
}
template <class X, class Y>
ostream& operator<<(ostream& cout, unordered_map<X, Y>& a) {
  for (auto& i : a) {
    cout << i.first << "\t" << i.second << "\n";
  }
  return cout;
}
template <class X, class Y>
ostream& operator<<(ostream& cout, map<X, Y>& a) {
  for (auto& i : a) {
    cout << i.first << "\t" << i.second << "\n";
  }
  return cout;
}
template <class X>
ostream& operator<<(ostream& cout, set<X>& a) {
  for (auto i : a) cout << i << " ";
  return cout;
}
void in(double& x) {
  string t;
  cin >> t;
  x = stod(t);
}
void in(long double& x) {
  string t;
  cin >> t;
  x = stold(t);
}
template <class T>
void in(T& x) {
  cin >> x;
}
template <class X, class... Args>
void in(X& first, Args&... rest) {
  in(first);
  in(rest...);
}
const int precision = 1;
void out(long double& x) {
  cout << fixed << setprecision(precision) << x << '\n';
}
template <class T>
void out(T x) {
  cout << x << '\n';
}
template <class Arg, class... Args>
void out(Arg first, Args... rest) {
  cout << first << ' ';
  out(rest...);
}
}  // namespace IO
using namespace IO;
ll max_pow(ll n, ll k) {
  if (n == 1) return 0;
  ll ret = 0;
  ll pr = 1;
  while (pr < n) {
    pr *= k;
    ret++;
  }
  if (pr == n) return ret;
  return ret - 1;
}
ll pow(ll a, ll b, ll mod = LLONG_MAX) {
  if (b == 0) return 1;
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    b >>= 1;
  }
  return res;
}
vector<ll> get(ll i, ll k) {
  vector<ll> ret;
  while (i > 0) {
    ret.push_back(max_pow(i, k));
    i -= pow(k, max_pow(i, k));
  }
  return ret;
}
vector<ll> get_down(map<ll, ll> mp, ll k) {
  if (!mp.size()) return {};
  ll pr = 0;
  for (auto i : mp) {
    smax(pr, i.first);
  }
  vector<ll> arr(pr + 1);
  if (pr == 0) {
    auto it = mp.begin();
    arr[0] += it->second;
    return arr;
  }
  for (__typeof(1) i = (pr + 1) - ((pr + 1) > (1)); i != (1) - ((pr + 1) > (1));
       i += 1 - 2 * ((pr + 1) > (1))) {
    arr[i] += mp[i];
    if (arr[i] > 1) {
      arr[i - 1] += k * (arr[i] - 1);
      arr[i] = 1;
    }
  }
  arr[0] += mp[0];
  return arr;
}
int main() {
  open();
  int t = 0;
  cin >> t;
  while (t--) {
    ll n, k;
    cin >> n >> k;
    vector<ll> arr(n);
    cin >> arr;
    map<ll, ll> powe;
    for (auto i : arr) {
      vector<ll> p = get(i, k);
      ;
      for (auto i : p) powe[i]++;
    };
    vector<ll> ap = get_down(powe, k);
    ;
    if (!ap.size()) {
      out("YES");
      continue;
    }
    if (ap[0] <= 1)
      out("YES");
    else
      out("NO");
  }
  close();
  return 0;
}
