#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long powe(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long mpowe(long long n, long long m) {
  if (m == 0) return 1;
  long long t = powe(n, m / 2);
  t %= 1000000007;
  if (m % 2 == 0) return (t * t) % 1000000007;
  return (((t * t) % 1000000007) * n) % 1000000007;
}
long long logtwo(long long n) {
  if (n == 1) return 0;
  return logtwo(n / 2) + 1;
}
void ceilsearch(long long ar[], long long low, long long high, long long x,
                long long &y) {
  if (low > high) return;
  long long mid = (low + high) / 2;
  if (ar[mid] >= x) {
    y = mid;
    ceilsearch(ar, low, mid - 1, x, y);
  } else {
    ceilsearch(ar, mid + 1, high, x, y);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long N, M;
    cin >> N >> M;
    long long ar[N];
    for (long long i = 0; i < N; i++) cin >> ar[i];
    ;
    long long po[63] = {};
    po[0] = 1;
    for (long long i = 1; i < 63; i++) {
      po[i] = po[i - 1] * M;
      if (po[i] < po[i - 1]) {
        for (long long j = i; j < 63; j++) po[j] = 1e18;
        break;
      }
    }
    for (long long i = 63; i >= 0; i--) {
      for (long long j = 0; j < N; j++) {
        if (ar[j] >= po[i]) {
          ar[j] -= po[i];
          break;
        }
      }
    }
    long long flag = 0;
    for (long long i = 0; i < N; i++) {
      if (ar[i] != 0) flag = 1;
    }
    if (flag)
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
}
