#include <bits/stdc++.h>
using namespace std;
int n, k;
long long s, x;
int check() {
  s = 0;
  int fg = 1;
  for (int i = 1, p, dig; i <= n; ++i) {
    p = 0;
    scanf("%I64d", &x);
    while (x) {
      dig = x % k;
      if (dig >= 2) {
        fg = 0;
        break;
      }
      if (dig) {
        if (s & (1ll << p)) {
          fg = 0;
          break;
        }
        s |= (1ll << p);
      }
      ++p;
      x /= k;
    }
  }
  return fg;
}
int main() {
  int t;
  int cnt = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    puts(check() ? "YES" : "NO");
  }
  return 0;
}
