#include <bits/stdc++.h>
using namespace std;
const int N = 31;
long long a[N];
long long b[N * 3], vis[N * 3];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    long long k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    int cnt = 0;
    long long tk = 1;
    while (tk <= 1e16) {
      b[++cnt] = tk;
      vis[cnt] = 0;
      tk *= k;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; ++i) {
      for (int j = cnt; j >= 1; --j) {
        if (vis[j]) continue;
        if ((a[i] - b[j]) >= 0 && (a[i] - b[j]) % k == 0) {
          a[i] -= b[j];
          vis[j] = 1;
        }
        if (a[i] == 0) break;
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = cnt; j >= 1; --j) {
        if (vis[j]) continue;
        if ((a[i] - b[j]) >= 0 && (a[i] - b[j]) % k == 0) {
          a[i] -= b[j];
          vis[j] = 1;
        }
        if (a[i] == 0) break;
      }
    }
    bool f = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i]) f = 0;
    if (f)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
