#include <bits/stdc++.h>
using namespace std;
int t, n, k, a[(int)100];
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof(a));
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      long long aux;
      cin >> aux;
      for (int pot = 0; pot < (int)100 && aux > 0; pot++, aux /= k) {
        a[pot] += aux % k;
      }
    }
    bool feasible = true;
    for (int i = 0; i < (int)100; i++)
      if (a[i] > 1) {
        feasible = false;
        break;
      }
    cout << (feasible ? "YES" : "NO") << endl;
  }
}
