#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        int ans = 0, f = 0;
        unordered_map<int, int> mp;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] != 0)
            {

                ans = 1;
                int g = 0;
                while (ans * k <= a[i])
                {
                    ans = ans * k;
                    g++;
                }
               // cerr << ans << " ";
                if (ans > a[i])
                {
                    ans /= k;
                 }
                if (mp[g])
                {
                    f = 1;
                    break;
                }
                mp[g] = 1;
                for (int j = g - 1; j >= 0; j--)
                {

                    int u;
                    u = pow(k, j);
                    if (ans + u <= a[i])
                    {
                        if (mp[j])
                        {
                            f = 1;
                            break;
                        }
                        mp[j] = 1;
                        ans = ans + u;
                    }
                }
                if(ans!=a[i]){
                    f = 1;
                }
                if (f)
                {
                    break;
                }
            }
        }
        if (!f)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n,k;
        cin >> n>>k;
        int a[n];
        int ans = 0,f=0;
        map<int, int> mp;

        for (int i = 0; i < n;i++){
            cin >> a[i];
            if(a[i]==0){
                continue;
            }
            ans = 1;
            int g = 0;
            while(ans*k<=a[i]){
                ans = ans * k;
                g++;
            }

            if(mp[g]){
                f = 1;
                break;
            }
            mp[g] = 1;
            for (int j = g - 1; j >= 0;j--){
                //cout << j << " ";
                int u;
                u = pow(k, j);
                if(ans+u<=a[i]){
                    if(mp[j]){
                        f = 1;
                        break;
                    }
                    mp[j] = 1;
                    ans=ans+u;
                }
            }
            if(f){
                break;
            }
        }
        if(!f){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        int ans = 0, f = 0;
        map<int, int> mp;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] != 0)
            {

                ans = 1;
                int g = 0;
                while (ans < a[i])
                {
                    ans = ans * k;
                    g++;
                }
                if(ans>a[i]){
                    ans /= k;
                    g--;
                }
                if (mp[g])
                {
                    f = 1;
                    break;
                }
                mp[g] = 1;
                for (int j = g - 1; j >= 0; j--)
                {

                    int u;
                    u = pow(k, j);
                    if (ans + u <= a[i])
                    {
                        if (mp[j])
                        {
                            f = 1;
                            break;
                        }
                        mp[j] = 1;
                        ans = ans + u;
                    }
                }
                if(ans!=a[i]){
                    f = 1;
                }
                if (f)
                {
                    break;
                }
            }
        }
        if (!f)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n,k;
        cin >> n>>k;
        int a[n];
        int ans = 0,f=0;
        map<int, int> mp;

        for (int i = 0; i < n;i++){
            cin >> a[i];
            if(a[i]==0){
                continue;
            }
            ans = 1;
            int g = 0;
            while(ans*k<=a[i]){
                ans = ans * k;
                g++;
            }
            //cout << g << " ";
            if(mp[g]){
                f = 1;
                break;
            }
            mp[g] = 1;
            for (int j = g - 1; j >= 0;j--){
                //cout << j << " ";
                int u;
                u = pow(k, j);
                if(ans+u<=a[i]){
                    if(mp[j]){
                        f = 1;
                        break;
                    }
                    mp[j] = 1;
                }
            }
        }
        if(!f){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n,k;
        cin >> n>>k;
        int a[n];
        int ans = 0,f=0;
        map<int, int> mp;
for (int i = 0; i < n;i++)
cin>>a[i];
        for (int i = 0; i < n;i++){

            if(a[i]==0){
                continue;
            }
            ans = 1;
            int g = 0;
            while(ans*k<=a[i]){
                ans = ans * k;
                g++;
            }

            if(mp[g]){
                f = 1;
                break;
            }
            mp[g] = 1;
            for (int j = g - 1; j >= 0;j--){
                //cout << j << " ";
                int u;
                u = pow(k, j);
                if(ans+u<=a[i]){
                    if(mp[j]){
                        f = 1;
                        break;
                    }
                     mp[j] = 1;
                    ans=ans+u;
                }
            }
            if(ans!=a[i])
            f=1;
            if(f){
                break;
            }
        }
        if(!f){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n,k;
        cin >> n>>k;
        int a[n];
        int ans = 0,f=0;
        map<int, int> mp;
for (int i = 0; i < n;i++)
cin>>a[i];
        for (int i = 0; i < n;i++){

            if(a[i]==0){
                continue;
            }
            ans = 1;
            int g = 0;
            while(ans*k<=a[i]){
                ans = ans * k;
                g++;
            }

            if(mp[g]){
                f = 1;
                break;
            }
            mp[g] = 1;
            for (int j = g - 1; j >= 0;j--){
                //cout << j << " ";
                int u;
                u = pow(k, j);
                if(ans+u<=a[i]){
                    if(mp[j]){
                        f = 1;
                        break;
                    }
                    mp[j] = 1;
                    ans=ans+u;
                }
            }
            if(ans!=a[i])
            f=1;
            if(f){
                break;
            }
        }
        if(!f){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    cin >> tc;
    while (tc--)
    {
        int n, k;
        cin >> n >> k;
        int a[n];
        int ans = 0, f = 0;
        int co[1000] = {0};

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] != 0)
            {

                ans = 1;
                int g = 0;
                while (ans < a[i])
                {
                    ans = ans * k;
                    g++;
                }
                if(ans>a[i]){
                    ans /= k;
                    g--;
                }
                if (mp[g])
                {
                    f = 1;
                    break;
                }
                mp[g] = 1;
                for (int j = g - 1; j >= 0; j--)
                {

                    int u;
                    u = pow(k, j);
                    if (ans + u <= a[i])
                    {
                        if (mp[j])
                        {
                            f = 1;
                            break;
                        }
                        mp[j] = 1;
                        ans = ans + u;
                    }
                }
                if(ans!=a[i]){
                    f = 1;
                }
                if (f)
                {
                    break;
                }
            }
        }
        if (!f)
        {
            cout << "YES" << "\n";
        }
        else
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int st[2000005]={0};
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        memset(st,0,sizeof(st));
        int fl=0;
        int cnt=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
            if(a[i]==1)cnt++;
        }
        for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){
                if(a[i]!=1||cnt!=1){
                    fl=1;
                    break;
                }
            }
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]+=tmp%k;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int fl=0;
        int st[100]={0};
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
        }
        if(a[0]==1&&n==1){cout<<"YES"<<endl;
            continue;}
        else for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){fl=1;
                break;}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]++;if(st[cnt]>2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
        while(t--){
            memset(a,0,sizeof(a));
            ll n,k;
            int fl=1;
            ll cnt=0,x;
            scanf("%lld %lld",&n,&k);
            for(int i=1;i<=n;i++){
                scanf("%lld",&x);
                cnt=0;
                while(x){
                    a[cnt]+=x%k;
                    x/=k;
                    if(a[cnt]>=2) fl=0;
                    cnt++;
                }
            }
            if(fl) printf("YES\n");
            else printf("NO\n");

        }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int fl=0;
        int st[20]={0};
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
        }
        if(a[0]==1&&n==1){cout<<"YES"<<endl;
            continue;}
        else for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){fl=1;
                break;}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]++;if(st[cnt]>2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int fl=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
        }
        sort(a,a+n);
        for (int j = 0; j <n ; ++j) {
            ll tmp=pow(k,j);
            if(a[j]%tmp!=0){fl=1;
                break;}
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 200007
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
        while(t--){
            ll n,k,fl=1,cnt=0,x;
            scanf("%lld %lld",&n,&k);
            for(int i=1;i<=n;i++){
                scanf("%lld",&x);
                cnt=0;
                while(x){
                    a[cnt]+=x%k;
                    x/=k;
                    if(a[cnt]>=2) fl=0;
                    cnt++;
                }
            }
            if(fl) printf("YES\n");
            else printf("NO\n");
            memset(a,0,sizeof(a));
        }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;

        int fl=0;
        int st[100]={0};
        int cnt=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
            if(a[i]==1)cnt++;
        }
        for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){
                if(a[i]==1&&cnt==1)continue;
                else{fl=1;
                break;}}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]++;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int st[2000005]={0};
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        memset(st,0,sizeof(st));
        int fl=0;
        int cnt=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
            if(a[i]==1)cnt++;
        }
        for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){
                if(a[i]==1&&cnt==1)continue;
                else{fl=1;
                break;}}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]+=tmp%k;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int fl=0;
        int st[100]={0};
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
        }
        if(a[0]==1&&n==1){cout<<"YES"<<endl;
            continue;}
        else for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){fl=1;
                break;}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]++;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int st[2000005]={0};
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        memset(st,0,sizeof(st));
        int fl=0;
        int cnt=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
            if(a[i]%k!=0&&(a[i]-1)%k==0)cnt++;
        }
        for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){
                if((a[i]-1)%k!=0){fl=1;
                    break;}
                if(cnt!=1){
                    fl=1;
                    break;
                }
            }
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]+=tmp%k;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 40
#define mod 998244353
ll a[maxn];
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;

        int fl=0;
        int st[100]={0};
        int cnt=0;
        for (int i = 0; i <n ; ++i) {
            scanf("%lld",&a[i]);
            if(a[i]==1)cnt++;
        }
        for (int i = 0; i <n ; ++i) {
            if(a[i]%k!=0){
                if(a[i]==1&&cnt==1)continue;
                else{fl=1;
                break;}}
            ll tmp=a[i];
            int cnt=0;
            while(tmp){
                if(tmp%k!=0){st[cnt]+=tmp%k;if(st[cnt]>=2)fl=1;}
                tmp/=k;
                cnt++;
            }
        }
        if(fl)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
