#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long int a[n];
    vector<int> v(64);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      long long int m = a[i];
      int j = 0;
      while (m) {
        int rem = m % k;
        v[j] += rem;
        j++;
        m = m / k;
      }
    }
    int flag = 1;
    for (int i = 0; i < 64; i++) {
      if (v[i] > 1) flag = -1;
    }
    if (flag == -1)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
