#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int MAXN = 3e1 + 10;
const int MAXK = 0;
long long arr[MAXN], k, n;
void solve() {
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) cin >> arr[i];
  set<int> s;
  bool flag = true;
  for (int i = 0; i < (n); ++i)
    if (flag) {
      int cnt = 0;
      while (arr[i]) {
        int rem = arr[i] % k;
        if (rem > 1) {
          flag = false;
          break;
        } else if (rem) {
          if (s.find(cnt) == s.end())
            s.insert(cnt);
          else {
            flag = false;
            break;
          }
        }
        arr[i] /= k;
        ++cnt;
      }
    }
  cout << (flag ? "YES" : "NO") << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
