#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, k;
bool flag;
vector<int> cnt;
void process(long long a) {
  int count = 0;
  while (a > 0) {
    while (a % k == 0) count++, a /= k;
    cnt[count] += a % k;
    a -= a % k;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cnt.assign(100, 0);
    flag = true;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) process(a[i]);
    for (int i = 0; i < 100; ++i)
      if (cnt[i] > 1) flag = false;
    cout << ((flag) ? "YES\n" : "NO\n");
  }
  return 0;
}
