#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
long long a[35];
long long b[35];
int n, k;
bool divid(int p) {
  long long t = a[p];
  long long f = 1;
  b[p] = 0;
  while (t) {
    int mod = t % k;
    if (mod > 1) return false;
    if (mod) b[p] |= f;
    f <<= 1;
    t /= k;
  }
  return 1;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%I64d", a + i);
    bool ok = true;
    for (int i = 1; i <= n; ++i) {
      if (!divid(i)) {
        ok = false;
        break;
      }
    }
    long long t = 0;
    for (int i = 1; i <= n; ++i) {
      if (t & b[i]) {
        ok = false;
        break;
      }
      t |= b[i];
    }
    if (ok)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
