#include <bits/stdc++.h>
using namespace std;
const int N = 105;
long long a[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long m;
    scanf("%d%lld", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    long long mx = 0;
    for (int i = 1; i <= n; i++) mx = max(a[i], mx);
    long long cnt = 1;
    for (; mx / cnt >= m; cnt *= m)
      ;
    for (; cnt; cnt /= m) {
      int flag = 0;
      for (int i = 1; i <= n; i++)
        if (!flag && a[i] >= cnt) a[i] -= cnt, flag = 1;
    }
    int Can = 1;
    for (int i = 1; i <= n; i++)
      if (a[i] != 0) Can = 0;
    if (Can)
      puts("YES");
    else
      puts("NO");
  }
}
