#include <bits/stdc++.h>
using namespace std;
bool s[1111111];
long long int f[1111111];
long long int fibo[1111111];
long long int fibonacci(long long int x) {
  fibo[1] = fibo[2] = 1;
  if (x < 1111111 && !fibo[x]) return fibo[x];
  if (x < 1111111)
    return fibo[x] =
               (fibonacci(x - 1) + fibonacci(x - 2)) % 1199999999999999999;
  return fibo[x] = (fibonacci(x - 1) + fibonacci(x - 2)) % 1199999999999999999;
}
long long int mul(long long int a, long long int b, long long int m) {
  long long int result = 0;
  a %= m;
  while (b) {
    if (b & 1) result = (result + a) % m;
    a = (2 * a) % m;
    b >>= 1;
  }
  return result;
}
long long int power(long long int b, long long int e, long long int m) {
  long long int result = 1;
  b %= m;
  while (e) {
    if (e & 1) result = mul(result, b, m);
    e >>= 1;
    b = mul(b, b, m);
  }
  return result;
}
bool func1(pair<long long int, long long int> x,
           pair<long long int, long long int> y) {
  if (x.first == y.first) return x.second < y.second;
  return x.first < y.first;
}
bool func2(pair<long long int, long long int> x,
           pair<long long int, long long int> y) {
  if (x.second == y.second) return x.first < y.first;
  return x.second < y.second;
}
bool dfunc(long long int a, long long int b) { return a > b; }
long long int fact(long long int x) {
  if (x <= 1) return f[x] = 1;
  if (f[x]) return f[x];
  if (x < 1111111) return f[x] = x * fact(x - 1);
  return x * fact(x - 1);
}
void seive() {
  for (long long int i = 2; i < 1111111; i++)
    if (!s[i])
      for (long long int j = i * i; j < 1111111; j += i) s[j] = true;
}
vector<vector<long long int>> adj(1111111);
bool visited[1111111];
queue<long long int> q;
vector<long long int> side(1111111, -1);
long long int cover1, cover2;
bool isbi = true;
void dfs(long long int n) {
  visited[n] = true;
  for (long long int i : adj[n])
    if (!visited[i]) dfs(i);
}
void bibfs(long long int n) {
  long long int s;
  for (s = 1; s <= n; s++)
    if (side[s] == -1) {
      q.push(s);
      side[s] = 0;
      cover1++;
      while (!q.empty()) {
        long long int temp = q.front();
        q.pop();
        for (long long int j : adj[temp])
          if (side[j] == -1) {
            q.push(j);
            side[j] = side[temp] ^ 1;
            if (!side[j])
              cover1++;
            else
              cover2++;
          } else
            isbi &= (side[j] != side[temp]);
      }
    }
}
void bfs(long long int n) {
  q.push(n);
  while (!q.empty()) {
    long long int temp = q.front();
    q.pop();
    visited[temp] = true;
    for (long long int j : adj[temp])
      if (!visited[j]) q.push(j);
  }
}
vector<vector<pair<long long int, long long int>>> adj1(1111111);
void dk(long long int n, long long int s, vector<long long int> &d,
        vector<long long int> &p) {
  long long int i, j, v;
  d[s] = 0;
  vector<bool> u(n + 5, false);
  for (i = 1; i <= n; i++) {
    v = -1;
    for (j = 1; j <= n; j++)
      if (!u[j] && (v == -1 || d[j] < d[v])) v = j;
    u[v] = true;
    if (d[v] == ((long long int)INT_MAX) * 1000) break;
    for (pair<long long int, long long int> temp : adj1[v])
      if (d[v] + temp.second < d[temp.first]) {
        d[temp.first] = d[v] + temp.second;
        p[temp.first] = v;
      }
  }
}
long long int sakamoto(long long int d, long long int m, long long int y) {
  long long int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  if (m < 3) y -= 1;
  return ((y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7);
}
long long int seg1[1111111];
vector<long long int> a;
void build(long long int left, long long int right, long long int index) {
  if (left == right) {
    seg1[index] = a[left];
    return;
  }
  long long int mid = (left + right) / 2;
  build(left, mid, 2 * index);
  build(mid + 1, right, 2 * index + 1);
  seg1[index] = seg1[2 * index] + seg1[2 * index + 1];
}
long long int query(long long int left, long long int right,
                    long long int lindex, long long int rindex,
                    long long int index) {
  if (right < lindex || rindex < left) return 0;
  if (left <= lindex && right >= rindex) return seg1[index];
  return query(left, right, lindex, (lindex + rindex) / 2, 2 * index) +
         query(left, right, (lindex + rindex) / 2 + 1, rindex, 2 * index + 1);
}
bool check(long long int n, long long int a, long long int d, long long int s) {
  long long int x = power(a, d, n);
  if (x == 1 || x == n - 1) return false;
  for (long long int i = 1; i < s; i++) {
    x = mul(x, x, n);
    if (x == n - 1) return false;
  }
  return true;
}
bool miller(long long int n, long long int iter) {
  srand(time(0));
  if (n < 4) return n == 2 || n == 3;
  long long int d = n - 1;
  long long int s = 0;
  while (!(d & 1)) {
    d >>= 1;
    s++;
  }
  for (long long int i = 1; i <= iter; i++) {
    long long int a = 2 + rand() % (n - 3);
    if (check(n, a, d, s)) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n, k, i, a[1010], s;
    bool flag = false;
    cin >> n >> k;
    for (i = 0; i < n; i++) cin >> a[i];
    s = 16 / log10(k) + 1;
    while (s >= 0) {
      long long int count = 0, index = -1;
      for (i = 0; i < n; i++)
        if (a[i] >= power(k, s, 1199999999999999999)) {
          index = i;
          count++;
        }
      if (count >= 2) {
        flag = true;
        cout << "NO" << endl;
        break;
      }
      if (index != -1) a[index] -= power(k, s, 1199999999999999999);
      s--;
    }
    if (!flag)
      for (i = 0; i < n; i++)
        if (a[i]) {
          flag = true;
          cout << "NO" << endl;
          break;
        }
    if (!flag) cout << "YES" << endl;
  }
  return 0;
}
