#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int k, a[10005] = {0}, b = 0, temp, j, n;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      for (j = 0; temp != 0; j++) {
        a[j] = a[j] + temp % k;
        if (a[j] > 1) {
          b = 1;
        }
        temp = temp / k;
      }
    }
    if (b == 1) {
      cout << "NO"
           << "\n";
    } else {
      cout << "YES"
           << "\n";
    }
  }
  return 0;
}
