#include <bits/stdc++.h>
using namespace std;
vector<long long> arr;
int k;
int main() {
  int t;
  cin >> t;
  for (int _ = 0; _ < t; _++) {
    int n;
    cin >> n >> k;
    arr.resize(n);
    for (long long &x : arr) cin >> x;
    long long mx = *max_element(arr.begin(), arr.end());
    long long s = 1;
    while (s < mx) s *= k;
    while (s) {
      for (long long &x : arr) {
        if (x >= s) {
          x -= s;
          break;
        }
      }
      s /= k;
    }
    bool b = true;
    for (long long x : arr)
      if (x) b = false;
    if (b)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
