#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  std::cin >> t;
  while (t--) {
    int n, k;
    std::cin >> n >> k;
    std::vector<long long int> a;
    long long int temp;
    for (int i = 0; i < n; i++) {
      std::cin >> temp;
      a.push_back(temp);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == 0) {
        a.erase(a.begin() + i);
        i--;
      } else {
        break;
      }
    }
    if (a.size() == 0) {
      std::cout << "YES" << endl;
      continue;
    }
    int flag1 = 0;
    for (int i = 1; i < a.size(); i++) {
      if (a[i] == a[i - 1]) {
        flag1 = 1;
        break;
      }
    }
    if (flag1 == 1) {
      std::cout << "NO" << endl;
      continue;
    }
    long long int b = pow(k, 0);
    temp = a[n - 1];
    int count = 0;
    while (temp / b > 1) {
      count++;
      b = pow(k, count);
    }
    int j;
    int flag = 0;
    for (int i = count; i >= 0; i--) {
      j = a.size() - 1;
      int ans = 0;
      int flag2 = 0;
      long long int c = pow(k, i);
      long long int b = a[j] / c;
      while (b == 1) {
        flag2 = 1;
        a[j] = a[j] - c;
        if (j > 0) j--;
        ans++;
        b = a[j] / c;
      }
      if (flag2 == 0) {
        if (a[j] / pow(k, i) > 1) {
          flag = 1;
          break;
        }
      }
      if (ans > 1) {
        flag = 1;
        break;
      }
      sort(a.begin(), a.end());
    }
    if (flag == 0) {
      std::cout << "YES" << endl;
    } else {
      std::cout << "NO" << endl;
    }
  }
}
