#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long ans = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans;
}
bool ok;
long long A[31], B[31];
long long fac(long long x, long long k) {
  if (x == 0) return 0;
  if (x % k == 0)
    return fac(x / k, k) << 1;
  else if (x % k == 1)
    return fac(x / k, k) << 1 | 1;
  else {
    ok = false;
    return -1;
  }
}
int main() {
  long long t = read();
  while (t--) {
    long long n = read(), k = read();
    ok = true;
    memset(A, 0, sizeof(A));
    memset(B, 0, sizeof(B));
    for (int i = 0; i < n; i++) A[i] = read();
    for (int i = 0; i < n; i++) B[i] = fac(A[i], k);
    long long cur = 0;
    if (ok)
      for (int i = 0; i < n; i++) {
        if (cur & B[i]) {
          ok = false;
          break;
        }
        cur |= B[i];
      }
    puts(ok ? "YES" : "NO");
  }
  return 0;
}
