#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  long long arr[32];
  int visited[65];
  while (t--) {
    memset(visited, 0, sizeof(visited));
    bool flag = true;
    int n;
    long long k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    for (int i = 0; i < n; i++) {
      if (arr[i] == 0) continue;
      long long prev = 1;
      for (int j = 0; j <= 64; j++) {
        long long cur;
        if (j == 0)
          cur = 1;
        else
          cur = prev * k;
        long long curarr = arr[i];
        if (cur >= arr[i]) {
          long long curnum = cur;
          for (int a = j; a >= 0; a--) {
            if (a != j) curnum /= k;
            if (curarr >= curnum && visited[a] == 0) {
              visited[a]++;
              curarr -= curnum;
            }
          }
          if (curarr != 0) {
            flag = false;
          } else
            break;
        }
        if (!flag) break;
        prev = cur;
      }
      if (!flag) break;
    }
    if (flag)
      cout << "YES" << '\n';
    else
      cout << "NO"
           << "\n";
  }
  return 0;
}
