#include <bits/stdc++.h>
using namespace std;
long long int max_pwr(long long int n, long long int k) {
  long long int i = 0, j = 1;
  while (j <= n) {
    i++;
    j *= k;
  }
  return i - 1;
}
long long int binary_expo(long long int base, long long int exp) {
  if (exp == 0) return 1;
  if (exp == 1) return base;
  long long int t = binary_expo(base, exp / 2);
  t = (t * t);
  if (exp % 2 == 0)
    return t;
  else
    return ((base)*t);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n, k, i, j, testcase, x, flag;
  cin >> t;
  for (testcase = 0; testcase < t; testcase++) {
    flag = 1;
    cin >> n >> k;
    long long int a[n];
    map<long long int, long long int> m;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < n && flag; i++) {
      x = a[i];
      while (x && flag) {
        if (m[max_pwr(x, k)]) {
          flag = 0;
          break;
        }
        m[max_pwr(x, k)] = 1;
        x -= binary_expo(k, max_pwr(x, k));
      }
    }
    if (flag)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
