#include <bits/stdc++.h>
using namespace std;
long long int const mod = 1e9 + 7;
long long int const inf = 1e18;
long long int const mxn = 2e5 + 5;
inline void file() {}
long long int fuc(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  }
  return ans;
}
int main() {
  file();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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];
    map<long long int, long long int> mp;
    bool ok = 1;
    for (long long int i = 0; i < n; i++) {
      long long int x = a[i];
      long long int c = 0;
      while (x) {
        if (x % k > 1)
          ok = 0;
        else if (x % k == 1) {
          if (mp[c]) ok = 0;
          mp[c]++;
        }
        x /= k;
        c++;
      }
      if (!ok) break;
    }
    if (ok)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
