#include <bits/stdc++.h>
using namespace std;
int main() {
  long long T;
  cin >> T;
  while (T--) {
    long long N, K;
    cin >> N >> K;
    long long k = K;
    vector<long long> arr;
    long long inp;
    for (long long i = 0; i < N; i++) {
      cin >> inp;
      arr.push_back(inp);
    }
    long long num = 1;
    while (num <= pow(10, 16)) {
      num = num * k;
    }
    num = num / k;
    long long pos = 1;
    while (num >= 1) {
      long long count = 0;
      for (long long i = 0; i < N; i++) {
        if (arr[i] >= num) {
          count = count + 1;
          if (count > 1) {
            pos = 0;
            break;
          }
          arr[i] = arr[i] - num;
        }
      }
      num = num / k;
      if (count > 1) {
        pos = 0;
        break;
      }
    }
    if (pos == 1) {
      long long pos2 = 1;
      for (long long i = 0; i < N; i++) {
        if (arr[i] != 0) {
          pos2 = 0;
          break;
        }
      }
      if (pos2 == 0)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    } else
      cout << "NO" << endl;
  }
}
