#include <bits/stdc++.h>
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
long long mm = 10000, M = mm * mm * mm * mm;
long long a[N];
int vis[N];
void solve() {
  int n, k;
  scanf("%d%d", &n, &k);
  int ff = 0, up = 0;
  a[0] = 1;
  vis[0] = 0;
  for (int i = 1; i <= 60; ++i) {
    vis[i] = 0;
    a[i] = a[i - 1] * k;
    up = i;
    if (a[i] > M) break;
  }
  for (int i = 1; i <= n; ++i) {
    long long x;
    scanf("%lld", &x);
    for (int j = up; j >= 0; --j)
      if (x >= a[j]) {
        if (x / a[j] >= 2 || vis[j] == 1)
          ff = 1;
        else {
          vis[j] = 1;
          x -= a[j];
        }
      }
    if (x) ff = 1;
  }
  puts(ff ? "NO" : "YES");
}
int main() {
  int _ = 1;
  scanf("%d", &_);
  while (_--) solve();
  return 0;
}
