#include <bits/stdc++.h>
using namespace std;
long long a[110];
long long b[50][70];
int main() {
  long long n, m, t;
  scanf("%lld", &t);
  while (t--) {
    memset(b, 0, sizeof(b));
    scanf("%lld%lld", &n, &m);
    int flag = 0;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      long long x = a[i];
      int k = 0;
      while (x) {
        b[i][k++] = x % m;
        if (x % m != 0 && x % m != 1) {
          flag = 1;
        }
        x /= m;
      }
    }
    for (int i = 0; i < 64; i++) {
      int sum = 0;
      for (int j = 0; j < n; j++) {
        sum += b[j][i];
      }
      if (sum != 0 && sum != 1) {
        flag = 1;
      }
    }
    if (flag == 1) {
      printf("NO\n");
    } else {
      printf("YES\n");
    }
  }
}
