#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long int solu() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n];
  long long int num[64];
  memset(num, 0, sizeof(num));
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  for (long long int i = 0; i < n; i++) {
    long long int x = arr[i];
    while (x > 0) {
      long long int j = 1;
      long long int s = 0;
      for (s = 1; j <= x; s++) {
        j = j * k;
      }
      num[s - 1]++;
      j = j / k;
      x = x - j;
    }
  }
  for (long long int i = 0; i < 64; i++) {
    if (num[i] > 1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    solu();
  }
  return 0;
}
