#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n, k;
    bool imposs = false;
    cin >> n >> k;
    set<long long> powers;
    for (int i = (1); i <= (n); i++) {
      long long x;
      cin >> x;
      long long cnt = 0;
      while (x) {
        if (imposs) break;
        long long a = x % k;
        if (a > 1) imposs = true;
        if (a && powers.count(cnt))
          imposs = true;
        else if (a)
          powers.insert(cnt);
        x /= k;
        cnt++;
        if (imposs) break;
      }
    }
    if (imposs)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
