#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
  return ((fabs(a - b) < (1e-9)) ? 0 : (a < b) ? -1 : +1);
}
double crossP(const complex<double> &v1, const complex<double> &v2) {
  return (conj(v1) * v2).imag();
}
double dotP(const complex<double> &v1, const complex<double> &v2) {
  return (conj(v1) * v2).real();
}
double lengthSqr(const complex<double> &p) { return dotP(p, p); }
double length(const complex<double> &p) { return hypot(p.real(), p.imag()); }
double fixAngle(double a) { return ((a > 1) ? 1 : (a < -1) ? -1 : a); }
bool same(const complex<double> &p1, const complex<double> &p2) {
  return ((dcmp(p1.real(), p2.real()) == 0 && dcmp(p1.imag(), p2.imag()) == 0)
              ? 1
              : 0);
}
double getAngle_A_abc(double a, double b, double c) {
  return acos(fixAngle((b * b + c * c - a * a) / (2 * b * c)));
}
const int N = 1000 + 9;
long long x[N];
bitset<N> vis;
bool f(const int n, const long long base) {
  for (auto i = 0; i < n; ++i) {
    int p = -1;
    while (x[i]) {
      p++;
      int r = x[i] % base;
      x[i] /= base;
      if (!r) continue;
      if (r > 1 || vis[p]) return 0;
      vis[p] = 1;
    }
  }
  return 1;
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int n, b;
    scanf("%d %d", &n, &b);
    for (auto i = 0; i < n; ++i) scanf("%lld", x + i);
    puts(f(n, b) ? "YES" : "NO");
    vis.reset();
  }
  return 0;
}
