#include <bits/stdc++.h>
using namespace std;
long long t, n, k, z, x, s, a[31], v[31][101], c[31];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> t;
  for (int zxc = 1; zxc <= t; zxc++) {
    cin >> n >> k;
    for (int i = 1; i <= 30; i++)
      for (int j = 1; j <= 100; j++) v[i][j] = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      long long z = a[i];
      long long x = 0;
      while (z != 0) {
        x++;
        v[i][x] = z % k;
        z /= k;
      }
    }
    int ff = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 100; j++) {
        if (v[i][j] > 1) {
          ff = 1;
          break;
        }
      }
      if (ff == 1) break;
    }
    if (ff == 1)
      cout << "NO"
           << "\n";
    else {
      for (int j = 1; j <= 100; j++) {
        long long x = 0;
        for (int i = 1; i <= n; i++)
          if (v[i][j] == 1) x++;
        if (x > 1) {
          ff = 1;
          break;
        }
      }
      if (ff == 1)
        cout << "NO"
             << "\n";
      else
        cout << "YES"
             << "\n";
    }
  }
}
