#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int flag = 0;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, flag = 0, j = 0;
    cin >> n >> k;
    long long int ar[n];
    long long int ar1[64] = {0};
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
      j = 0;
      while (ar[i] >= k) {
        ar1[j] += ar[i] % k;
        ar[i] = ar[i] / k;
        j++;
      }
      ar1[j] += ar[i];
    }
    for (int i = 0; i < 64; i++) {
      if (ar1[i] > 1) {
        flag = 1;
      }
    }
    if (flag == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
