#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f, NegOO = -1 * OO, maxarr = 2e5 + 5, mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0), ios::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long arr[n];
    map<long long, bool> mp;
    for (int c = 0; c < n; c++) cin >> arr[c];
    bool tmam = 1;
    for (int c = 0; c < n; c++) {
      long long powy;
      while (arr[c]) {
        if (arr[c] < k && arr[c] != 1) {
          tmam = 0;
          break;
        }
        for (int i = 0; i < 60; i++) {
          if (powl(k, i) <= arr[c])
            powy = i;
          else
            break;
        }
        if (!mp[powy])
          arr[c] -= powl(k, powy), mp[powy] = 1;
        else {
          tmam = 0;
          break;
        }
      }
      if (!tmam) break;
    }
    if (tmam)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
  return 0;
}