typedef long double ll;

using namespace std;
ll ar[30];

int main () {
	ll t, n, k, perfectPower;
	long long maxSize;
	int flag = 0;
	scanf("%Lf", &t);
	while(t--) {
		flag = 0;
		scanf("%Lf%Lf", &n, &k);
		maxSize = (long long)((ll)log2(pow(10, 16)) / (ll)log2(k));
		ll *p = new ll[maxSize+1];
		for(long long i = 0; i < maxSize; i++)
			p[i] = 0;
		for(long long i = 0; i < n; i++)
			scanf("%Lf", &ar[i]);

		for(long long i = 0; i < n; i++){
			if(ar[i] != 0) {
				ll temp = ar[i];
				do {
					perfectPower = (ll)((ll)log2(temp)/(ll)log2(k));
					temp = temp - pow(k, floor(perfectPower));
					if(p[(long long)(perfectPower)] == 1) {
						flag = 1;
						printf("NO\n");
						break;
					}
					else if(p[(long long)(perfectPower)] == 0){
						p[(long long)(perfectPower)]++;
					}
				}
				while(temp > 0);
				if(flag == 1)
					break;
			}
		}
		if(flag == 0)
			printf("YES\n");
		delete[] p;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

ll power(ll x, ll y) {
	if(y == 0) return 1;
	if(y & 1) return x * power(x, y/2)  * power(x, y/2);
	return power(x, y/2)  * power(x, y/2);
}

int main() {
	ll t, n, k;
	cin >> t;

	while(t--) {
		cin >> n >> k;

		vector<ll> a, b(n);
		map<ll,ll> mp;

		for(ll i=0; i<n; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		a.push_back(1);
		for(ll i=1; power(k, i) < b[0]+1; i++) a.push_back(a[i-1] * k);
		// cout << endl;

		// for(auto k: b) cout << k << " ";
		// cout<< endl;
		ll flag = 0;

		for(ll i=0; i<n; i++) {
			if(!b[i]) {
				cout << "YES" << endl;
				flag = 1;
				break;
			}

			while(b[i] > 0) {
				ll idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
				if(idx == n-1) idx-=1;
				// cout << b[i] << " idx: " << idx << endl;
				if(mp[idx+1]) {
					cout << "NO" << endl;
					flag = 1;
					break;
				}
				b[i] -= a[idx];
				mp[idx+1] = 1;
			}

			if(flag) break;
		}
		if(!flag) cout << "YES" << endl;
		mp.clear();
		a.clear();
		b.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

ll power(ll x, ll y) {
	if(y == 0) return 1;
	if(y & 1) return x * power(x, y/2)  * power(x, y/2);
	return power(x, y/2)  * power(x, y/2);
}

int main() {
	ll t, n, k;
	cin >> t;

	while(t--) {
		cin >> n >> k;

		vector<ll> a, b(n);
		map<ll,ll> mp;

		for(ll i=0; i<n; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		a.push_back(1);
		for(ll i=1; power(k, i) < b[0]+1; i++) a.push_back(a[i-1] * k);
		// cout << endl;

		// for(auto k: b) cout << k << " ";
		// cout<< endl;
		ll flag = 0;

		for(ll i=0; i<n; i++) {
			if(!b[i]) {
				cout << "YES" << endl;
				flag = 1;
				break;
			}

			while(b[i] > 0) {
				ll idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
				if(b[i] != a[idx]) idx--;
				// cout << b[i] << " idx: " << idx << endl;
				if(mp[idx+1]) {
					cout << "NO" << endl;
					flag = 1;
					break;
				}
				b[i] -= a[idx];
				mp[idx+1] = 1;
			}

			if(flag) break;
		}
		if(!flag) cout << "YES" << endl;
		mp.clear();
		a.clear();
		b.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

/* Iterative Function to calculate (x^y) in O(log y) */
ll power(ll x, ll unsigned y)
{
	ll res = 1;	 // Initialize result

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = res*x;

		// y must be even now
		y = y>>1; // y = y/2
		x = x*x; // Change x to x^2
	}
	return res;
}

int main() {
	ll t, n, k, arr[35], temp;
	long double kpower;
	int parr[60], flag = 0;
	scanf("%lld", &t);
	while(t--){
		flag = 0;
		for(int i = 0; i < 60; i++)
			parr[i] = 0;
		scanf("%lld%lld", &n, &k);
		for(int i = 0; i < n; i++)
			scanf("%lld", &arr[i]);

		for(int i = 0; i < n; i++) {
			if(arr[i] != 0) {
				temp = arr[i];
				do{
					kpower = floor((float)log(temp)/(log(k)));

					temp = temp - power(k, (ll)(kpower));
					// printf("%Lf %lld , ", kpower, power(k, (kpower)));
					if(parr[(int(kpower))] == 0) {
						parr[(int(kpower))]++;
					}
					else{
						flag = 1;
						printf("NO\n");
						break;
					}
				}
				while(temp > 0);
			}
			if(flag == 1)
				break;
		}
		if(flag == 0)
			printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

ll power(ll x, ll y) {
	if(y == 0) return 1;
	if(y & 1) return x * power(x, y/2)  * power(x, y/2);
	return power(x, y/2)  * power(x, y/2);
}

int main() {
	ll t, n, k;
	cin >> t;

	while(t--) {
		cin >> n >> k;

		vector<ll> a, b(n);
		map<ll,ll> mp;

		for(ll i=0; i<n; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		a.push_back(1);
		for(ll i=1; a[i-1] < b[0]; i++) a.push_back(a[i-1] * k);
		// cout << endl;

		// for(auto k: b) cout << k << " ";
		// cout<< endl;
		ll flag = 0;

		for(ll i=0; i<n; i++) {
			if(!b[i]) {
				cout << "YES" << endl;
				flag = 1;
				break;
			}

			while(b[i] > 0) {
				ll idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
				if(b[i] != a[idx]) idx--;
				// cout << b[i] << " idx: " << idx << endl;
				if(mp[idx+1]) {
					cout << "NO" << endl;
					flag = 1;
					break;
				}
				b[i] -= a[idx];
				mp[idx+1] = 1;
			}

			if(flag) break;
		}
		if(!flag) cout << "YES" << endl;
		mp.clear();
		a.clear();
		b.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long double ll;

using namespace std;
ll ar[30];

int main () {
	ll t, n, k, perfectPower;
	long long maxSize;
	int flag = 0;
	scanf("%Lf", &t);
	while(t--) {
		flag = 0;
		scanf("%Lf%Lf", &n, &k);
		maxSize = (long long)((ll)log2(pow(10, 16)) / (ll)log2(k));
		ll *p = new ll[maxSize+1];
		for(long long i = 0; i < maxSize; i++)
			p[i] = 0;
		for(long long i = 0; i < n; i++)
			scanf("%Lf", &ar[i]);

		for(long long i = 0; i < n; i++){
			if(ar[i] != 0) {
				ll temp = ar[i];
				do {
					perfectPower = (ll)((ll)log2(temp)/(ll)log2(k));
					temp = temp - pow(k, perfectPower);
					// printf("%Lf %Lf ", perfectPower, temp);
					if(p[(long long)(perfectPower)] == 1) {
						flag = 1;
						printf("NO\n");
						break;
					}
					else if(p[(long long)(perfectPower)] == 0){
						p[(long long)(perfectPower)]++;
					}
				}
				while(temp > 0);
				if(flag == 1)
					break;
			}
		}
		if(flag == 0)
			printf("YES\n");
		delete[] p;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

ll power(ll x, ll y) {
	if(y == 0) return 1;
	if(y & 1) return x * power(x, y/2)  * power(x, y/2);
	return power(x, y/2)  * power(x, y/2);
}

int main() {
	ll t, n, k;
	cin >> t;

	while(t--) {
		cin >> n >> k;

		vector<ll> a, b(n);
		map<ll,ll> mp;

		for(ll i=0; i<n; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		a.push_back(1);
		for(ll i=1; power(k, i) < b[0]+1; i++) a.push_back(a[i-1] * k);
		// cout << endl;

		// for(auto k: b) cout << k << " ";
		// cout<< endl;
		ll flag = 0;

		for(ll i=0; i<n; i++) {
			if(!b[i]) {
				cout << "YES" << endl;
				flag = 1;
				break;
			}

			while(b[i] > 0) {
				ll idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
				if(b[i] != a[idx]) idx--;
				cout << b[i] << " idx: " << idx << endl;
				if(mp[idx+1]) {
					cout << "NO" << endl;
					flag = 1;
					break;
				}
				b[i] -= a[idx];
				mp[idx+1] = 1;
			}

			if(flag) break;
		}
		if(!flag) cout << "YES" << endl;
		mp.clear();
		a.clear();
		b.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

/* Iterative Function to calculate (x^y) in O(log y) */
ll power(ll x, ll y)
{
	ll res = 1;	 // Initialize result

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = res*x;

		// y must be even now
		y = y>>1; // y = y/2
		x = x*x; // Change x to x^2
	}
	return res;
}

int main() {
	ll t, n, k, arr[35], temp;
	long double kpower;
	int parr[60], flag = 0;
	scanf("%lld", &t);
	while(t--){
		flag = 0;
		for(int i = 0; i < 60; i++)
			parr[i] = 0;
		scanf("%lld%lld", &n, &k);
		for(int i = 0; i < n; i++)
			scanf("%lld", &arr[i]);

		for(int i = 0; i < n; i++) {
			if(arr[i] != 0) {
				temp = arr[i];
				do{
					kpower = floor((float)log(temp)/(log(k)));

					temp = temp - power(k, (ll)(kpower));
					// printf("%Lf %lld , ", kpower, power(k, (kpower)));
					if(parr[(int(kpower))] == 0) {
						parr[(int(kpower))]++;
					}
					else{
						flag = 1;
						printf("NO\n");
						break;
					}
				}
				while(temp > 0);
			}
			if(flag == 1)
				break;
		}
		if(flag == 0)
			printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long double ll;

using namespace std;
ll ar[40];

int main () {
	ll t, n, k, perfectPower;
	long long maxSize;
	int flag = 0;
	scanf("%Lf", &t);
	while(t--) {
		flag = 0;
		scanf("%Lf%Lf", &n, &k);
		maxSize = (long long)((ll)log2(pow(10, 16)) / (ll)log2(k));
		ll *p = new ll[maxSize+10];
		for(long long i = 0; i <= maxSize+5; i++)
			p[i] = 0;
		for(long long i = 0; i < n; i++)
			scanf("%Lf", &ar[i]);

		for(long long i = 0; i < n; i++){
			if(ar[i] != 0) {
				ll temp = ar[i];
				do {
					perfectPower = (ll)((ll)log2(temp)/(ll)log2(k));
					temp = temp - pow(k, floor(perfectPower));
					if(p[(long long)(perfectPower)] == 1) {
						flag = 1;
						printf("NO\n");
						break;
					}
					else if(p[(long long)(perfectPower)] == 0){
						p[(long long)(perfectPower)]++;
					}
				}
				while(temp > 0);
				if(flag == 1)
					break;
			}
		}
		if(flag == 0)
			printf("YES\n");
		delete[] p;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
ll ar[30];

int main () {
	ll t, n, k, maxSize, perfectPower;
	int flag = 0;
	scanf("%lld", &t);
	while(t--) {
		flag = 0;
		scanf("%lld%lld", &n, &k);
		maxSize = (ll)((ll)log2(pow(10, 16)) / (ll)log2(k));
		ll *p = new ll[maxSize+1];
		for(ll i = 0; i < maxSize; i++)
			p[i] = 0;
		for(ll i = 0; i < n; i++)
			scanf("%lld", &ar[i]);

		for(ll i = 0; i < n; i++){
			if(ar[i] != 0) {
				ll temp = ar[i];
				do {
					perfectPower = (ll)((ll)log2(temp)/(ll)log2(k));
					temp = temp - pow(k, perfectPower);
					// printf("%lld %lld ", perfectPower, temp);
					if(p[perfectPower] == 1) {
						flag = 1;
						printf("NO\n");
						break;
					}
					else if(p[perfectPower] == 0){
						p[perfectPower]++;
					}
				}
				while(temp > 0);
				if(flag == 1)
					break;
			}
		}
		if(flag == 0)
			printf("YES\n");
		delete[] p;
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

ll power(ll x, ll y) {
	if(y == 0) return 1;
	if(y & 1) return x * power(x, y/2)  * power(x, y/2);
	return power(x, y/2)  * power(x, y/2);
}

int main() {
	ll t, n, k;
	cin >> t;
	const ll MAX = 1e16+1;
	while(t--) {
		cin >> n >> k;

		vector<ll> a, b(n);
		map<ll,ll> mp;
		a.push_back(1);
		for(ll i=1; power(k, i) < MAX; i++) a.push_back(a[i-1] * k);
		// cout << endl;
		for(ll i=0; i<n; i++) cin >> b[i];
		sort(b.rbegin(), b.rend());
		// for(auto k: b) cout << k << " ";
		// cout<< endl;
		ll flag = 0;

		for(ll i=0; i<n; i++) {
			if(!b[i]) {
				cout << "YES" << endl;
				flag = 1;
				break;
			}

			while(b[i] > 0) {
				ll idx = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
				// cout << b[i] << " idx: " << idx << endl;
				if(mp[idx]) {
					cout << "NO" << endl;
					flag = 1;
					break;
				}
				b[i] -= a[idx];
				mp[idx] = 1;
			}

			if(flag) break;
		}
		if(!flag) cout << "YES" << endl;
		mp.clear();
		a.clear();
		b.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long double ll;

using namespace std;
ll ar[40];

int main () {
	ll t, n, k, perfectPower;
	long long maxSize;
	int flag = 0;
	scanf("%Lf", &t);
	while(t--) {
		flag = 0;
		scanf("%Lf%Lf", &n, &k);
		maxSize = (long long)((ll)log2(pow(10, 16)) / (ll)log2(k));
		ll *p = new ll[maxSize+10];
		for(long long i = 0; i < maxSize; i++)
			p[i] = 0;
		for(long long i = 0; i < n; i++)
			scanf("%Lf", &ar[i]);

		for(long long i = 0; i < n; i++){
			if(ar[i] != 0) {
				ll temp = ar[i];
				do {
					perfectPower = (ll)((ll)log2(temp)/(ll)log2(k));
					temp = temp - pow(k, floor(perfectPower));
					if(p[(long long)(perfectPower)] == 1) {
						flag = 1;
						printf("NO\n");
						break;
					}
					else if(p[(long long)(perfectPower)] == 0){
						p[(long long)(perfectPower)]++;
					}
				}
				while(temp > 0);
				if(flag == 1)
					break;
			}
		}
		if(flag == 0)
			printf("YES\n");
		delete[] p;
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		map<int, int> mp;
		for (int i = 0; i < n; ++i)
		{
			int tmp = v[i];
			int pow = 1;
			while (tmp)
			{
				++mp[tmp%k * pow];
				tmp /= k;
				pow *= k;
			}
		}

		bool work = true;
		for (auto m : mp)
		{
			if (m.first != 0 && m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<ll> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<ll, int> mp;
		for (int i = 0; i < n; ++i)
		{
			ll tmp = v[i];
			ll pow = 1;
			while (tmp)
			{
				++mp[(tmp%k) * pow];
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first <= 1)
				continue;
			if (m.first < k || m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<ll> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<ll, int> mp;
		for (int i = 0; i < n; ++i)
		{
			ll tmp = v[i];
			ll pow = 1;
			while (tmp)
			{
				if (tmp%k != 0)
				mp[pow] += tmp % k;
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first == 0)
				continue;
			if ((m.first > 1 && m.first < k) || m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<int, int> mp;
		for (int i = 0; i < n; ++i)
		{
			if (v[i] > 1 && v[i] < k)
			{
				work = false;
				continue;
			}
			int tmp = v[i];
			int pow = 1;
			while (tmp)
			{
				++mp[(tmp%k) * pow];
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first != 0 && m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		sort(v.begin(), v.end());

		vector<bool> fit(n);
		ll num = 1;
		while (num < 2e6)
		{
			for (int i = 0; i < n; ++i)
			{
				if (v[i] == 0)
					fit[i] = true;
				if (v[i] < num)
					continue;
				if (v[i] % num == 0)
				{
					fit[i] = true;
					break;
				}
			}
			num *= k;
		}
		bool work = true;
		for (int i = 0; i < n; ++i)
			if (fit[i] == false)
			{
				work = false;
			}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<ll> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<ll, int> mp;
		for (int i = 0; i < n; ++i)
		{
			if (v[i] > 1 && v[i] < k)
			{
				work = false;
				continue;
			}
			ll tmp = v[i];
			ll pow = 1;
			while (tmp)
			{
				++mp[(tmp%k) * pow];
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first != 0 && m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		map<int, int> mp;
		for (int i = 0; i < n; ++i)
		{
			int tmp = v[i];
			int pow = 1;
			while (tmp)
			{
				++mp[tmp%k * pow];
				tmp /= k;
				pow *= k;
			}
		}

		bool work = true;
		for (auto m : mp)
		{
			if (m.first!=0 && m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<int, int> mp;
		for (int i = 0; i < n; ++i)
		{
			if (v[i] < k)
			{
				work = false;
				break;
			}
			int tmp = v[i];
			int pow = 1;
			while (tmp)
			{
				++mp[(tmp%k) * pow];
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first != 0 && m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main()
{
	//freopen("src.txt", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		vector<ll> v(n);
		for (int i = 0; i < n; ++i)
			cin >> v[i];

		bool work = true;
		map<ll, int> mp;
		for (int i = 0; i < n; ++i)
		{
			ll tmp = v[i];
			ll pow = 1;
			while (tmp)
			{
				++mp[(tmp%k) * pow];
				tmp /= k;
				pow *= k;
			}
		}
		for (auto m : mp)
		{
			if (m.first == 0)
				continue;
			if ((m.first > 1 && m.first < k) || m.second > 1)
				work = false;
		}

		if (work)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
const int LOG=60;
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		lvector a(n);
		for (auto& i : a) {
			cin >> i;
		}
		lvector cnt(LOG,0);
		for (auto &v: a) {
			for (int j=0;j<LOG && v;++j) {
				cnt[j]+=v%k;
				v/=k;
			}
		}
		if (*max_element(cnt.begin(), cnt.end()) < 2) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
const int LOG=60;
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		lvector a(n);
		read(a,n);
		lvector cnt(LOG,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && LOG;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		if (*max_element(cnt.begin(), cnt.end()) < 2) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		ll a[n];
		read(a,n);
		lvector cnt(60,0);
		bool res=1;
		rep(i,0,n)
		{
			for(ll j=0;j<a[i] && 60;++j)
			{
				cnt[j]+=a[i]%k;
				a[i]/=k;
				if(cnt[j]>1)res=0;
			}
		}
		yes(res);
		cout<<endl;

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		ll a[n];
		read(a,n);
		lvector cnt(60,0);
		bool res=1;
		rep(i,0,n)
		{
			ll ma=a[i] && 60;
			rep(j,0,ma)
			{
				cnt[j]+=a[i]%k;
				a[i]/=k;
				if(cnt[j]>1)res=0;
			}
		}
		yes(res);
		cout<<endl;

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
const int LOG=60;
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		lvector a(n);
		for (auto& i : a) {
			cin >> i;
		}
		lvector cnt(LOG,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && LOG;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		if (*max_element(cnt.begin(), cnt.end()) < 2) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		ll a[n];
		read(a,n);
		lvector cnt(60,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && 60;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		yes(res);
		cout<<endl;

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		lvector a(n);
		read(a,n);
		lvector cnt(60,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && 60;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		yes(res);
		cout<<endl;

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		ll a[n];
		read(a,n);
		lvector cnt(60,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && 60;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		if (*max_element(cnt.begin(), cnt.end()) < 2) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}

	}
}
///////////////////SOLUTION


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef short int int16;
typedef long double ldouble;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

typedef pair < int , int > ipair;
typedef pair < LL , LL > lpair;
typedef pair < int , int > pii;
typedef pair < LL , LL > pll;
typedef pair<double, double> pdd;

typedef map < int,int > imap;
typedef map < LL , LL > lmap;
typedef map < char , int > cimap;
typedef map < string , int > simap;

typedef vector < int > ivector;
typedef vector < LL > lvector;
typedef vector < string > svector;

typedef set < int > iset;
typedef set < LL > lset;
typedef set < char > cset;
typedef set < string > sset;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

const int size = 1e5 + 5;
const double eps = 0.0001;
const ldouble PI = 3.1415926535897932384626433832795;
const LL  MOD = 1000000007;
const LL INF = 1LL << 62;
const LL MAX5 = 100001;
const LL MAX6 = 1000001;
const LL MAX17 = 99999999999999999;
const double DMAX = 2e18+5;
const int P = 239017;

#define MEMS(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max6(a,b,c,d,e,f) max(max3(a,b,c),max3(d,e,f))
#define min6(a,b,c,d,e,f) min(min3(a,b,c),min3(d,e,f))
#define all(x) (x).begin(), (x).end()
#define rall(c) (c).rbegin(), (c).rend()
#define rep(i,a,n) for (long long i=a;i<n;++i)
#define per(i,n,a) for (long long i=n-1;i>=a;--i)
#define read(a,n) for(LL i=0;i<n;++i)cin>>a[i];
#define print(a,n) for(int i=0;i<n;++i)cout<<a[i]<<" ";
#define vout(); for(int i=0;i<res.size();++i)cout<<res[i]<<" ";
#define reunique(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define res(); cout<<res;
#define ones(a) __builtin_popcount(a);
#define onesll(a) __builtin_popcountll(a);
#define log2(val) logb(val)
void solution();
void include_file();

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//srand(time(0));
//include_file();
//#define mishatron

#ifdef mishatron
	clock_t z = clock();
#endif
    solution();
#ifdef mishatron
    printf("\n*** EXECUTION TIME: %.3lf***\n", (double)(clock() - z) / CLOCKS_PER_SEC);
#endif

return 0;
}
inline void include_file(){
	ios_base::sync_with_stdio(true);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
}
inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}
inline string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}
inline LL cubic_root(LL x) {
    LL l = 0, r = MAX6;
    while (l != r) {
        LL m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
inline float FastInvSqrt(float x) {//   1/sqrt(X)
  float xhalf = 0.5f * x;
  int i = *(int*)&x;  // i?aanoaaei aeou float a aeaa oaeiai ?enea
  i = 0x5f3759df - (i >> 1);  // eaeiai ?a?oa caanu i?ienoiaeo ?
  x = *(float*)&i;
  x = x*(1.5f-(xhalf*x*x));
  return x;
}
inline LL gcd(LL a,LL b)
{
	while(b ^= a ^= b ^= a = a % b);
	return a;
}
inline LL lcm(LL a, LL b)
{
  return a/gcd(a, b)*b;
}
unsigned long long NCR(unsigned long long n, unsigned long long r)
{
    if (r == 0) return 1;
    if (r > n>>1) return NCR(n, n-r); // save some computation
    unsigned long long res = 1;
    for(long long k = 1; k <= r; ++k)
    {
        res *= (unsigned long long)(n-k+1);
        res /= k;
    }
    return res;
}
//2^61-1
constexpr uint64_t mod = (1ull<<61) - 1;
inline uint64_t modmul(uint64_t a, uint64_t b){
	uint64_t l1 = (uint32_t)a, h1 = a>>32, l2 = (uint32_t)b, h2 = b>>32;
	uint64_t l = l1*l2, m = l1*h2 + l2*h1, h = h1*h2;
	uint64_t ret = (l&mod) + (l>>61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + 1;
	ret = (ret & mod) + (ret>>61);
	ret = (ret & mod) + (ret>>61);
	return ret-1;
}
void yes()
{
	cout<<"YES";
}
void no()
{
	cout<<"NO";
}

void yes(bool res, bool small=false)
{
	if(!small)
	{
		if(res)
		cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		if(res)
		cout<<"Yes";
		else cout<<"No";
	}

}
void dabl(double x)
{
	printf("%.10lf",x);
}
namespace bits
{
	template<typename X> inline X MAX(const X& a, const X& b)
{ return b & ((a-b) >> 31) | a & (~(a-b) >> 31);}
template<typename X> inline X MIN(const X& a, const X& b)
{ return a & ((a-b) >> 31) | b & (~(a-b) >> 31);}

//i?iaa?ea ia noaiaiu 2
inline bool check2(const LL n)
{
	return 	n > 0 && (n & (n - 1));
}
//inoaoie io aaeaiey 2^n ia m
inline LL ostatok2(const LL n, const LL m)
{
	return m & (n-1);
}
template<typename X>
inline void SWAP(X &a, X &b)
{
	a^=b;
	b^=a;
	a^=b;
}

inline size_t count_1_in_LL(unsigned long long n)
{
    std::size_t i(0);
    for (;n;++i) n&=n-1;
    return i;
}
}
// deg[] = {1, P, P^2, P^3, ...}
// h[] = {0, s[0], s[0]*P + s[1], s[0]*P^2 + s[1]*P + s[2], ...}
/*unsigned long long h[n + 1], deg[n + 1];
h[0] = 0, deg[0] = 1;
for (int i = 0; i < n; i++) {
  h[i + 1] = h[i] * P + s[i];
  deg[i + 1] = deg[i] * P;
}
auto get_hash = [&]( int l, int r ) { // [l..r]
  return h[r + 1] - h[l] * deg[r - l + 1];
};*/
void debug() {cout<<endl;}
template <typename H, typename... T> void debug(H p, T... t) {
   std::cout << p<<" ";
   debug(t...);
}
vector <vector<int> > g;
///////////////////SOLUTION
const int LOG=60;
inline void solution()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		lvector a(n);
		read(a,n);
		lvector cnt(LOG,0);
		bool res=1;
		for (auto &v: a) {
			for (int j=0;j<v && LOG;++j) {
				cnt[j]+=v%k;
				v/=k;
				if(cnt[j]>1)res=0;
			}
		}
		yes(res);
		cout<<endl;

	}
}
///////////////////SOLUTION