#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    long long int e = 0;
    map<long long int, long long int> m, p;
    for (int i = 0; i < n; i++) {
      int d = 0;
      while (arr[i] != 0) {
        while (arr[i] % k == 0) {
          d++;
          arr[i] = arr[i] / k;
        }
        arr[i]--;
        if (m[d] != 0) {
          e = 1;
          break;
        } else
          m[d]++;
      }
      if (e == 1) break;
    }
    if (e == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
