#include <bits/stdc++.h>
using namespace std;
long long int findlog(long long int num, long long int k) {
  long long int c = 0;
  while (num > 1) {
    num /= k;
    c += 1;
  }
  return c;
}
int main() {
  long long int t, n, k, temp;
  vector<long long int> v;
  cin >> t;
  long long int x;
  set<long long int> s;
  while (t-- > 0) {
    long long int c = 0;
    cin >> n >> k;
    bool flag = true;
    bool f = true;
    long long int maxi = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
      if (maxi < x) maxi = x;
      if (x % k != 0 && x % k != 1) flag = false;
    }
    sort(v.begin(), v.end());
    long long int res;
    if (!flag) goto label;
    res = findlog(maxi, k);
    for (int i = 0; i <= res; i++) s.insert(i);
    for (int i = 0; i < n; i++) {
      if (v[i] != 0) {
        while (v[i] != 0) {
          temp = findlog(v[i], k);
          if (find(s.begin(), s.end(), temp) != s.end()) {
            v[i] -= pow(k, temp);
            s.erase(temp);
          } else {
            f = false;
            break;
          }
        }
      }
      if (!f) goto label;
    }
  label:;
    for (int i = 0; i < n; i++) {
      if (v[i] == 0) c++;
    }
    if (c == n)
      cout << "YES\n";
    else
      cout << "NO\n";
    v.clear();
    s.clear();
  }
  return 0;
}
