#include <bits/stdc++.h>
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
using namespace std;
long long ppow(int x, int y) {
  long long ans = 1, x1 = x;
  while (y > 0) {
    if (y % 2) ans *= x1;
    x1 *= x1;
    y /= 2;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long sum = 0, a[50];
    int n, k, i, j, flag = 0, count = 0;
    cin >> n >> k;
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    sum = a[n - 1];
    while (sum) {
      count++;
      sum /= k;
    }
    for (i = count - 1; i >= 0; i--) {
      for (j = n - 1; j >= 0; j--) {
        if (a[j] >= ppow(k, i)) {
          a[j] -= ppow(k, i);
          break;
        }
      }
    }
    for (i = 0; i < n; i++)
      if (a[i]) flag = 1;
    if (flag == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
