#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int T, n, k;
LL a[35];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    LL cur = 1;
    while (cur <= 1E16) cur *= k;
    cur /= k;
    while (cur > 0) {
      for (int i = 1; i <= n; i++)
        if (a[i] >= cur) {
          a[i] -= cur;
          break;
        }
      cur /= k;
    }
    bool f = true;
    for (int i = 1; i <= n; i++)
      if (a[i]) f = false;
    puts(f ? "YES" : "NO");
  }
  return 0;
}
