#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    map<long long int, long long int> mp;
    long long int n, k;
    cin >> n >> k;
    long long int arr[n];
    for (int a = 0; a < n; a++) cin >> arr[a];
    for (int a = 0; a < n; a++) {
      if (arr[a] == 0) continue;
      long long int x, y, z;
      x = arr[a];
      y = 0;
      while (x != 0) {
        while (x % k == 0) {
          x = x / k;
          y++;
        }
        mp[y]++;
        x = x - 1;
      }
    }
    map<long long int, long long int>::iterator it;
    long long int ans = 1;
    for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second > 1) {
        ans = 0;
        break;
      }
    }
    if (ans == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
