#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x);
    }
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long mcd(long long a, long long b) {
  if (b > a) swap(a, b);
  if (b == 0)
    return a;
  else
    return mcd(b, a % b);
}
long long t, n;
bool esprimo(long long n) {
  long long s = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      s++;
    }
  }
  if (s >= 2) {
    return false;
  }
  return true;
}
int main() {
  cin >> t;
  while (t--) {
    long long k;
    cin >> n >> k;
    long long a[n];
    multiset<long long> b;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long x = 0, j = 0;
    while (x < 10000000000000000) {
      x = power(k, j, 1000000000000000000);
      b.insert(x);
      j++;
    }
    int q = 1;
    multiset<long long> c, d;
    for (int i = 0; i < n; i++) {
      x = a[i];
      long long p = 0, r = 0;
      if (x % k != 0) {
        x--;
        c.insert(1);
      }
      while (x) {
        if (x % k == 0) {
          x /= k;
          p++;
        } else if (p) {
          x--;
          if (x % k == 0) {
            c.insert(power(k, p, 100000000000000000));
          } else {
            r++;
            x = 0;
          }
          p == 0;
        } else {
          r++;
          x = 0;
        }
      }
      if (r) {
        q = 0;
        break;
      }
    }
    if (q) {
      multiset<long long>::iterator it;
      for (it = c.begin(); it != c.end(); it++) {
        if (b.find(*it) != b.end()) {
          b.erase(*it);
        } else {
          q = 0;
          break;
        }
      }
    }
    if (q) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
    b.clear();
    c.clear();
  }
}
