#include <bits/stdc++.h>
using namespace std;
void Fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
}
inline int D() {
  int t;
  scanf("%d", &t);
  return t;
}
inline long long llD() {
  long long t;
  scanf("%lld", &t);
  return t;
}
long long MOD = 1e9 + 7;
const int N = 1e2 + 5;
long long power[N];
int OO = 1e6;
long long n, m, k, cnt, SU, idx, len, MN;
long long l, r, mid;
long long a, b, c, d;
vector<int> vec;
int BS(long long n) {
  l = 0, r = len - 1, mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (power[mid] <= n)
      l = mid;
    else
      r = mid - 1;
  }
  return l;
}
void Gen() {
  len = 0, MN = 1e16 + 5;
  power[len] = 1;
  while (power[len] <= MN) {
    power[len + 1] = power[len] * m;
    ++len;
  }
}
int main() {
  int T = D();
  while (T--) {
    scanf("%lld%lld", &n, &m);
    Gen();
    map<int, int> mp;
    bool flage = true;
    while (n--) {
      scanf("%lld", &cnt);
      while (cnt) {
        idx = BS(cnt);
        cnt -= power[idx];
        ++mp[idx];
        flage &= (mp[idx] == 1);
      }
    }
    puts(flage ? "YES" : "NO");
  }
}
