#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool ans = false;
    long long int x = 16 * (1.0 * (log(10)) / log(k));
    for (long long int j = x; j >= 0; j--) {
      long long int count = 0;
      long long int z = (long long int)pow(k, j);
      for (long long int i = 0; i < n; i++) {
        if (a[i] >= z) {
          count++;
          a[i] -= z;
        }
      }
      if (count > 1) {
        ans = true;
        cout << "NO\n";
        break;
      }
    }
    if (!ans) {
      for (long long int i = 0; i < n; i++) {
        if (a[i] != 0) {
          cout << "NO\n";
          ans = true;
          break;
        }
      }
      if (!ans) {
        cout << "YES\n";
      }
    }
  }
}
