Suppose you are performing the following algorithm. There is an array v_1, v_2, ..., v_n filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can: 

  * either choose position pos (1 ≤ pos ≤ n) and increase v_{pos} by k^i; 
  * or not choose any position and skip this step. 



You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array v equal to the given array a (v_j = a_j for each j) after some step?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of test cases. Next 2T lines contain test cases — two lines per test case.

The first line of each test case contains two integers n and k (1 ≤ n ≤ 30, 2 ≤ k ≤ 100) — the size of arrays v and a and value k used in the algorithm.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{16}) — the array you'd like to achieve.

Output

For each test case print YES (case insensitive) if you can achieve the array a after some step or NO (case insensitive) otherwise.

Example

Input


5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810


Output


YES
YES
NO
NO
YES

Note

In the first test case, you can stop the algorithm before the 0-th step, or don't choose any position several times and stop the algorithm.

In the second test case, you can add k^0 to v_1 and stop the algorithm.

In the third test case, you can't make two 1 in the array v.

In the fifth test case, you can skip 9^0 and 9^1, then add 9^2 and 9^3 to v_3, skip 9^4 and finally, add 9^5 to v_2.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void _err(std::ostream& cerr, istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "  ";
  _err(cerr, ++it, args...);
}
const double pi = 2 * acos(.0);
const int inf = 0x3f3f3f3f;
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-10;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T> V) {
  os << "[";
  int cnt = 0;
  T curr;
  if (!V.empty()) {
    for (int i = 0; i < V.size() - 1; ++i) {
      if (V[i] == curr)
        cnt++;
      else
        cnt = 0;
      if (cnt == 4) os << "... ";
      if (cnt < 4) os << V[i] << " ";
      curr = V[i];
    }
    os << V.back();
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U> P) {
  os << "(";
  os << P.first << "," << P.second;
  os << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const set<T, U> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename H, typename P>
ostream& operator<<(ostream& os, const unordered_set<K, H, P> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename C>
ostream& operator<<(ostream& os, const multiset<K, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << *it << " ";
      it++;
    }
    os << *it;
  }
  os << "}";
  return os;
}
template <typename K, typename T, typename C>
ostream& operator<<(ostream& os, const map<K, T, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << "(";
      os << it->first << "," << it->second;
      os << ") ";
      it++;
    }
    os << "(";
    os << it->first << "," << it->second;
    os << ")";
  }
  os << "}";
  return os;
}
template <typename K, typename T, typename C>
ostream& operator<<(ostream& os, const unordered_map<K, T, C> V) {
  os << "{";
  if (!V.empty()) {
    auto it = V.begin();
    for (int i = 0; i < V.size() - 1; ++i) {
      os << "(";
      os << it->first << "," << it->second;
      os << ") ";
      it++;
    }
    os << "(";
    os << it->first << "," << it->second;
    os << ")";
  }
  os << "}";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T> V) {
  os << "[";
  if (!V.empty()) {
    for (int i = 0; i < V.size() - 1; ++i) {
      os << V[i] << "->";
    }
    if (!V.empty()) os << V.back();
  }
  os << "]";
  return os;
};
template <typename T, typename Cont, typename Comp>
ostream& operator<<(ostream& os, const priority_queue<T, Cont, Comp> V) {
  priority_queue<T, Cont, Comp> _V = V;
  os << "[";
  if (!_V.empty()) {
    while (_V.size() > 1) {
      os << _V.top() << "->";
      _V.pop();
    }
    os << _V.top();
  }
  os << "]";
  return os;
};
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
template <class T>
void Chmod(T& a, const T& m) {
  a = ((((a) % (m)) + (m)) % (m));
}
template <class T>
bool Chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool Chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
class CAddingPowers {
 public:
  void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    int TC;
    cin >> TC;
    while (TC--) {
      int N, K;
      cin >> N >> K;
      vector<ll> a(N);
      bitset<200> bit;
      auto f = [&](ll x) {
        int i = 0;
        while (x) {
          if (x % K == 1) {
            if (bit[i]) return 0;
            bit[i] = 1;
          } else if (x % K == 0) {
          } else
            return 0;
          x /= K;
          i++;
        }
        return 1;
      };
      for (__typeof(N) i = 0, _len = (N); i < (_len); i += 1) cin >> a[i];
      int ok = 1;
      for (__typeof(N) i = 0, _len = (N); i < (_len); i += 1) {
        if (!f(a[i])) {
          cout << ("NO") << endl;
          ok = 0;
          {};
          break;
        }
      }
      if (ok) cout << ("YES") << endl;
    }
  }
};
int main() {
  CAddingPowers solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  std::ostringstream err;
  in.tie(0);
  ios::sync_with_stdio(0);
  solver.solve(in, out, err);
  return 0;
}
