Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can:   either choose position $pos$ ($1 \le pos \le n$) and increase $v_{pos}$ by $k^i$;  or not choose any position and skip this step. 

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


-----Input-----

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

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

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


-----Output-----

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


-----Example-----
Input
5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810

Output
YES
YES
NO
NO
YES



-----Note-----

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

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

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

In the fifth test case, you can skip $9^0$ and $9^1$, then add $9^2$ and $9^3$ to $v_3$, skip $9^4$ and finally, add $9^5$ to $v_2$.

Source: codeforces | Difficulty: MEDIUM
Tags: Bit manipulation

Sorting

Implementation

Greedy algorithms

Number theory

Mathematics


Solutions:
for t in range(int(input())):
	(n, k) = [*map(int, input().split())]
	p = 1
	while p < 1e+16:
		p *= k
	a = [*map(int, input().split())]
	valid = True
	while valid:
		chk = False
		for i in range(len(a)):
			if a[i] >= p:
				if chk:
					valid = False
					break
				else:
					chk = True
					a[i] -= p
		if sum(a) == 0 or p == 1:
			valid = False
		p //= k
	print('NO' if sum(a) else 'YES')


def to_base(k, number):
	k_base = []
	while number:
		k_base.append(number % k)
		number //= k
	return k_base

def can_be_game_result(array, k):
	max_item = max(array)
	used_powers = [0] + [0] * len(to_base(k, max_item))
	for item in array:
		item_in_k_base = to_base(k, item)
		for (idx, used) in enumerate(item_in_k_base):
			used_powers[idx] += used
	return max(used_powers) <= 1
test_cases = int(input())
for _ in range(test_cases):
	(_, k) = map(int, input().split())
	desired_array = [int(x) for x in input().split()]
	result = can_be_game_result(desired_array, k)
	print('YES' if result else 'NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for each in range(59, -1, -1):
		temp = k ** each
		for i in range(n):
			if arr[i] >= temp:
				arr[i] -= temp
				break
	if len([i for i in arr if i != 0]) > 0:
		print('NO')
	else:
		print('YES')


import math

def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		a = [int(x) for x in input().split()]
		l = math.ceil(math.log(1e+16, k))
		powers_visited = {}
		for i in range(l + 1):
			powers_visited[i] = False
		possible = True
		for i in range(n):
			x = a[i]
			j = l
			while x > 0 and j >= 0:
				if powers_visited[j] == False and k ** j <= x:
					x -= k ** j
					powers_visited[j] = True
				j -= 1
			if x != 0:
				possible = False
				break
		if possible:
			print('YES')
		else:
			print('NO')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	cnt = 1
	while cnt * k <= a[n - 1]:
		cnt *= k
	while cnt >= 1:
		for i in range(n):
			if cnt <= a[i]:
				a[i] -= cnt
				break
		cnt /= k
	if sum(a) == 0:
		print('YES')
	else:
		print('NO')


def cb(l, n, arr, to_base=10):
	if n < to_base:
		arr[l] += n
		return
	else:
		cb(l + 1, n // to_base, arr, to_base)
		arr[l] += n % to_base
		return
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	arr = [0 for i in range(100)]
	for z in a:
		cb(1, z, arr, k)
	if max(arr) > 1:
		print('NO')
	else:
		print('YES')


import sys
import math
import bisect

def solve(A, m):
	n = len(A)
	d = dict()
	for a in A:
		cnt = 0
		while a:
			if a % m:
				if cnt not in d:
					d[cnt] = 0
				d[cnt] += a % m
			a //= m
			cnt += 1
	if len(d) == 0:
		return True
	return max(list(d.values())) <= 1

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		A = list(map(int, input().split()))
		if solve(A, m):
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = []
	d = set()
	w = 0
	for i in range(n):
		p = a[i]
		while p > k - 1:
			q = 1
			r = 0
			while q * k <= p:
				q = q * k
				r = r + 1
			p = p - q
			if r in d:
				w = w + 1
				break
			else:
				d.add(r)
		if p == 0:
			continue
		elif p == 1:
			if 0 in d:
				w = w + 1
				break
			else:
				d.add(0)
		else:
			w = w + 1
			break
	if w == 0:
		print('YES')
	else:
		print('NO')


def maxPow(p, k):
	n = p
	i = 0
	while p > 0:
		p //= k
		i += 1
	if k ** i > n:
		i -= 1
	return i

def pows(n, k, s):
	while n > 0:
		p = maxPow(n, k)
		n -= k ** p
		if p in s:
			return False
		else:
			s.add(p)
	return True
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	res = True
	s = set()
	for j in l:
		if j > 0:
			res = res and pows(j, k, s)
	if res:
		print('YES')
	else:
		print('NO')


T = int(input())

def k_beats(n, k, l):
	d = set()
	for i in range(len(l)):
		t = 1
		j = 0
		while l[i]:
			while not l[i] % t:
				t = t * k
				j = j + 1
			l[i] = l[i] - t // k
			if j - 1 in d:
				return 'NO'
			d.add(j - 1)
			if l[i] < 0:
				return 'NO'
	return 'YES'
for i in range(T):
	r = []
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	print(k_beats(n, k, l))


import math

def mpow(b, p):
	if p != -1:
		return pow(b, p)
	return 0
t = int(input())
for ir in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	l = [int(x) for x in input().split()]
	l.sort()
	mm = pow(10, 16)
	s = int(math.log(mm, k))
	c = n - 1
	for i in range(s, -2, -1):
		if l[c] == 0:
			c = -1
			break
		if c == -1:
			break
		if mpow(k, i) == l[c]:
			c -= 1
		if mpow(k, i) < l[c]:
			l[c] -= mpow(k, i)
			l.sort()
	if c == -1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = [0] * 100
	flag = True
	for x in a:
		i = 0
		while x:
			if x % k > 1:
				flag = False
				break
			if x % k == 1:
				p[i] += 1
			x //= k
			i += 1
	else:
		if flag and max(p) <= 1:
			print('YES')
		else:
			print('NO')


def ifpow(x, k):
	take = []
	i = 0
	while x != 0:
		if x % k:
			if x % k > 1:
				return [-1]
			take.append(i)
		x //= k
		i += 1
	return take
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	pows = [1] * 60
	res = True
	for x in a:
		take = ifpow(x, k)
		try:
			if take[0] == -1:
				res = False
				break
		except:
			pass
		for y in take:
			pows[y] -= 1
	for x in pows:
		res = res and x >= 0
	print(('NO', 'YES')[res])


def bin(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a
		a *= a
		b >>= 1
	return res
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = I()
	l = I()
	maxx = 1e+16
	s = 1
	while bin(k, s) <= 1e+16:
		s += 1
	s -= 1
	max_val = bin(k, s)
	flag = False
	for i in range(s, -1, -1):
		max_val = bin(k, i)
		count = 0
		for j in range(len(l)):
			if l[j] >= max_val:
				l[j] -= max_val
				count += 1
			if count > 1:
				flag = True
				print('NO')
				break
		if flag:
			break
	if not flag:
		flag2 = False
		for e in l:
			if e != 0:
				print('NO')
				flag2 = True
				break
		if not flag2:
			print('YES')


t = int(input())

def check(temp):
	if any([x for x in temp if x > 1]):
		return 0
	return 1

def check2(req):
	finalSet = set()
	for item in req:
		for x in range(len(item)):
			if item[x]:
				if x in finalSet:
					return 0
				finalSet.add(x)
	return 1
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split() if int(x)]
	req = []
	flag = 1
	for item in arr:
		temp = []
		while item >= k:
			temp.append(item % k)
			item = item // k
		temp.append(item)
		req.append(temp)
		flag = flag and check(temp)
	if not flag:
		print('NO')
		continue
	flag = check2(req)
	if not flag:
		print('NO')
	else:
		print('YES')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		(n, k) = read()
		arr = read()
		helper = []
		i = 0
		while k ** i <= 10 ** 16:
			helper.append(k ** i)
			i += 1
		sett = set()
		flag = 0
		for i in range(n):
			elem = arr[i]
			if elem == 0:
				continue
			while elem > 0:
				ind = bisect(helper, elem)
				elem -= helper[ind - 1]
				if not ind - 1 in sett:
					sett.add(ind - 1)
				elif elem < 0:
					flag = 1
					break
				else:
					flag = 1
					break
			if flag:
				break
		if flag:
			print('NO')
		else:
			print('YES')
solve()


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def main():
	tt = inin()
	for _ in range(tt):
		v = {}
		(n, k) = cin()
		a = ain()
		ans = 0
		for i in a:
			j = 0
			if i == 0:
				continue
			jj = 0
			while 1:
				if i % pow(k, j) == 0:
					j += 1
				elif jj + j - 1 in v:
					ans = -1
					break
				else:
					jj = jj + j - 1
					v[jj] = 1
					i = i // pow(k, j - 1)
					i -= 1
					j = 0
				if i == 0:
					break
				if ans == -1:
					break
		if ans == 0:
			print('YES')
		else:
			print('NO')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	print_res = 'YES'
	des = [0] * n
	cnt = [0] * 1000
	temp = input().split()
	for j in range(n):
		des[j] = int(temp[j])
	for j in range(n):
		loc = 0
		while des[j]:
			cnt[loc] += des[j] % x
			loc += 1
			des[j] = des[j] // x
	for j in range(1000):
		if cnt[j] > 1:
			print_res = 'NO'
			break
	print(print_res)


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	while 1:
		if any(a) == 0:
			print('YES')
			break
		if sum((x % k for x in a)) > 1:
			print('NO')
			break
		a = [x // k for x in a]


import collections

def block(x, k):
	v = []
	ans = []
	while x > 0:
		v.append(int(x % k))
		x = int(x / k)
	for i in range(0, len(v)):
		if v[i] == 1:
			ans.append(i)
		elif v[i] > 1:
			ans = []
			break
	return ans
t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	flag = 0
	for i in range(0, n):
		if a[i] != 0:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		b = []
		flag = 0
		for i in range(0, n):
			if a[i] != 0:
				val = block(a[i], k)
				if len(val) == 0:
					flag = 1
					break
				b += val
		if flag == 1:
			print('NO')
		else:
			d = collections.Counter(b)
			flag = 0
			for i in d:
				if d[i] > 1:
					flag = 1
					break
			if flag == 1:
				print('NO')
			else:
				print('YES')


t = input()
t = int(t)
for _ in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
	exp = []
	i = 0
	while k ** i <= 10 ** 16:
		exp.append(k ** i)
		i += 1
	exp.sort(reverse=True)
	index = len(exp) - 1
	stop = False
	ans = 0
	z = 0
	while not stop:
		cnt = 0
		temp = 0
		for i in range(len(a)):
			if a[i] > a[temp]:
				temp = i
		if z == len(exp):
			ans = 'NO'
			stop = True
			break
		if a[temp] >= exp[z]:
			a[temp] -= exp[z]
		for i in range(len(a)):
			if a[i] == 0:
				cnt += 1
			if cnt == len(a):
				stop = True
				ans = 'YES'
				break
		z += 1
	print(ans)


tests = int(input())
for test in range(tests):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0 for i in range(60)]
	for i in a:
		j = 0
		while i:
			b[j] += i % k
			i //= k
			j += 1
	for i in b:
		if i > 1:
			print('NO')
			break
	else:
		print('YES')


def power(g, z):
	w = g
	c = 0
	while w >= z:
		c += 1
		w = w // z
	return c
for i in range(int(input())):
	a = 0
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in l:
		if i == 0:
			continue
		j = i
		while j > 0:
			q = power(j, k)
			if q in l1:
				a += 1
				break
			j = j - k ** q
			l1.append(q)
		if j != 0:
			a += 1
			break
	if a == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for t1 in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	setOfA = set()

	def factorization(num):
		powK = 0
		if (num - 1) % k == 0:
			if powK in setOfA:
				return False
			num -= 1
			setOfA.add(powK)
		while num % k == 0 and num != 0:
			while num != 1 and num % k == 0:
				num //= k
				powK += 1
			if (num - 1) % k == 0:
				if powK in setOfA:
					return False
				num -= 1
				setOfA.add(powK)
		return num == 0
	success = True
	for ai in a:
		if ai == 0:
			continue
		if not factorization(ai):
			success = False
			break
	print(('NO', 'YES')[success])


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')

def solve(n, k, a):
	a.sort(reverse=True)
	m = a[0]
	things = [1, k]
	while m >= things[-1]:
		things.append(things[-1] * k)
	things.pop()
	while a[0] > 0 and len(things) > 0:
		curr = things.pop()
		while curr > a[0] and len(things) > 0:
			curr = things.pop()
		a[0] -= curr
		a.sort(reverse=True)
	return sum(a) == 0
	pass
for i in range(int_in()):
	(n, k) = arr_in()
	a = arr_in()
	bool_out(solve(n, k, a))


from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

def LI():
	return list(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

def LS():
	return S().split()

def IR(n):
	res = [None] * n
	for i in range(n):
		res[i] = II()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI()
	return res

def FR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR_(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI_()
	return res

def SR(n):
	res = [None] * n
	for i in range(n):
		res[i] = S()
	return res

def LSR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LS()
	return res
mod = 1000000007
inf = float('INF')

def solve():
	t = II()
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		h = []
		for i in a:
			heappush(h, -i)
		x = 1
		m = max(a)
		while x < m:
			x *= k
		while x >= 1:
			m = -heappop(h)
			if m >= x:
				m -= x
			heappush(h, -m)
			x //= k
		if heappop(h) == 0:
			print('YES')
		else:
			print('NO')
	return
solve()


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	la = list(map(int, input().split()))
	l = []
	Max = max(la)
	Count = True
	x = True
	while x == True:
		value = Max ** (1 / Count)
		if value <= k:
			break
		Count = Count + 1
	for i in range(len(la)):
		for ii in range(Count, -1, -1):
			if la[i] - k ** ii >= 0 and la[i] != 0:
				if ii not in l:
					la[i] = la[i] - k ** ii
					l.append(ii)
	ans = la.count(0)
	if ans == len(la):
		print('YES')
	else:
		print('NO')


from math import log
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	se = set()
	flag = 0
	for i in range(n):
		if a[i] == 0:
			None
		else:
			while a[i] > 0:
				val = round(log(a[i], k))
				if k ** val > a[i]:
					val -= 1
				if val not in se:
					se.add(val)
				else:
					flag = 1
					break
				a[i] -= k ** val
		if flag == 1:
			break
	else:
		print('YES')
	if flag == 1:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
from math import log, floor

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		ans = 1
		s = set()
		while True:
			flag = 1
			mx = 0
			mxi = -1
			for (i, item) in enumerate(arr):
				if item > mx:
					mx = item
					flag = 0
					mxi = i
					break
			if flag:
				break
			z = floor(log(mx, k))
			zz = k ** z
			while zz * k <= mx:
				z += 1
				zz *= k
			while zz > mx and z:
				z -= 1
				zz //= k
			if z not in s:
				s.add(z)
				arr[mxi] -= zz
			else:
				ans = 0
				break
		if ans:
			if max(arr) == 0 and len(set(arr)) == 1:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	a = (*R(),)
	r = 0
	while any(a):
		r |= [x % k for x in a if x % k] > [1]
		a = [x // k for x in a]
	print('YNEOS'[r::2])


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(dic, ans) = ({}, 'YES')
	for el in map(int, input().split()):
		c = 0
		while el != 0:
			if el % k == 0:
				c += 1
				el //= k
			elif (el - 1) % k == 0 or el == 1:
				try:
					_ = dic[c]
					ans = 'NO'
					break
				except:
					dic[c] = 1
				el -= 1
			else:
				ans = 'NO'
				break
		if ans == 'NO':
			break
	print(ans)


def fn(n, k):
	if n == 0:
		return [1]
	if n == 1:
		return [1]
	if n % k == 0:
		return [0] + fn(n // k, k)
	elif (n - 1) % k == 0:
		return [1] + fn((n - 1) // k, k)
	else:
		return [None]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	v = [True for _ in range(60)]
	ans = 'YES'
	for aa in a:
		if aa == 0:
			continue
		d = fn(aa, k)
		if d[-1] is None:
			ans = 'NO'
			break
		for i in range(len(d)):
			if d[i] == 1 and v[i] == True:
				v[i] = False
			elif d[i] == 1 and v[i] == False:
				ans = 'NO'
				break
	print(ans)


from math import log
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	if arr.count(0) == n:
		print('Yes')
		continue
	check = {*range(65)}
	f = True
	for e in arr:
		while f and e > 0:
			p = int(log(e, k) + 1e-09)
			p -= 1 if k ** p > e else 0
			if p not in check:
				print('No')
				f = False
				break
			check.remove(p)
			e -= k ** p
	print('Yes\n' if f else '', end='')


import math
from bisect import bisect_right
from decimal import Decimal, getcontext
getcontext().prec = 6

def slve(n, k, a):
	p = max(a)
	s = []
	q = int(Decimal(math.log(p)) / Decimal(math.log(k)))
	arr = []
	for i in range(q + 2):
		arr.append(k ** i)
	for x in a:
		while x != 0:
			p = bisect_right(arr, x)
			s.append(p - 1)
			x = x - arr[p - 1]
	if len(set(s)) != len(s):
		return 'NO'
	else:
		return 'YES'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) == 1 and a[0] == 0:
		print('YES')
	else:
		print(slve(n, k, a))


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().strip().split()]
	a = [int(x) for x in input().strip().split()]
	a.sort()
	iset = set([])
	res = True
	pi = 0
	for i in range(n):
		pi = 0
		while a[i] != 0:
			if a[i] % k == 0:
				ci = pi
				while a[i] % k == 0 and a[i] != 1:
					a[i] = a[i] // k
					ci += 1
				if a[i] == 1:
					ind = ci
					a[i] = 0
				elif a[i] % k == 1:
					a[i] = a[i] - 1
					ind = ci
					pi = ci
				else:
					res = False
					break
			elif a[i] == 1:
				ind = 0
				a[i] = 0
			elif a[i] % k == 1:
				ind = 0
				a[i] -= 1
			else:
				res = False
				break
			if ind not in iset:
				iset.add(ind)
			else:
				res = False
				break
	if res:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, p) = map(int, input().split())
	now = list(map(int, input().split()))
	while now:
		last = now
		now = []
		cnt = 0
		for x in last:
			cnt += x % p
			x //= p
			if cnt >= 2:
				print('NO')
				break
			if x != 0:
				now.append(x)
		else:
			continue
		break
	else:
		print('YES')


def findrange(integer, K):
	init = 0
	while K ** init <= integer:
		init += 1
	return init

def decompose(integer, farray, flist):
	exp = len(flist) - 1
	while exp >= 0:
		factor = flist[exp]
		if integer >= factor:
			integer -= factor
			if farray[exp] == 1:
				return False
			else:
				farray[exp] = 1
		else:
			exp -= 1
	return True
T = int(input())
for test in range(T):
	(N, K) = list(map(int, input().split()))
	goalarray = list(map(int, input().split()))
	result = 'YES'
	farraysize = findrange(max(goalarray), K)
	if farraysize > 0:
		farray = [0 for i in range(farraysize)]
		flist = [K ** i for i in range(farraysize)]
		for goal in goalarray:
			if not decompose(goal, farray, flist):
				result = 'NO'
				break
	print(result)


T = int(input())
for s in range(T):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	maxPower = 1
	while maxPower <= 10000000000000000:
		maxPower *= k
	while maxPower > 0:
		s = 0
		for i in range(len(array)):
			if array[i] >= maxPower:
				s += 1
				if s <= 1:
					array[i] = array[i] - maxPower
		maxPower //= k
	if min(array) == 0 and max(array) == 0:
		print('YES')
	else:
		print('NO')


def change_base(n, k):
	arr = []
	while n != 0:
		rem = n % k
		n = n // k
		arr.append(rem)
	return arr
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	flag = True
	farr = [False for i in range(66)]
	for i in range(n):
		if arr[i] <= 0:
			continue
		s = change_base(arr[i], k)
		if s.count(1) + s.count(0) != len(s):
			flag = False
		for i in range(len(s)):
			if s[i] == 1 and farr[i] == True:
				flag = False
			if s[i] == 1 and farr[i] == False:
				farr[i] = True
	if flag:
		print('YES')
	else:
		print('NO')


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	ch = 0
	for i in range(n):
		ch = 0
		if a[i] > 1:
			while a[i] > 0 and ch < 1:
				j = int(math.log(a[i], k))
				if k ** (j + 1) <= a[i]:
					j = j + 1
				if k ** (j + 1) <= a[i]:
					j += 1
				if k ** j > a[i]:
					j -= 1
				if d.get(j, -1) != -1:
					ch = 1
					break
				d[j] = 1
				a[i] -= k ** j
			if ch == 1:
				break
		elif a[i] == 1:
			if d.get(0, -1) != -1:
				ch = 1
				break
			d[0] = 1
			a[i] = 0
		if a[i] != 0:
			break
	ch = 0
	for i in range(n):
		if a[i] != 0:
			ch = 1
			break
	if ch == 1:
		print('NO')
	else:
		print('YES')


t = eval(input())
for k in range(t):
	numbers = list(map(int, input().split()))
	n = numbers[0]
	k = numbers[1]
	index = []
	for i in range(100):
		index.append(-1)
	arr = []
	numbers = list(map(int, input().split()))
	for i in range(n):
		arr.append(numbers[i])
	flag = 0
	for i in range(n):
		if arr[i] != 0:
			remaining = arr[i]
			while 1:
				temp = 1
				count = 0
				while temp < remaining:
					temp = temp * k
					count += 1
				if temp == remaining:
					if index[count] == -1:
						index[count] = 1
					else:
						flag = 1
					break
				else:
					temp /= k
					remaining -= temp
					if count > 0 and index[count - 1] == -1:
						index[count - 1] = 1
					else:
						flag = 1
						break
			if flag == 1:
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	flag = 0
	while arr != [0 for i in arr]:
		b = [x % k for x in arr]
		arr = [x // k for x in arr]
		if sum(b) > 1:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')


import sys
t = int(sys.stdin.readline())

def used(n, k):
	ans = set()
	i = 0
	while n > 0:
		used = n % k
		if used == 1:
			ans.add(i)
		if used > 1:
			return None
		n = n // k
		i += 1
	return ans
for _ in range(t):
	(n, k) = [int(i) for i in sys.stdin.readline().split()]
	a = [int(i) for i in sys.stdin.readline().split()]
	seen = set()
	for v in a:
		now = used(v, k)
		if now is None or len(now & seen) != 0:
			seen = None
			print('NO')
			break
		seen = seen | now
	if not seen is None:
		print('YES')


def main():
	return '\n'.join((ifPossibleToMake(*case1312c()) for x in range(int(input()))))

def case1312c():
	(nValues, number) = map(int, input().split())
	array = tuple(map(int, input().split()))
	return (array, number)

def ifPossibleToMake(array, number):
	usedPowers = set()
	for value in array:
		power = 0
		while value:
			remainder = value % number
			if remainder == 1 and power not in usedPowers:
				value -= 1
				usedPowers.add(power)
			elif remainder:
				return 'NO'
			value /= number
			power += 1
	return 'YES'
print(main())


task_number = int(input())

class FindContradiction(Exception):
	pass

def find_positions(number, base):
	result = set()
	current_position = 0
	while number > 0:
		if number % base not in (0, 1):
			raise FindContradiction()
		if number % base == 1:
			result.add(current_position)
		number = number // base
		current_position += 1
	return result
for _ in range(task_number):
	(n, k) = map(int, input().split())
	array = [int(item) for item in input().split()]
	used_positions = set()
	try:
		for number in array:
			positions = find_positions(number, k)
			if positions.intersection(used_positions):
				raise FindContradiction()
			used_positions.update(positions)
		print('YES')
	except FindContradiction:
		print('NO')


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():

	def tok(a):
		res = [0] * 60
		i = 0
		while a:
			(a, r) = divmod(a, k)
			if r > 1:
				return [-1]
			res[i] = r
			i += 1
		return res
	t = II()
	for _ in range(t):
		(n, k) = MI()
		aa = LI()
		used = [0] * 60
		br = False
		for a in aa:
			ret = tok(a)
			if ret == [-1]:
				br = True
				print('NO')
				break
			for i in range(60):
				if used[i] and ret[i]:
					br = True
					print('NO')
					break
				used[i] += ret[i]
			if br:
				break
		if br:
			continue
		print('YES')
main()


import math
arr = set()

def find(n, k):
	while n != 0:
		n1 = round(math.log(n, k))
		if k ** n1 > n:
			n1 -= 1
		if n1 in arr:
			return False
		else:
			n -= k ** n1
			arr.add(n1)
	return True
ns = int(input())
for i in range(ns):
	arr = set()
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) == 0:
		print('YES')
		continue
	f = 0
	for j in range(a):
		if l[j] == 0:
			continue
		elif find(l[j], b):
			continue
		else:
			f = 1
			break
	if f == 0:
		print('YES')
	if f == 1:
		print('NO')


import sys
input = sys.stdin.readline

def check(A, K):
	s = set()
	for a in A:
		i = 0
		while a:
			m = a % K
			if m == 0:
				pass
			elif m == 1:
				if i in s:
					return False
				s.add(i)
			else:
				return False
			a = a // K
			i += 1
	return True
t = int(input())
for _ in range(t):
	(N, K) = map(int, input().split())
	A = map(int, input().split())
	if check(A, K):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a)
	s = 0
	while k ** s < m:
		s += 1
	for i in range(s, -1, -1):
		for j in range(n):
			if a[j] >= k ** i:
				a[j] -= k ** i
				break
	flag = 0
	for i in range(n):
		if a[i] > 0:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
	t -= 1


T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	s = [int(x) for x in input().split()]
	L = []
	pre = []
	temp = 'YES'
	for i in range(60):
		pre.append(k ** i)
	for i in range(0, len(s)):
		ele = s[i]
		for j in range(len(pre) - 1, -1, -1):
			if ele >= pre[j]:
				L.append(j)
				ele -= pre[j]
		if ele != 0:
			temp = 'NO'
	if len(L) != len(set(L)):
		temp = 'NO'
	print(temp)


I = lambda : map(int, input().split())
from bisect import bisect_right as br
for _ in range(int(input())):
	(n, k) = I()
	(a, t, l, r, q) = (list(I()), 0, [1], 1, [])
	while r < 10 ** 16:
		r *= k
		l += [r]
	for i in a:
		w = br(l, i)
		p = set()
		for j in range(w - 1, -1, -1):
			if i >= l[j]:
				i -= l[j]
				p.add(j)
			if i == 0:
				break
		if i != 0:
			t = 1
			break
		q.append(p)
	for i in range(len(q)):
		for j in range(i + 1, len(q)):
			if len(q[i] & q[j]) != 0:
				t = 1
				break
	print(['YES', 'NO'][t])


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = [0] * 60
	for i in a:
		hi = 1
		while i > 0:
			r[hi] += i % k
			hi += 1
			i //= k
	nn = 0
	for j in r:
		if j > 1:
			nn = 1
			break
	print('NO' if nn == 1 else 'YES')


import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		const = k
		deg = 1
		tmp = max(a)
		while const < tmp:
			const *= k
			deg += 1
		used = defaultdict(bool)
		ans = 'YES'
		flag = 0
		for i in range(n):
			cur = a[i]
			mult = const
			cur_deg = deg
			while cur > 0:
				add = cur // mult
				if add == 1:
					if not used[cur_deg]:
						used[cur_deg] = True
					else:
						ans = 'NO'
						flag = 1
						break
				elif add != 0:
					ans = 'NO'
					flag = 1
					break
				cur %= mult
				mult //= k
				cur_deg -= 1
			if flag:
				break
		print(ans)
main()


from functools import reduce
t = int(input())
for x in range(t):
	l1 = input().split()
	n = int(l1[0])
	k = int(l1[1])
	a = list(map(int, input().split()))
	while a != [0 for x in a]:
		b = [x % k for x in a]
		if reduce(lambda x, y: x + y, b) > 1:
			print('NO')
			break
		a = [x // k for x in a]
	else:
		print('YES')


t = int(input())

def valid(a, k):
	v = set()
	for x in a:
		s = 0
		while x > 0:
			if x % k == 0:
				x //= k
				s += 1
				continue
			if x % k == 1:
				if s in v:
					return False
				v.add(s)
				x //= k
				s += 1
				continue
			return False
	return True
for it in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if valid(a, k):
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	import math
	(n, k) = map(int, input().split())
	dat = list(map(int, input().split()))
	dat.sort(reverse=True)
	if dat[0] == 0:
		print('YES')
		continue
	ma = math.ceil(math.log(dat[0], k))
	for i in range(ma, -1, -1):
		for j in range(n):
			if dat[j] == 0:
				continue
			if dat[j] >= k ** i:
				dat[j] -= k ** i
				break
	if sum(dat) == 0:
		print('YES')
	else:
		print('NO')


import math as m

def f1():
	N = int(input())
	Matrix = list()
	for j in range(0, N):
		M = int(input())
		input1 = [int(i) for i in input().split(' ')]
		input1.sort(reverse=True)
		for i in range(0, len(input1)):
			print(input1[i], end=' ')
		print('')

def f2():
	N = int(input())
	Matrix = list()
	for i in range(0, N):
		input1 = [int(i) for i in input().split(' ')]
		if input1[0] % input1[1] == 0:
			print('YES')
		else:
			print('NO')

def f3():
	Testcases = int(input())
	for i in range(0, Testcases):
		l1 = [int(j) for j in input().split(' ')]
		l2 = [int(k) for k in input().split(' ')]
		k = l1[1]
		flag = False
		counter1 = 0
		MAX1 = 0
		max_index = 0
		for i in range(0, len(l2)):
			if l2[i] > MAX1:
				MAX1 = l2[i]
				max_index = i
		MAX1 = max(l2)
		if MAX1 == 0:
			print('YES')
			continue
		s = m.log(MAX1) / m.log(k)
		s = round(s, 1)
		s = m.floor(s)
		ks = m.pow(k, s)
		ks = int(ks)
		if ks > l2[max_index]:
			ks = ks // k
		l2[max_index] = l2[max_index] - ks
		ks = ks // k
		while ks > 0:
			MAX1 = l2[0]
			max_index = 0
			for i in range(0, len(l2)):
				if l2[i] > ks:
					l2[i] = l2[i] - ks
					ks = ks // k
					flag = True
				elif l2[i] == ks:
					l2[i] = 0
					ks = ks // k
					flag = True
			if flag == False:
				ks = ks // k
			else:
				flag = False
		x = max(l2)
		y = min(l2)
		if x == y and x == 0:
			print('YES')
		else:
			print('NO')
f3()


def solution():
	from sys import stdout, stdin
	(_input, _print) = (stdin.readline, stdout.write)
	(_range, _int, _list) = (range, int, list)
	for _ in _range(_int(_input())):
		(n, k) = [_int(i) for i in _input().split()]
		degrees = [1]
		counter = 1
		while degrees[-1] < 10 ** 16:
			degrees.append(k ** counter)
			counter += 1
		counter -= 1
		arr = [_int(i) for i in _input().split()]
		flag = True
		for i in arr:
			temp = counter
			current = i
			while temp >= 0:
				if current >= degrees[temp] > 0:
					current -= degrees[temp]
					degrees[temp] = 0
				temp -= 1
			else:
				if current > 0:
					flag = False
		if flag:
			_print('YES\n')
		else:
			_print('NO\n')
solution()


import os
import sys
from io import BytesIO, IOBase
from math import log

def solution(n, k, arr):
	v_arr = [0] * n
	powers = set()
	while True:
		for i in range(n):
			if arr[i] > 0:
				exp = int(log(arr[i]) / log(k))
				exp -= 1
				if exp < 0:
					exp = 0
				while k ** (exp + 1) <= arr[i]:
					exp += 1
				if exp in powers:
					write('NO')
					return
				powers.add(exp)
				arr[i] -= k ** exp
		if arr == v_arr:
			write('YES')
			return

def main():
	for _ in range(r_int()):
		(n, k) = r_array()
		arr = r_array()
		solution(n, k, arr)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def p_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


for w in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	l = [[] for i in range(n)]
	d = {}
	for i in range(n):
		j = 0
		while j <= 100:
			if pow(k, j) <= a[i]:
				if a[i] % pow(k, j) == 0 and a[i] % pow(k, j + 1) != 0:
					l[i].append(j)
					a[i] -= pow(k, j)
			else:
				break
			j += 1
	c = 0
	for i in range(n):
		if a[i] != 0:
			c = 1
			break
		else:
			for j in range(len(l[i])):
				if l[i][j] not in d:
					d[l[i][j]] = 1
				else:
					c = 1
					break
	if c == 1:
		print('NO')
	else:
		print('YES')


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(n, k) = M()
	l = L()
	w = 0
	d = defaultdict(int)
	ans = [0] * 1000
	for i in range(n):
		x = l[i]
		r = []
		while x != 0:
			if x % k > 1:
				w = 1
				break
			r.append(x % k)
			x //= k
		for j in range(len(r)):
			ans[j] += r[j]
			if ans[j] > 1:
				w = 1
				break
	if w == 0:
		print('YES')
	else:
		print('NO')


tc = int(input())

def shucks(a, k):
	sum = 0
	for i in a:
		sum += i % k
	return sum
notded = 1
for _ in range(tc):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	while notded:
		if not any(a):
			print('YES')
			break
		if shucks(a, k) > 1:
			print('NO')
			break
		a = [i // k for i in a]


def check(s):
	while s > 0:
		c = maxPower(s)
		if c != -1:
			s = s - c
		else:
			return -1
	if s == 0:
		return 1

def maxPower(s):
	i = 1
	t = 0
	while i <= s:
		i *= k
		t += 1
	t -= 1
	i = i // k
	powers[t] += 1
	if powers[t] > 1:
		return -1
	return i
t = int(input())
for i in range(t):
	powers = [0] * 100
	flag = 1
	(size, k) = map(int, input().split())
	numbers = input().split()
	for j in range(size):
		if check(int(numbers[j])) == -1:
			print('NO')
			flag = 0
			break
	if flag == 1:
		print('YES')


def ms(a, k):
	i = 0
	while k ** i <= a:
		i += 1
	return i - 1
kl = int(input())
for l in range(kl):
	(n, k) = [int(i) for i in input().split()]
	pr = 0
	A = set()
	for i in input().split():
		r = int(i)
		if r == 0:
			continue
		if pr:
			continue
		while r != 0:
			t = ms(r, k)
			if t in A:
				pr = 1
				break
			else:
				A.add(t)
				r = r - k ** t
	if pr:
		print('NO')
	else:
		print('YES')


from math import *
mod = 1000000007
inf = 10000000000000000

def binpow(a, b):
	global mod
	if b == 1:
		return a % mod
	u = binpow(a, b // 2)
	if b % 2 == 0:
		return u * u % mod
	else:
		return u * u * a % mod

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
temp = [0] * 500
used = [0] * 500

def bs(low, high, target):
	if low == high:
		return low
	elif low + 1 == high:
		if temp[high] > target:
			return low
		else:
			return high
	else:
		mid = (low + high) // 2
		if temp[mid] == target:
			return mid
		elif temp[mid] > target:
			return bs(low, mid - 1, target)
		else:
			return bs(mid, high, target)
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	for i in range(300):
		used[i] = 0
	temp[0] = 1
	counter = 1
	while temp[counter - 1] < pow(10, 20):
		temp[counter] = temp[counter - 1] * k
		counter += 1
	arr = [int(i) for i in input().split()]
	b = True
	for a in arr:
		while a > 0:
			g = bs(0, counter - 2, a)
			if used[g] == 1:
				b = False
				break
			else:
				a -= temp[g]
				used[g] = 1
		if not b:
			break
	if not b:
		print('NO')
	else:
		print('YES')


from math import *
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	powers = []
	flag = 0
	limit = max(a)
	for i in range(54):
		powers.append(k ** i)
		if k ** i > limit:
			end = i
			break
	for i in range(len(powers) - 1, -1, -1):
		for j in range(len(a)):
			if a[j] >= powers[i]:
				a[j] -= powers[i]
				break
	for i in a:
		if i > 0:
			flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


import math
import sys

def getNbaseK(n, k):
	nl = int(math.log(n) // math.log(k))
	if n // k ** nl >= k:
		nl += 1
	a = [0] * (nl + 1)
	i = 0
	while n:
		kp = k ** (nl - i)
		a[i] = n // kp
		n %= kp
		i += 1
	return a
input = sys.stdin.readline
for ti in range(int(input())):
	(n, k) = [int(x) for x in input().strip().split()]
	a = [int(x) for x in input().strip().split()]
	pu = [0] * 100
	for ai in a:
		if not ai:
			continue
		ab = getNbaseK(ai, k)
		for i in range(len(ab) - 1, -1, -1):
			pu[len(ab) - i - 1] += ab[i]
	for pui in pu:
		if pui > 1:
			print('NO')
			break
	else:
		print('YES')


import math
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	j = 0
	d = {}
	b = 0
	while j < n:
		if l[j] == 0:
			j += 1
			continue
		c = int(math.log(l[j], k))
		if l[j] - k ** (c + 1) >= 0:
			c += 1
		if l[j] - k ** c < 0:
			c -= 1
		l[j] -= k ** c
		if c in d:
			print('NO')
			b = 1
			break
		else:
			d[c] = 1
		if l[j] == 0:
			j += 1
	if b == 0:
		print('YES')


def notallzero(arr):
	for i in range(len(arr)):
		if arr[i] != 0:
			return 1
	return 0

def ispossible(arr, k):
	while notallzero(arr):
		count = 0
		for i in range(len(arr)):
			if arr[i] % k == 1:
				count += 1
				arr[i] = arr[i] // k
			elif arr[i] % k != 0:
				return 0
			else:
				arr[i] = arr[i] // k
			if count > 1:
				return 0
	return 1
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	a = input().split()
	ai = [int(i) for i in a]
	if ispossible(ai, k):
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	a = input().split()
	a = [int(x) for x in a]
	b = [0 for j in range(60)]
	flag = True
	for x in a:
		p = 1
		j = 0
		while p <= x:
			p *= k
			j += 1
		p //= k
		j -= 1
		tmp = [0 for j in range(60)]
		while x > 0 and p >= 1:
			if x >= p:
				x -= p
				tmp[j] = 1
			p //= k
			j -= 1
		if x != 0:
			flag = False
			break
		for j in range(60):
			b[j] += tmp[j]
			if b[j] > 1:
				flag = False
				break
		if not flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys
import math
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a = sorted(a)
	up = math.ceil(math.log(a[-1]) / math.log(k)) if a[-1] > 0 else 0
	while up >= 0:
		cur = k ** up
		if cur <= a[-1]:
			a[-1] -= cur
			a = sorted(a)
		up -= 1
	sys.stdout.write('YES\n' if sum(a) == 0 else 'NO\n')


R = lambda : map(int, input().split())
t = int(input())

def check(a, k):
	ans = []
	power = 0
	while a > 0:
		if a % k != 0 and a % k != 1:
			return [-1]
		if a % k == 1:
			ans.append(power)
		power += 1
		a = a // k
	return ans

def check_array(a, k):
	d = {0: 0}
	for el in a:
		temp = check(el, k)
		for power in temp:
			if power not in d:
				d[power] = 1
			else:
				d[power] += 1
	if max(d.values()) > 1 or -1 in d.keys():
		return 'NO'
	else:
		return 'YES'
for _ in range(t):
	(n, k) = R()
	a = list(R())
	print(check_array(a, k))


(t,) = map(int, input().split())
for b in [0] * t:
	(n, k) = map(int, input().split())
	a = (*map(int, input().split()),)
	r = 0
	s = 1
	while s:
		z = sum(a)
		a = [x // k for x in a]
		r |= s > k * z + 1
		s = z
	print('YNEOS'[r::2])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	while any(a):
		ans |= [x % k for x in a if x % k] > [1]
		a = [x // k for x in a]
	print('YNEOS'[ans::2])


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	(n, k) = get_ints()
	arr = get_list()
	ans = [0] * 65
	for i in arr:
		for j in range(64):
			if i % k:
				ans[j] += i % k
			i = i // k
	if max(ans) > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0 for i in range(58)]
	m = True
	for i in a:
		c = 0
		while i != 0:
			h = i // k
			ost = i - h * k
			if ost == 0 or (b[c] == 0 and ost == 1):
				b[c] = max(b[c], ost)
				i = h
			else:
				m = False
				break
			c += 1
	if m:
		print('YES')
	else:
		print('NO')


import os, sys
if os.path.exists('inp.txt'):
	sys.stdin = open('inp.txt', 'r')

def _():
	return sys.stdin.readline()

def __():
	return sys.stdin.readline().split()
maxn = 100005
t = int(_())
for id in range(t):
	ok = 1
	(n, k) = map(int, __())
	dd = [0 for i in range(67)]
	a = list(map(int, __()))
	for i in range(n):
		res = 0
		cur = 1
		x = a[i]
		while x:
			while int(x / cur) % k == 0:
				res += 1
				cur *= k
			dd[res] += 1
			x -= cur
			if x % k != 0:
				ok = 0
				break
		if not ok:
			break
	for i in range(65):
		if dd[i] >= 2:
			ok = 0
			break
	print('NO' if not ok else 'YES')


import os, sys, bisect, copy, math
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())

def deconstruct(aNum, aBase):
	primeComps = []
	num = aNum
	while num >= 1:
		index = ilog(num, aBase)
		num = num - aBase ** index
		primeComps.append(int(index))
	return primeComps

def ilog(aNum, aBase):
	count = 0
	temp = aNum
	while temp >= aBase:
		count = count + 1
		temp = temp / aBase
	return count
for _ in range(int(input())):
	(n, k) = mapi()
	a = list(mapi())
	v = [0] * n
	check = []
	a.sort()
	for i in range(n):
		if a[i] != 0:
			a = a[i:]
			break
	if a.count(0) == len(a):
		print('YES')
		continue
	if len(set(a)) != len(a):
		print('NO')
		continue
	for i in a:
		tmp = deconstruct(i, k)
		check += tmp
	if len(set(check)) == len(check):
		print('YES')
	else:
		print('NO')


import math
T = int(input())
for case in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if max(a) != 0:
		i = int(math.log(max(a), k))
		if math.log(max(a), k) % 1 > 0.99:
			i += 1
		while i >= 0:
			if max(a) - k ** i >= 0:
				a[a.index(max(a))] = max(a) - k ** i
			i -= 1
	if sum(a) == 0:
		print('YES')
	else:
		print('NO')


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(n, k) = invr()
	a = inlt()
	for i in range(60, -1, -1):
		for j in range(n):
			if a[j] >= k ** i:
				a[j] = a[j] - k ** i
				break
	if len(set(a)) == 1 and a[0] == 0:
		print('YES')
	else:
		print('NO')


from math import inf
t = int(input())
for q in range(t):
	(n, k) = [int(i) for i in input().split()]
	L = [int(i) for i in input().split()]
	F = [0] * 60
	for i in L:
		num = i
		step = 0
		while num:
			F[step] += num % k
			num //= k
			step += 1
	flag = True
	for i in F:
		if i > 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	possible = True
	used = set()
	for val in a:
		shift = 0
		while val > 0:
			(val, rem) = divmod(val, k)
			if rem > 1:
				possible = False
				break
			elif rem == 1:
				if shift in used:
					possible = False
					break
				else:
					used.add(shift)
			shift += 1
		if not possible:
			break
	if possible:
		print('YES')
	else:
		print('NO')


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, k) = li()
	l = sorted(li())
	remainingset = set()
	for i in range(61):
		remainingset.add(k ** i)
	remainingset = sorted(list(remainingset))
	notpossible = 0
	for (ind, i) in enumerate(l):
		if not i:
			continue
		for j in list(remainingset)[::-1]:
			if j <= l[ind]:
				l[ind] -= j
				remainingset.remove(j)
		remainingset.sort()
		if l[ind]:
			notpossible = 1
			break
	if notpossible:
		print('NO')
		continue
	else:
		print('YES')


from math import *
import sys, random

def nextInt():
	return int(input())

def nextStrs():
	return input().split()

def nextInts():
	return list(map(int, nextStrs()))

def main():
	t = nextInt()
	while t > 0:
		(n, k) = nextInts()
		arr = nextInts()
		cnt = [0] * 100
		for i in arr:
			pw = 0
			while i > 0:
				cnt[pw] += i % k
				i //= k
				pw += 1
		ok = True
		for i in range(100):
			if cnt[i] > 1:
				ok = False
				break
		print('YES' if ok else 'NO')
		t -= 1
exit(main())


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	b = [0] * 65
	for num in l:
		for i in range(64):
			if num % k:
				b[i] += num % k
			num = num // k
	if max(b) > 1:
		print('NO')
	else:
		print('YES')


def fct(x, m):
	ind = 1
	p = 1
	while x != 0:
		if x % m != 0:
			x -= 1
			if x % m != 0:
				return False
			elif ind - 1 in s:
				return False
			else:
				s.add(ind - 1)
		else:
			x = x // m
			ind += 1
	return True
t = int(input())
for _ in range(t):
	ch1 = input()
	ch2 = input()
	L1 = [int(i) for i in ch1.split()]
	L2 = [int(i) for i in ch2.split()]
	x = []
	s = set()
	for i in range(L1[0]):
		x.append(fct(L2[i], L1[1]))
	if all(x):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	p = [0] * 100
	f = 0
	for i in l:
		m = 0
		while i:
			p[m] += i % k
			i //= k
			if p[m] > 1:
				f = 1
				break
			m += 1
	if f:
		print('NO')
	else:
		print('YES')


t = int(input().strip())
kmax = 10 ** 16 + 10

def find_possible(num, k, power_array):
	start = 1
	power = 0
	if num == 1:
		power_array[0] += 1
		return
	while True:
		result = start * k
		if result > num:
			break
		else:
			start = result
			power += 1
			if start == num:
				power_array[power] += 1
				return
	high = power
	while True:
		result = num
		rep = 0
		for i in range(0, k):
			if result - start == 0:
				rep += 1
				result = 0
				break
			elif result - start < 0:
				break
			result -= start
			rep += 1
		if result == 0:
			for i in range(rep):
				power_array[power] += 1
			return high
		if rep > 0:
			for i in range(rep):
				power_array[power] += 1
			power -= 1
			start = start // k
			num = result
		else:
			power -= 1
			start = start // k
for _ in range(t):
	power_array = [0 for i in range(100)]
	(n, k) = map(int, input().strip().split())
	nums = [int(i) for i in input().strip().split()]
	nums.sort()
	has = True
	cur_index = 0
	while cur_index < n:
		if nums[cur_index] == 0:
			cur_index += 1
		else:
			result = find_possible(nums[cur_index], k, power_array)
			cur_index += 1
	for i in power_array:
		if i >= 2:
			has = False
			break
	if has:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	cnt = [0] * 64
	flag = 0
	for i in a:
		x = i
		p = 0
		while x:
			if x % k > 1:
				print('NO')
				flag = 1
				break
			cnt[p] += x % k
			p += 1
			x //= k
		if flag:
			break
	else:
		if any((i > 1 for i in cnt)):
			print('NO')
		else:
			print('YES')


import sys
input = sys.stdin.readline

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n, k) = I()
	a = I()
	d = dd(int)
	ans = 'YES'
	for i in a:
		x = i
		cur = []
		p = 0
		while x > 0:
			m = x % k
			if m:
				d[p] += 1
				if d[p] == 2 or m > 1:
					ans = 'NO'
			x = x // k
			p += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	sm = sum(a)
	flag = True
	divs = k
	d = dict()
	for i in a:
		sm = i
		count = 0
		while sm:
			if sm % divs != 0 and sm % divs != 1:
				flag = False
			elif sm % divs == 1:
				if count not in d:
					d[count] = 1
				else:
					d[count] += 1
			sm //= divs
			count += 1
	for i in d:
		if d[i] > 1:
			flag = False
	print('YES') if flag else print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = []
	for i in range(n):
		cur = []
		x = a[i]
		if x == 0:
			cur = [0]
		while x:
			cur.append(x % k)
			x //= k
		s += [cur]
	cnt = [0] * 100
	for i in s:
		for j in range(len(i)):
			cnt[j] += i[j]
	fl = 1
	for i in cnt:
		if i > 1:
			fl = 0
	if fl:
		print('Yes')
	else:
		print('No')


t = int(input())
fi = float('inf')
bgnm = 10 ** 16
max_pow = 56
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = sum(arr)
	pows = [k ** i for i in range(max_pow + 1, -1, -1)]
	flag = False
	for thing in arr:
		for (num, p) in enumerate(pows):
			if p <= thing:
				thing -= p
				pows[num] = fi
		if thing != 0:
			print('NO')
			flag = True
			break
	else:
		print('YES')


t = int(input())
import heapq as hq
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	heap = []
	hq.heapify(heap)
	flag = 0
	for num in arr:
		hq.heappush(heap, -num)
	max_n = 1
	s = 0
	while max_n < 10 ** 16:
		max_n *= k
		s += 1
	while max_n > 0 and heap:
		nums = -hq.heappop(heap)
		if nums >= max_n:
			nums -= max_n
		if nums > 0:
			hq.heappush(heap, -nums)
		if heap:
			secn = -hq.heappop(heap)
			if secn >= max_n:
				flag = 1
				break
			elif secn > 0:
				hq.heappush(heap, -secn)
		s -= 1
		max_n = k ** s
	if flag == 0:
		print('YES')
	else:
		print('NO')


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	a = (*R(),)
	r = 'YES'
	while any(a):
		if [x % k for x in a if x % k] > [1]:
			r = 'NO'
		a = [x // k for x in a]
	print(r)


import os
import sys
from io import BytesIO, IOBase

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(n, k) = lin()
		a = lin()
		ch = [0] * 60
		for i in a:
			x = i
			ch1 = 0
			while x:
				ch[ch1] += x % k
				x //= k
				ch1 += 1
		print('YES' if max(ch) <= 1 else 'NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mark = [False] * 1000
	count = 0
	for j in range(n):
		sm = 0
		st = 0
		if a[j] != 0:
			while k ** st <= a[j]:
				st += 1
			st -= 1
			if not mark[st]:
				for l in range(st, -1, -1):
					if sm + k ** l <= a[j] and (not mark[l]):
						sm += k ** l
						mark[l] = True
					if sm == a[j]:
						count += 1
						break
			else:
				count = 0
				break
		else:
			count += 1
	if count == n:
		print('YES')
	else:
		print('NO')


def rec(a, k):
	now = 1
	i = 0
	while now * k <= a:
		now *= k
		i += 1
	if i in s:
		return 0
	elif now == a:
		s.add(i)
		return 1
	else:
		s.add(i)
		return rec(a - now, k)
q = int(input())
for i in range(q):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	s = set()
	for i in range(len(a)):
		if a[i] == 0:
			continue
		if not rec(a[i], k):
			print('NO')
			break
	else:
		print('YES')


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, k) = RI()
	a = RI()
	arr = []
	outflag = True
	for i in a:
		temp = i
		bit = []
		flag = True
		while temp > 0:
			temp1 = temp % k
			if temp1 != 0 and temp1 != 1:
				flag = not flag
				break
			bit.append(temp1)
			temp = temp // k
		if not flag:
			outflag = not outflag
			break
		arr.append(bit)
	if outflag == False:
		print('NO')
	else:
		flag = True
		xor = [0] * 64
		maxlen = -1
		for i in arr:
			maxlen = max(maxlen, len(i))
			for j in range(len(i)):
				xor[j] ^= i[j]
				if i[j] == 1 and xor[j] == 0:
					flag = not flag
					break
			if not flag:
				break
		if flag:
			print('YES')
		else:
			print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		c = collections.defaultdict(int)
		for t in a:
			i = 0
			while t > 0:
				c[i] += t % k
				t //= k
				i += 1
		rr.append(YES(all((t < 2 for t in c.values()))))
	return JA(rr, '\n')
print(main())


from sys import stdin
from collections import defaultdict

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))

def power(n, k):
	i = 0
	while n % k == 0:
		n //= k
		i += 1
	return i
t = iinput()
while t:
	t -= 1
	(n, k) = minput()
	a = linput()
	v = [0] * n
	ans = 'YES'
	if a == v:
		print(ans)
	else:
		a.sort()
		c = defaultdict(int)
		for j in range(n):
			if a[j] == 1:
				c[0] += 1
				if c[0] > 1:
					ans = 'NO'
					break
			elif a[j] > 1:
				while True:
					p = power(a[j], k)
					a[j] = a[j] - k ** p
					if 1 < a[j] < k:
						ans = 'NO'
						break
					c[p] += 1
					if c[p] > 1:
						ans = 'NO'
						break
					if a[j] == 0:
						break
				if ans == 'NO':
					break
		print(ans)


def func(val, k):
	cnt = 0
	while True:
		if val % k == 0:
			cnt += 1
			val = val // k
		else:
			break
	return cnt
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	f = 0
	d = {}
	temp = arr[:]
	while True:
		for i in range(n):
			if arr[i] != 0:
				val = func(arr[i], k)
				if val not in d:
					d[val] = 1
					arr[i] -= pow(k, val)
				else:
					f = 1
					break
		if f == 1 or arr == temp:
			break
		else:
			temp = arr[:]
	ans = [0 for i in range(n)]
	if arr == ans:
		print('YES')
	else:
		print('NO')


from sys import stdin
from collections import Counter
T = int(input())
for _ in range(T):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	count = 0
	for i in range(len(a)):
		if a[i] % k == 1:
			a[i] -= 1
			count += 1
	if count > 1:
		print('NO')
		continue
	zz = False
	x = Counter()
	y = Counter()
	while set(a) != {0}:
		for i in range(len(a)):
			if a[i] == 0:
				continue
			if a[i] % k != 0:
				print('NO')
				zz = True
				break
			else:
				e = 0
				while True:
					if a[i] % k ** e == 0:
						e += 1
					else:
						break
				y[e - 1 + x[i]] += 1
				if y[e - 1 + x[i]] > 1:
					print('NO')
					zz = True
					break
				a[i] = a[i] // k ** (e - 1) - 1
				x[i] += e - 1
		if zz:
			break
	if zz:
		continue
	else:
		print('YES')


def kbins(v, k):
	c = []
	while v:
		c.append(v % k)
		v //= k
	p = []
	j = 0
	bl = True
	for i in c:
		if i == 1:
			p.append(j)
		elif i > 1:
			bl = False
		j += 1
	return (p, bl)
cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = {}
	f = 0
	for i in a:
		(b, bl) = kbins(i, k)
		if bl:
			for j in b:
				if j in d:
					f = 1
					break
				else:
					d[j] = True
		else:
			f = 1
		if f == 1:
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


import math
from bisect import bisect_left, bisect_right
from sys import stdin, stdout
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	arr = []
	for i in range(55):
		arr.append(k ** i)
	soln = []
	arr.reverse()
	solns = []
	for i in range(len(ls)):
		for j in range(len(arr)):
			if int(ls[i] // arr[j] > 0) == 1:
				ls[i] -= arr[j]
				solns.append(len(arr) - j - 1)
	if len(solns) == len(set(solns)):
		for i in ls:
			if i > 0:
				print('NO\n')
				break
		else:
			print('YES\n')
	else:
		print('NO\n')


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	Max = max(a)
	Count = True
	x = True
	while x == True:
		value = Max ** (1 / Count)
		if value <= k:
			break
		Count = Count + 1
	for i in range(Count, -1, -1):
		value = k ** i
		for ii in range(n):
			if a[ii] >= value:
				a[ii] = a[ii] - value
				break
	Max = max(a)
	if Max > 0:
		print('NO')
	else:
		print('YES')


for _ in range(0, int(input())):
	(n, m) = input().split()
	used = []
	val = []
	bnd = 10000000000000000
	nw = 1
	while int(nw) <= int(bnd):
		val.append(nw)
		used.append(0)
		nw *= int(m)
	val.reverse()
	can = 1
	a = list(map(int, input().split()))
	for j in range(0, int(n)):
		x = a[j]
		for i in range(0, len(val)):
			if x >= val[i] and used[i] == 0:
				x -= val[i]
				used[i] = 1
		if x > 0:
			can = 0
	if can == 1:
		print('YES')
	else:
		print('NO')


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	arr = l()
	arr.sort()
	used = set()
	result = True
	for i in range(n):
		temp = 54
		while temp >= 0:
			if arr[i] == 0:
				break
			if int(pow(k, temp)) <= arr[i]:
				if temp not in used:
					arr[i] -= int(pow(k, temp))
					used.add(temp)
			temp -= 1
		if arr[i] != 0:
			result = False
	if result:
		out('YES\n')
	else:
		out('NO\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	s = set()
	f = 0
	for i in range(n):
		j = 66
		while a[i] > 0:
			while j >= 0 and a[i] < k ** j:
				j -= 1
			if a[i] >= k ** j:
				if j in s:
					f = 1
					break
				a[i] -= k ** j
				s.add(j)
		if f == 1:
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans

def c(n, k):
	i = 64
	while i >= 0:
		if n % k ** i == 0:
			return i
		i -= 1
	return -1
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	a = [0] * n
	if ar == a:
		print('YES')
	else:
		ans = 'YES'
		d = [0] * 65
		for i in range(n):
			nm = ar[i]
			while nm > 0:
				if nm % k == 0:
					t = c(nm, k)
					if d[t] == 1 or t == -1:
						ans = 'NO'
						break
					else:
						nm -= k ** t
						d[t] = 1
				elif d[0] == 1:
					ans = 'NO'
					break
				else:
					d[0] = 1
					nm -= 1
		print(ans)


def check(i, k):
	arr = []
	p = 0
	while i > 0:
		rem = i % k
		i = i // k
		if rem > 1:
			return -1
		else:
			if rem == 1:
				arr.append(p)
			p += 1
	return arr
for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	sets = [set() for i in range(n)]
	ans = 1
	for i in range(len(arr)):
		res = check(arr[i], k)
		if res == -1:
			ans = -1
			break
		else:
			sets[i] = set(res)
	if ans == -1:
		print('NO')
	else:
		for i in range(len(sets)):
			for j in range(len(sets)):
				if i != j and len(sets[i] & sets[j]) > 0:
					ans = -1
					break
			if ans == -1:
				break
		if ans == -1:
			print('NO')
		else:
			print('YES')


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())

def conv(x, k):
	s = ''
	while x:
		t = x % k
		if t > 1:
			s = 0
			break
		else:
			s = str(t) + s
		x //= k
	return s
for i in range(int(data())):
	(n, k) = mdata()
	A = list(mdata())
	t = 1
	flag = True
	l = [0] * 60
	for i in A:
		a = conv(i, k)
		if a == 0:
			flag = False
			break
		for i in range(len(a)):
			if a[i] == '1':
				l[len(a) - i - 1] += 1
	for i in l:
		if i > 1:
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


import sys
import math
input = sys.stdin.readline

def conv_strLs2intLs(line):
	a_list = line.split()
	map_object = map(int, a_list)
	list_of_integers = list(map_object)
	return list_of_integers

def nu_bgst_power(nu, base):
	pow = math.log(nu, base)
	ctmp = math.ceil(pow)
	ftmp = math.floor(pow)
	pow = ctmp if ctmp - pow < 1e-13 else ftmp
	nu2 = int(math.pow(base, pow))
	if nu2 - nu > 0:
		return pow - 1
	return pow
count = int(input())
for line in range(count):
	content1 = input().split()
	n = int(content1[0])
	k = int(content1[1])
	array = input().split()
	result = 'YES'
	usedIndexes = set()
	for nu in array:
		newnu = int(nu)
		while newnu != 0:
			index = nu_bgst_power(newnu, k)
			if index in usedIndexes:
				result = 'NO'
				break
			usedIndexes.add(index)
			newnu -= k ** index
		if result == 'NO':
			break
	print(result)


import math
T = int(input())

def tobasek(n, k):
	base = []
	while n > 0:
		base.append(n % k)
		n //= k
	return base
for t in range(T):
	(n, k) = list(map(int, input().split()))
	target_vector = list(map(int, input().split()))
	matrix = list(map(lambda x: tobasek(x, k), target_vector))
	dic = {}
	for row in matrix:
		for i in range(len(row)):
			if i not in dic:
				dic[i] = 0
			dic[i] += row[i]
	possible = True
	for val in dic.values():
		if val > 1:
			possible = False
	if possible:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	(n, k) = read()
	v = [0] * n
	a = get_list()
	if a == v:
		print('YES')
		return
	mp = {}
	for j in range(60, -1, -1):
		for i in range(n):
			if a[i] >= k ** j:
				a[i] -= k ** j
				break
	if a == v:
		print('YES')
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


from math import log2

def intlog(v, k):
	(l, r) = (-1, 100)
	while r - l > 1:
		m = (r + l) // 2
		if k ** m < v:
			l = m
		else:
			r = m
	return r

def solve(a, k):
	(n, m) = (len(a), intlog(max(a), k))
	used = [0] * (m + 1)
	for i in range(n):
		for j in range(m, -1, -1):
			x = pow(k, j)
			if x <= a[i]:
				if used[j]:
					return 'NO'
				used[j] = True
				a[i] -= x
	for v in a:
		if v != 0:
			return 'NO'
	return 'YES'

def main():
	t = int(input())
	for _ in range(t):
		(_, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort()
		print(solve(a, k))
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	if lst == [0] * n or k == 1:
		print('YES')
	else:
		p = 0
		while True:
			if k ** p > 10 ** 16:
				break
			else:
				p += 1
		p -= 1
		e = 0
		for h in range(p, -1, -1):
			lst1 = []
			ele = k ** h
			for j in range(n):
				if lst[j] >= ele:
					lst1.append(j)
			if len(lst1) > 1:
				e += 1
				break
			elif len(lst1) == 1:
				ind = lst1[0]
				lst[ind] -= ele
		if e == 0 and lst == [0] * n:
			print('YES')
		else:
			print('NO')


from math import *
import heapq
T = int(input())
for _ in range(T):
	(N, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if max(arr) == 0:
		print('YES')
	else:
		n = max(ceil(log(max(arr), k)), 1)
		for i in range(n, -1, -1):
			mul = int(pow(k, i))
			if arr[0] == 0:
				break
			elif arr[0] >= mul:
				arr[0] -= mul
				arr.sort(reverse=True)
		if arr[0] != 0:
			print('NO')
		else:
			print('YES')


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i

def sumdigits(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n //= 10
	return ans

def product(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def maxpower(n, k):
	cnt = 0
	while n > 1:
		cnt += 1
		n //= k
	return cnt
from math import *
from collections import deque
max_steps = 100005
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = maxpower(10000000000000000, k)
	f = 1
	while p >= -1 and f == 1:
		if a.count(0) == n:
			print('yes')
			break
		elif p == -1:
			f = 0
		for i in range(n):
			if a[i] < 0:
				f = 0
		ind = []
		for i in range(n):
			if a[i] >= k ** p:
				a[i] -= k ** p
				ind.append(i)
		if len(ind) > 1:
			f = 0
			break
		else:
			p -= 1
	if f == 0:
		print('no')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = True
	keep_going = True
	while ans and keep_going:
		keep_going = False
		cur_pow_used = False
		for i in range(n):
			if a[i] > 0:
				keep_going = True
			if a[i] % k == 1:
				if cur_pow_used:
					ans = False
					break
				else:
					cur_pow_used = True
			elif a[i] % k > 1:
				ans = False
				break
			else:
				pass
			a[i] = a[i] // k
	if ans:
		print('YES')
	else:
		print('NO')


def cs(n, k):
	a = n
	b = a
	C = []
	d = 0
	while a != 0:
		if a % k == 0:
			a = a // k
			d = d + 1
		else:
			C.append(d)
			a = b - k ** d
			d = 0
			b = a
	return C
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	a = A[n - 1]
	flag = 0
	for i in range(n - 1):
		if A[i] != 0 and A[i] == A[i - 1]:
			flag = 1
			break
	if A[n - 1] == 0:
		flag = 0
	if flag == 0 and A[n - 1] != 0:
		b = 1
		ty = 1
		while b < A[n - 1]:
			b = b * k
			ty = ty + 1
		D = [0 for i in range(ty + 1)]
		for i in range(n):
			E = cs(A[i], k)
			for j in E:
				if D[j] == 1:
					flag = 1
					break
				else:
					D[j] = 1
			if flag == 1:
				break
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = {}
	g = 0
	for i in l:
		x = i
		j = 0
		while x > 0:
			f = x % k
			x //= k
			if f > 1:
				g = 1
				break
			elif f:
				if a.get(j, 0) != 0:
					g = 1
					break
				a[j] = 1
			j += 1
		if g:
			break
	if g:
		print('NO')
	else:
		print('YES')


def sol():
	(x, y) = map(int, input().split())
	s = list(map(int, input().split()))
	vis = [0] * 100
	for n in s:
		t = 0
		d = n
		while d > 0:
			v = d % y
			if v > 1:
				print('NO')
				return
			vis[t] += v
			if vis[t] > 1:
				print('NO')
				return
			d //= y
			t += 1
	print('YES')
for n in range(int(input())):
	sol()


def rebase(x, b):
	bits = []
	one = True
	while x != 0:
		(q, r) = divmod(x, b)
		bits.append(r)
		if r not in [0, 1]:
			one = False
		x = q
	if not one:
		return (one, -1)
	has = 0
	for (i, b) in enumerate(bits):
		if b == 0:
			continue
		has |= 1 << i
	return (one, has)

def exclusive(arr):
	acc = arr[0]
	for e in arr[1:]:
		if acc & e != 0:
			return False
		acc |= e
	return True
for _ in range(int(input())):
	(_, k) = map(int, input().split())
	pows = []
	term = False
	for e in map(int, input().split()):
		(good, p) = rebase(e, k)
		if not good:
			term = True
			break
		pows.append(p)
	if term or not exclusive(pows):
		print('NO')
		continue
	print('YES')


def tellMeWhy(i, k, p):
	t = 0
	flag = 1
	while i > 0:
		if i % k > 1:
			flag = 0
			break
		if i % k == 1:
			if p.get(t, 0) == 0:
				p[t] = 1
			else:
				flag = 0
				break
		i = i // k
		t += 1
	return flag
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = {}
	flag = 1
	for i in a:
		if tellMeWhy(i, k, p) == 0:
			flag = 0
			break
	print('YES' if flag == 1 else 'NO')


def getPowerCombination(b):
	ans = []
	while b:
		for i in range(len(ks)):
			if ks[i] > b:
				i -= 1
				break
		if notTaken[i]:
			notTaken[i] = False
			ans.append(i)
			b -= ks[i]
		else:
			return False
	return True
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	ks = []
	x = 1
	while x <= max(a) * k:
		ks.append(x)
		x *= k
	notTaken = [True for __ in range(len(ks))]
	ok = True
	for b in a:
		if getPowerCombination(b) == False:
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')


def conv(x, k):
	s = ''
	while x != 0:
		if x % k == 0:
			s += '0'
		elif x % k == 1:
			s += str('1')
		else:
			return -1
		x = x // k
	s = s[::-1]
	return s
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 'YES'
	s = ''
	xor = []
	for i in a:
		if i == 0:
			s = '0'
		else:
			s = conv(i, k)
		if s == -1:
			ans = 'NO'
			break
		else:
			xor.append(int(s, 2))
	if ans == 'NO':
		print(ans)
	else:
		t = 0
		for i in range(len(xor)):
			if t ^ xor[i] == t + xor[i]:
				t = t + xor[i]
			else:
				ans = 'NO'
				break
		print(ans)


n = int(input())
for _ in range(n):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	possible = True
	s = set()
	for v in arr:
		power = 0
		while v != 0:
			mod = v % k
			if mod == 1:
				if power in s:
					possible = False
					break
				else:
					s.add(power)
			elif mod > 1:
				possible = False
				break
			power += 1
			v = v // k
		if not possible:
			break
	if possible:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()

	def f(num):
		ans = []
		i = 0
		while num > 0:
			if num % k == 1:
				ans.append(i)
			elif num % k > 1:
				return (ans, False)
			i += 1
			num = num // k
		return (ans, True)
	bits = []
	flag = 0
	for e in a:
		(x, z) = f(e)
		if z:
			bits.append(x)
		else:
			flag = 1
			break
	if flag == 1:
		print('NO')
		t -= 1
		continue
	flag = 0
	mem = set()
	for i in range(n):
		if a[i] == 0:
			continue
		for l in bits[i]:
			if l in mem:
				flag = 1
				break
			mem.add(l)
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


T = int(input())
for _ in range(T):
	used = set()
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	bad = False
	for e in a:
		pk = 1
		while pk <= e:
			pk *= k
		pk //= k
		while pk >= 1:
			if e >= pk:
				e -= pk
				if pk in used:
					bad = True
					break
				used.add(pk)
			pk = pk // k
		if e != 0:
			bad = True
			break
		if bad:
			break
	print('YES' if not bad else 'NO')


t = int(input())
for i in range(t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	req = input().split(' ')
	ind = []
	c = 0
	for j in range(n):
		req[j] = int(req[j])
		l = 0
		while req[j] >= k ** l:
			l += 1
		while l != -1:
			m = req[j] // k ** l
			if m != 0:
				if m == 1:
					ind.append(l)
				else:
					c += 1
					break
			req[j] = req[j] % k ** l
			l -= 1
	ind.sort()
	for o in range(len(ind) - 1):
		if ind[o] == ind[o + 1]:
			c += 1
			break
	if c:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	L = [0] * 100
	for i in A:
		l = 0
		while i > 0:
			L[l] += i % K
			i //= K
			l += 1
	c = max(L)
	print('NO' if c > 1 else 'YES')


from math import log

def f(n, x):
	a = [0, 1]
	b = []
	while True:
		s = n // x
		y = n % x
		b = b + [y]
		if s == 0:
			break
		n = s
	b.reverse()
	res = ''
	for i in b:
		try:
			res += str(a[i])
		except:
			return False
	return res

def solve():
	(n, k) = map(int, input().split())
	array = [x for x in list(map(int, input().split())) if x != 0]
	if len(set(array)) != len(array):
		print('NO')
		return
	maxLen = 0
	strings = []
	for a in array:
		curstring = f(a, k)
		if curstring == False:
			print('NO')
			return
		if len(curstring) > maxLen:
			maxLen = len(curstring)
		strings.append(curstring)
	for index in range(len(strings)):
		strings[index] = '0' * (maxLen - len(strings[index])) + strings[index]
	for i in range(maxLen):
		count = 0
		for s in strings:
			if s[i] == '1':
				count += 1
			if count == 2:
				print('NO')
				return
	print('YES')
for _ in range(int(input())):
	solve()


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		A = list(map(int, input().split()))
		used = [0] * 60
		ans = 'YES'
		for a in A:
			i = 0
			while a:
				if a % k == 1:
					if used[i] == 1:
						ans = 'NO'
					else:
						used[i] = 1
				elif a % k != 0:
					ans = 'NO'
				a //= k
				i += 1
		print(ans)
main()


t = int(input())
from math import log, ceil, floor

def solve(no, k, ans):
	global answer
	try:
		z = log(no, k)
		if k ** ceil(z) > no:
			if k ** (ceil(z) - 1) > no:
				z = ceil(z) - 2
			else:
				z = ceil(z) - 1
		else:
			z = ceil(z)
		z = int(z)
		if z in ans:
			answer = False
			return
		else:
			ans[int(z)] = 1
			solve(no - k ** int(z), k, ans)
	except:
		pass
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ans = {}
	answer = True
	for i in arr:
		solve(i, k, ans)
	if answer:
		print('YES')
	else:
		print('NO')


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def main():
	ans = ''
	for _ in range(ii()):
		(n, k) = mi()
		arr = li()
		d = defaultdict(int)
		flag = 0
		for i in arr:
			m = i
			if m != 0:
				x = int(math.log(m, k)) + 1
				while m > 0:
					if k ** x > m:
						x -= 1
					elif d[x] == 0:
						m -= k ** x
						d[x] += 1
					else:
						flag = 1
						break
			if flag:
				break
		if flag == 0:
			ans += 'YES\n'
		else:
			ans += 'NO\n'
	print(ans)
main()


from collections import *
from bisect import *

def sum_pow(r, n, m=None):
	return (1 - pow1(r, n + 1)) // (1 - r)

def pow1(x, base):
	sq = 1
	while base > 0:
		if base % 2:
			base -= 1
			sq = sq * x
		base //= 2
		x = x * x
	return sq
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 'YES'
	(a, visit, s) = (list(map(int, input().split())), defaultdict(int), [pow1(k, i) for i in range(59)])
	for j in range(n):
		for m in range(len(s) - 1, -1, -1):
			if a[j] - s[m] >= 0:
				if not visit[m]:
					visit[m] += 1
					a[j] -= s[m]
				else:
					ans = 'NO'
					break
		if a[j]:
			ans = 'NO'
		if ans == 'NO':
			break
	print(ans)


t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = 1
	arr = [0] * 101
	for i in a:
		tt = i
		p = 0
		while tt > 0:
			if tt % k == 1:
				if arr[p] != 0:
					b = 0
				arr[p] = 1
			elif tt % k != 0:
				b = 0
			p += 1
			tt //= k
	print('YES' if b else 'NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	al = list(map(int, input().split()))
	al2 = []
	for i in range(n):
		if al[i] != 0:
			al2.append(al[i])
	al = al2
	al.sort(reverse=True)
	n = len(al)
	if n == 0:
		print('YES')
		continue
	x = 1
	pl = []
	while x <= al[0]:
		pl.append(x)
		x = x * k
	i = 0
	while i < n:
		j = len(pl) - 1
		while j >= 0 and (pl[j] == 0 or pl[j] > al[i]):
			j -= 1
		if j < 0:
			break
		if al[i] > 0:
			al[i] -= pl[j]
			pl[j] = 0
		if al[i] == 0:
			i += 1
	if i == n:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	aa = [int(i) for i in input().split()]
	k1 = 1
	while k1 <= 10 ** 16:
		k1 *= k
	while k1 > 0:
		for i in range(0, n):
			if aa[i] >= k1:
				aa[i] -= k1
				break
		k1 //= k
	if sum(aa) == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin

def func(x, k):
	ans = []
	while x > 0:
		i = 0
		m = 1
		while m <= x:
			i += 1
			m = pow(k, i)
		ans.append(i - 1)
		x -= m // k
	if len(ans) == len(set(ans)):
		return (True, set(ans))
	return (False, {})
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	arr = sorted(list(map(int, stdin.readline().split())))
	cond = True
	s = set()
	for i in range(n):
		if arr[i] != 0:
			(val, l) = func(arr[i], k)
			if val == True:
				if len(s.intersection(l)) == 0:
					s = s.union(l)
				else:
					cond = False
					break
			else:
				cond = False
				break
	if cond == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	max_power = 1
	while max_power < max(a):
		max_power *= k
	while max_power > 0:
		for (key, v) in enumerate(a):
			if v >= max_power:
				a[key] -= max_power
				break
		max_power //= k
	print('YES' if max(a) == 0 else 'NO')


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	v = [0] * 100
	for item in a:
		i = 0
		while item:
			v[i] += item % k
			item //= k
			i += 1
	print('YES' if max(v) <= 1 else 'NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	lst = []
	flag = 0
	for i in arr:
		m = 1
		while i != 0:
			if i % k == 0:
				pass
			elif i % k == 1:
				if m in lst:
					print('NO')
					flag = 1
					break
				else:
					lst.append(m)
			else:
				print('NO')
				flag = 1
				break
			m *= k
			i //= k
		if flag == 1:
			break
	if flag == 0:
		print('YES')


import sys
from collections import defaultdict

def main():

	def reVal(num):
		if num >= 0 and num <= 9:
			return chr(num + ord('0'))
		else:
			return chr(num - 10 + ord('A'))

	def fromDeci(res, base, inputNum):
		while inputNum > 0:
			res += reVal(inputNum % base)
			inputNum = int(inputNum / base)
		res = res[::-1]
		return res

	def check(q):
		for i in q:
			if i != '1' and i != '0':
				return True
		return False

	def setans(ans, q):
		x = len(q)
		for i in range(x):
			if q[i] == '1':
				ans[x - i - 1] += 1
	for _ in range(int(sys.stdin.readline())):
		(n, k) = map(int, sys.stdin.readline().split())
		l = [int(y) for y in sys.stdin.readline().split()]
		ans = defaultdict(int)
		flag = 0
		for i in l:
			if i != 0:
				res = ''
				q = fromDeci(res, k, i)
				if check(q):
					flag = 1
					break
				setans(ans, q)
		for i in ans:
			if ans[i] != 1:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')
main()


from math import ceil, log

def solve():
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	m = ceil(log(max(L), K)) if max(L) != 0 else 0
	while m >= 0:
		larger = list(filter(lambda x: x >= K ** m, L))
		if len(larger) >= 2:
			print('NO')
			return
		elif len(larger) == 1:
			for (i, v) in enumerate(L):
				if v >= K ** m:
					L[i] -= K ** m
					break
		m -= 1
	if max(L) != 0:
		print('NO')
	else:
		print('YES')
T = int(input())
for _ in range(T):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = 1
	while x < 10 ** 16 + 1:
		x *= k
	while x:
		for i in range(n):
			if a[i] >= x:
				a[i] -= x
				break
		x //= k
	if sum(a) == 0:
		print('YES')
	else:
		print('NO')


def dec(a, k):
	res = []
	while a >= k:
		rest = a % k
		res.append(rest)
		a = a // k
		if rest > 1:
			return ([], False)
	if a > 1:
		return ([], False)
	res.append(a)
	return (res, True)
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ok = True
	m = 0
	r = {}
	ma = 0
	for i in a:
		if i == 0:
			continue
		(tmp, o) = dec(i, k)
		if o == False:
			ok = False
			break
		for (idx, kk) in enumerate(tmp):
			if kk == 1:
				if idx in r:
					ok = False
					break
				else:
					r[idx] = 1
	if ok:
		print('YES')
	else:
		print('NO')


def func(n):
	p = k
	q = 0
	while q < 56:
		an = n % k
		n = n // k
		if an > 1:
			return -1
		elif an > 0:
			x[q] += 1
		p *= k
		q += 1
	return 1
for _ in range(int(input())):
	(m, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	x = [0] * 60
	id = 0
	for i in a:
		if func(i) == -1:
			id = 1
			break
	if not id:
		for i in x:
			if i > 1:
				id = 1
				break
	if id:
		print('NO')
	else:
		print('YES')


from math import log
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = True
	mx = max(a)
	if mx == 0:
		print('YES')
		continue
	val = k ** round(log(mx, k))
	if val > mx:
		val //= k
	while val:
		flag = False
		for i in range(len(a)):
			if a[i] >= val:
				if flag or a[i] // val > 1:
					ans = False
					break
				else:
					a[i] %= val
				flag = True
		val //= k
	if ans:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	fl = True
	has = [0] * 64
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	for t in a:
		i = 0
		while fl and t:
			if t % k < 2:
				if t % k == 1:
					if has[i]:
						fl = False
					else:
						has[i] = 1
			else:
				fl = False
			i += 1
			t //= k
	if fl:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	cc = defaultdict(int)
	for u in ar:
		ix = 0
		while u:
			if u % k:
				cc[ix] += u % k
			u //= k
			ix += 1
	print('YES' if not cc or max(cc.values()) < 2 else 'NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [0] * 100
	for v in a:
		i = 0
		while v:
			b[i] += v % k
			v //= k
			i += 1
	print('YES' if max(b) <= 1 else 'NO')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, k) = inp()
	arr = list(inp())
	bit = [False] * 55
	ch = sum(arr)
	flag = True
	for i in arr:
		ch = i
		temp = []
		while ch > 0:
			rem = ch % k
			ch = ch // k
			if rem == 0 or rem == 1:
				temp.append(rem)
			else:
				flag = False
				break
		if flag:
			for i in range(len(temp)):
				if temp[i] == 1:
					if bit[i]:
						flag = False
						break
					else:
						bit[i] = True
		else:
			break
	if flag:
		ans = 'YES'
	else:
		ans = 'NO'
	out(ans)


def Adding_Powers(n, k, array):
	P = []
	for i in range(n):
		e = array[i]
		m = Max_Power(e, k)
		while array[i] > 0 and m >= 0:
			if array[i] >= k ** m:
				array[i] -= k ** m
				if P.count(m) == 1:
					return 'NO'
				P.append(m)
			m -= 1
	if max(array) > 0:
		return 'No'
	else:
		return 'Yes'

def Max_Power(M, k):
	m = 0
	while k ** m < M:
		m += 1
	if k ** m > M:
		m -= 1
	return m
for l in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	print(Adding_Powers(n, k, array))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def digits(n, b):
	out = []
	while n:
		(n, r) = divmod(n, b)
		out.append(r)
	return out[::-1]

def solve():
	(n, k) = rl()
	A = rl()
	used = set()
	for a in A:
		D = digits(a, k)
		for (i, d) in enumerate(D):
			if d not in [0, 1]:
				print('NO')
				return
			elif d == 0:
				continue
			p = len(D) - 1 - i
			if p in used:
				print('NO')
				return
			else:
				used.add(p)
	print('YES')
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


def binary_pow(k, x):
	if x == 1:
		return k
	if x == 0:
		return 1
	elif x % 2 == 0:
		return binary_pow(k, x // 2) * binary_pow(k, x // 2)
	else:
		return k * binary_pow(k, (x - 1) // 2) * binary_pow(k, (x - 1) // 2)

def func(x):
	global k
	left = 0
	right = 100
	while right - left > 1:
		mid = (left + right) // 2
		if binary_pow(k, mid) < x:
			left = mid
		else:
			right = mid
	ans = []
	for i in range(right, -1, -1):
		v = x // binary_pow(k, i)
		ans.append(v)
		x -= v * binary_pow(k, i)
	return ans[::-1]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	good = [0] * 200
	for i in range(n):
		x = func(a[i])
		for j in range(len(x)):
			good[j] += x[j]
	f = True
	for i in good:
		if i > 1:
			f = False
			break
	if f:
		print('YES')
	else:
		print('NO')


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	(n, k) = map(int, z().split())
	l = list(map(int, z().split()))
	d = [0] * 10001
	for i in range(n):
		x = l[i]
		c = 0
		while x > 0:
			d[c] += x % k
			c += 1
			x = x // k
	if max(d) > 1:
		print('No')
	else:
		print('yEs')


from sys import stdin

def factor(a, k):
	factor = []
	cur = 0
	while a != 0:
		if a % k == 0:
			a /= k
		elif a % k == 1:
			factor.append(cur)
			a = (a - 1) / k
		else:
			return -1
		cur += 1
	return factor
T = int(stdin.readline())
for i in range(T):
	(n, k) = list(map(int, stdin.readline().split(' ')))
	A = list(map(int, stdin.readline().split(' ')))
	state = 1
	dic = {}
	for item in A:
		if item == 0:
			continue
		else:
			fact = factor(item, k)
			if fact == -1:
				print('NO')
				state = -1
				break
			for index in fact:
				if index not in dic:
					dic[index] = 1
				else:
					print('NO')
					state = -1
					break
			if state == -1:
				break
	if state == 1:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	f = 1
	p = set()
	for i in range(n):
		if l[i] != 0:
			c = 0
			if l[i] != 1 and l[i] < k:
				f = 0
				break
			while l[i]:
				q = l[i] % k
				l[i] = l[i] // k
				if q == 1:
					if c not in p:
						p.add(c)
					else:
						f = 0
						break
				elif q != 0:
					f = 0
					break
				c += 1
	if f:
		print('YES')
	else:
		print('NO')


MAXN = int(1000000.0)

def solve():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	cnt = [0 for i in range(101)]
	for i in range(n):
		x = a[i]
		b = 0
		while x > 0:
			cnt[b] += x % k
			b += 1
			x //= k
	if max(cnt) > 1:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	solve()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	(n, k) = mi()
	a = sorted(li())
	b = []
	for i in a:
		if i:
			b.append(i)
	v = [0] * n
	if len(b) == 0:
		print('YES')
	elif len(set(b)) < n - a.count(0):
		print('NO')
	else:
		t = [0] * (int(math.log(b[-1], k)) + 1)
		for item in b:
			if item == 0:
				pass
			else:
				tt = item
				for i in range(int(math.log(item, k)) + 1):
					t[i] += tt % k
					tt //= k
		if max(t) > 1:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 'YES'
	po = 54
	while po >= 0 and sum(l):
		k = b ** po
		v = []
		for i in range(a - 1, -1, -1):
			if l[i] >= k:
				v.append(i)
		if len(v) > 1:
			ans = 'NO'
			break
		elif len(v) == 1:
			l[v[0]] -= k
		po -= 1
	if sum(l) > 0:
		ans = 'NO'
	print(ans)


import bisect
t = int(input())
for i in range(t):
	(size, k) = input().split(' ')
	elements = list(map(int, input().split(' ')))
	helper = []
	j = 0
	visited = {}
	while True:
		el = int(k) ** j
		helper.append(el)
		visited[el] = False
		if el > max(elements):
			break
		j += 1
	flag = 0
	for item in elements:
		while item > 0:
			ia = bisect.bisect_left(helper, item)
			if helper[ia] != item:
				index = ia - 1
			else:
				index = ia
			if index == -1 or visited[helper[index]]:
				print('NO')
				flag = 1
				break
			helper_value = helper[index]
			visited[helper_value] = True
			item -= helper_value
		if item < 0:
			print('NO')
			flag = 1
			break
		if flag == 1:
			break
	if flag == 0:
		print('YES')


def power(x, exponential):
	if exponential == 0:
		return 1
	t = power(x, exponential // 2)
	t = t * t
	if exponential % 2 == 1:
		t = t * x
	return t
test = int(input())
while test > 0:
	test -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = [0] * 54
	limit = 0
	x = 1
	while x <= 10000000000000000:
		x = x * k
		limit += 1
	limit -= 1
	check = True
	for i in a:
		x = i
		bit = limit
		while x > 0 and bit >= 0:
			if x >= power(k, bit):
				x -= power(k, bit)
				cnt[bit] += 1
			bit -= 1
		if x > 0:
			check = False
			break
	for i in range(limit + 1):
		if cnt[i] > 1:
			check = False
			break
	if check == True:
		print('YES')
	else:
		print('NO')


from bisect import bisect_right as br

def f(k, a):
	if a == [0] * len(a):
		return 'YES'
	power = [k ** i for i in range(0, 100)]
	s = sum(a)
	for i in a:
		while i:
			rr = br(power, i) - 1
			if rr < 0:
				return 'NO'
			i -= power[rr]
			power.pop(rr)
	return 'YES'
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	print(f(b, lst))


t = int(input())

def in_base(n, k):
	l = list()
	kk = 1
	if n == 0:
		l.append(0)
	while n >= 1:
		l.append(n % k)
		n //= k
	return l
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	bases = list()
	yes = True
	for i in range(len(a)):
		bases.append(in_base(a[i], k))
	for i in range(111):
		cnt = 0
		for b in bases:
			if i >= len(b):
				continue
			cnt += b[i]
		if cnt > 1:
			yes = False
			break
	if yes:
		print('YES')
	else:
		print('NO')


T = int(input())
while T:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ls = [0 for i in range(55)]
	power = [k ** (54 - i) for i in range(55)]
	flag = True
	for i in range(n):
		for j in range(55):
			if a[i] >= power[j]:
				a[i] -= power[j]
				ls[j] += 1
		if a[i]:
			flag = False
			break
	for i in range(55):
		if ls[i] > 1:
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')
	T -= 1


def is_normal(x, q, k, chisl):
	answer = chisl
	f = True
	w = 0
	while f and x > 0:
		f = False
		for i in range(1, q):
			st = k ** i
			if x % st == 0:
				kol = 0
				while x % st == 0:
					x //= st
					kol += 1
				x -= 1
				q -= i * kol
				answer.append(i * kol + w)
				w += i * kol
				f = True
				break
	if f:
		return answer
	return 'o'
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	Max = 0
	d = dict()
	flag = True
	for j in range(n):
		e = arr[j]
		ch = 0
		while e > 1:
			e //= k
			ch += 1
		Max = max(Max, ch + 1)
	for j in range(Max):
		d[j] = False
	for j in range(n):
		if arr[j] == 0:
			continue
		mass1 = is_normal(arr[j] - 1, Max, k, [0])
		mass2 = is_normal(arr[j], Max, k, [])
		if mass1 == 'o' and mass2 == 'o':
			flag = False
			break
		if mass1 != 'o':
			mass = mass1
		else:
			mass = mass2
		for l in mass:
			if d[l]:
				flag = False
				break
			d[l] = True
	if not flag:
		print('NO')
	else:
		print('YES')


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	v = list(map(int, input().split()))
	temp = v
	if v == [0] * n:
		print('YES')
	else:
		loplen = int(round(math.log(max(v)) / math.log(k)))
		if loplen == 0:
			loplen += 1
		pow_used = [0] * (loplen + 1)
		temp.sort()
		for i in range(n):
			if temp[i] != 0:
				for j in range(loplen + 1):
					if pow_used[j] != 1 and temp[i] % k ** j == 0 and (temp[i] % k ** (j + 1) != 0):
						temp[i] = temp[i] - k ** j
						pow_used[j] = 1
		if temp == [0] * n:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	hihi = [0] * 101
	check = 1
	for i in range(n):
		if arr[i] == 0:
			continue
		else:
			Tong = 0
			while arr[i] != 0:
				Buon = 0
				while arr[i] % k ** Buon == 0:
					Buon += 1
				Tong += Buon - 1
				if hihi[Tong] == 1:
					check = 0
					break
				else:
					hihi[Tong] = 1
				arr[i] = arr[i] // k ** (Buon - 1) - 1
	if check == 0:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for i in range(tc):
	(n, k) = iia()
	nums = [0]
	for i in range(55):
		if nums[-1] >= 10 ** 16:
			break
		nums.append(k ** i)
	arr = iia()
	powers = []
	for i in arr:
		if i > 0:
			cur = 0
			for j in range(55):
				if cur + nums[j] >= i:
					cur += nums[j]
					break
				cur += nums[j]
			temp = [j]
			for k in range(j)[::-1]:
				if cur - nums[k] >= i:
					cur -= nums[k]
				else:
					temp.append(k)
			if cur != i:
				print('NO')
				break
			powers.extend(temp)
	else:
		if len(powers) == len(set(powers)):
			print('YES')
		else:
			print('NO')


def degree_check(number):
	if number not in degrees:
		degrees[number] = 1
		return False
	else:
		return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	degrees = dict()
	state = False
	for num in array:
		if num < k:
			if num == 1:
				if degree_check(0):
					print('NO')
					state = True
			elif num != 0:
				print('NO')
				state = True
		else:
			degree = 0
			while num >= k:
				current = num % k
				if current == 1:
					if degree_check(degree):
						print('NO')
						state = True
						break
				elif current > 1:
					print('NO')
					state = True
					break
				num //= k
				degree += 1
				if num < k:
					if num == 1:
						if degree_check(degree):
							print('NO')
							state = True
							break
					else:
						print('NO')
						state = True
						break
		if state == True:
			break
	if state == False:
		print('YES')
	state = False


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
for _ in range(ii()):
	(n, k) = mi()
	a = li()
	c = [0] * 100
	for i in range(n):
		x = a[i]
		j = 0
		while x:
			c[j] += x % k
			j += 1
			x //= k
	f = 0
	for i in range(100):
		if c[i] > 1:
			f = 1
			print('NO')
			break
	if f == 0:
		print('YES')


def go():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ma = max(a)
	kp = 1
	while kp < ma:
		kp *= k
	u = set()
	for aa in a:
		if aa == 0:
			continue
		c = kp
		while aa > 0:
			while c > aa:
				c //= k
			if aa >= 2 * c or c in u:
				return 'NO'
			else:
				u.add(c)
				aa -= c
	return 'YES'
t = int(input())
ans = []
for _ in range(t):
	ans.append(go())
print('\n'.join(ans))


from sys import stdin

def to_ternary(n, x):
	l = []
	while n > 0:
		y = n % x
		if y > 1:
			l = []
			break
		l.append(y)
		n = n // x
	return l
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	z = [0] * 100
	r = 'YES'
	for i in range(n):
		if l[i] != 0:
			x = to_ternary(l[i], k)
			if x:
				for i in range(len(x)):
					z[i] += x[i]
					if z[i] > 1:
						r = 'NO'
						break
			else:
				r = 'NO'
				break
	print(r)


def getComponent(array, k):
	Set = set()
	for each in array:
		if each != 0:
			count = 0
			while each > 1:
				if each % k == 0:
					each = each // k
					count += 1
				elif count in Set:
					return 'NO'
				else:
					Set.add(count)
					each -= 1
			if count in Set:
				return 'NO'
			else:
				Set.add(count)
	return 'YES'
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	array = list(map(int, input().split()))
	print(getComponent(array, k))


t = int(input())
for y in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	if m == 1:
		print('YES')
		continue
	for i in range(n):
		j = 0
		while a[i]:
			val = a[i] % m
			if j not in d:
				d[j] = 0
			d[j] += val
			a[i] //= m
			j += 1
	f = 1
	for v in d.values():
		if v > 1:
			f = 0
	if f == 0:
		print('NO')
	else:
		print('YES')


import random
import sys
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	K = 1
	while K < 10 ** 16 + 1:
		K *= k
	kk = K
	while kk > 0:
		for j in range(n):
			if l[j] >= kk:
				l[j] -= kk
				break
		kk //= k
	if sum(l) == 0:
		print('YES')
	else:
		print('NO')


def bits(n, k):
	l = []
	step = 0
	while n > 0:
		digit = n % k
		if digit != 0:
			l.append(step)
		n = n // k
		step += 1
	return l

def expre(n, k):
	if n == 0 or n == 1:
		return True
	if n < k:
		return False
	x = 0
	m = n
	step = 1
	while n > 0:
		digit = n % k
		if digit != 0:
			x += step
		step *= k
		n = n // k
	return x == m
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	b = True
	steps = []
	for i in A:
		u = bits(i, k)
		b &= expre(i, k)
		steps += u
	if len(set(steps)) == len(steps) and b:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from math import *
t = int(input())

def bit(n, k):
	s = []
	while n > 0:
		p = n % k
		s.append(p)
		n //= k
	return s
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = []
	flag = 0
	for i in range(n):
		b.append(bit(a[i], k))
	d = [0 for i in range(70)]
	for i in range(n):
		for j in range(len(b[i])):
			if b[i][j] == 1:
				d[j] += 1
			elif b[i][j] > 1:
				flag = 1
				break
	if max(d) <= 1 and flag == 0:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
import collections
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

def MI():
	return map(int, input().split())

def S():
	return input()

def MS():
	return map(str, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def input():
	return sys.stdin.readline().rstrip()

def print_matrix(mat):
	for i in range(len(mat)):
		print(*mat[i])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def solve(T):
	(n, k) = MI()
	a = LI()
	MAX = 10 ** 16 + 1
	v = 1
	while v < MAX:
		v *= k
	while v > 0:
		for i in range(n):
			if a[i] >= v:
				a[i] -= v
				break
		v //= k
	if all([a[i] == 0 for i in range(n)]):
		print('YES')
	else:
		print('NO')

def main():
	T = I()
	for i in range(T):
		solve(T)
main()


n = int(input())
for _ in range(n):
	(m, k) = map(int, input().split(' '))
	ks = [1]
	kk = 1
	while kk <= 10 ** 16:
		kk *= k
		ks += [kk]
	ns = list(map(int, input().split(' ')))
	fail = False
	for x in ns:
		upper = len(ks) - 1
		while x > 0 and upper >= 0:
			if ks[upper] != None and ks[upper] <= x:
				x -= ks[upper]
				ks[upper] = None
			upper -= 1
		if x > 0:
			fail = True
			break
	if fail:
		print('NO')
	else:
		print('YES')


def can_be(n, k, e):
	pos = set()
	for i in range(n):
		curr = e[i]
		d = 0
		while curr:
			(curr, mod) = divmod(curr, k)
			if mod not in [0, 1]:
				return 'NO'
			if mod:
				if d in pos:
					return 'NO'
				pos.add(d)
			d += 1
	return 'Yes'
for _ in range(int(input())):
	(nb_element, k_factor) = [int(x) for x in input().split()]
	elements = [int(x) for x in input().split()]
	print(can_be(nb_element, k_factor, elements))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = array()
	s = set()
	f = 1
	for i in a:
		if i == 0:
			continue
		else:
			powers = []
			p = 0
			while i > 0:
				if i % k == 0:
					i = i // k
					p += 1
				else:
					powers.append(p)
					i -= 1
			for p in powers:
				if p in s:
					f = 0
					print('NO')
					break
				else:
					s.add(p)
			if f == 0:
				break
	if f:
		print('YES')


def rep(n, k):
	s = 0
	i = 1
	cnt = 0
	while n:
		s += n % k * i
		n //= k
		i *= 10
		cnt += 1
	return [s, cnt]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	z = 1
	a = 0
	(cnt, ct) = (0, 0)
	for i in ar:
		f = rep(i, k)
		a += f[0]
		ct = max(ct, f[1])
	while a > 0:
		if a % 10 != 0 and a % 10 != 1:
			z = 0
			break
		a //= 10
		cnt += 1
	if z and cnt == ct:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	mx = max(A)
	arr = []
	val = 1
	while val <= mx:
		arr.append(val)
		val *= k
	arr.reverse()
	ind = [0] * len(arr)
	flag = 0
	for a in A:
		for i in range(len(arr)):
			if arr[i] <= a and ind[i] == 0:
				a -= arr[i]
				ind[i] = 1
		if a != 0:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
for g in range(0, t):
	ans = []
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	a = list(map(int, input().split()))
	breaks = 0
	for i in range(0, n):
		b = 0
		if a[i] == 0:
			continue
		else:
			s = []
			m = 0
			while a[i] != 0:
				if a[i] % k == 0:
					a[i] = a[i] / k
					m = m + 1
				elif a[i] % k == 1:
					a[i] = a[i] - 1
					s.append(m)
				else:
					b = 1
					break
			if b == 1:
				breaks = 1
				break
			else:
				for p in range(0, len(s)):
					ans.append(s[p])
	if breaks == 0 and len(ans) == len(set(ans)):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	am = max(a)
	cnt = 0
	while am > 0:
		am //= k
		cnt += 1
	for _ in range(cnt):
		ar = [a[i] % k for i in range(n)]
		if sum(ar) > 1:
			print('NO')
			break
		a = [a[i] // k for i in range(n)]
	if max(a) == 0:
		print('YES')


t = int(input())
for i in range(t):
	e = 0
	(n, k) = map(int, input().split())
	(s, m) = (input().split(), set())
	for j in s:
		p = 0
		while j != 0:
			(j, r, p) = (int(j) // k, int(j) % k, p + 1)
			if r >= 1:
				if p - 1 in m:
					e = 1
				m.add(p - 1)
				if r > 1:
					e = 1
	if e == 0:
		print('YES')
	else:
		print('NO')


def omg(x, n):
	ans = []
	while x > 0:
		ans.append(x % n)
		x //= n
	ans.reverse()
	return ans
T = int(input())
answer = []
for kek in range(T):
	(n, k) = map(int, input().split())
	b = list(map(lambda x: omg(x, k), map(int, input().split())))
	flag = True
	M = 0
	for i in b:
		M = max(M, len(i))
	for i in range(1, M + 1):
		test = 0
		if flag:
			for j in b:
				if len(j) >= i:
					test += j[-i]
			if test > 1:
				flag = False
		else:
			break
	if flag:
		answer.append('YES')
	else:
		answer.append('NO')
print(*answer, sep='\n')


def frm(x, b):
	r = []
	while x > 0:
		r.append(x % b)
		x //= b
	return r
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	d = {}
	for i in lst:
		tmp = frm(i, k)
		for j in range(len(tmp)):
			if tmp[j]:
				if j not in d.keys():
					d[j] = tmp[j]
				else:
					d[j] += tmp[j]
	ck = True
	for (i, j) in d.items():
		if j > 1:
			ck = False
			break
	if ck:
		print('YES')
	else:
		print('NO')


from math import ceil, log
t = int(input())
for i2 in range(t):
	check = [0] * 60
	ans = 1
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	for i in range(n):
		if x[i] == 0:
			continue
		p = ceil(log(x[i], k))
		while 1:
			if x[i] == 0:
				break
			elif p < 0:
				ans = 0
				break
			if x[i] >= k ** p:
				x[i] -= k ** p
				if check[p] == 1:
					ans = 0
					break
				check[p] = 1
			p -= 1
	if ans == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	d = {}
	l = []
	c = 0
	for i in range(n):
		v = []
		pos = 1
		temp = a[i]
		while temp:
			r = temp % k
			if r == 0:
				pass
			elif r == 1:
				if pos not in d:
					d[pos] = 1
				else:
					c = 1
			else:
				c = 1
			temp //= k
			pos += 1
	if a.count(0) == n:
		print('YES')
	elif c == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	f = 0
	powr = [k ** (54 - i) for i in range(55)]
	check = [0 for i in range(55)]
	for i in range(n):
		for j in range(55):
			if a[i] >= powr[j]:
				a[i] -= powr[j]
				check[j] += 1
		if a[i]:
			f = 1
			break
	for i in range(55):
		if check[i] > 1:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


import math
t = int(input())

def fn():
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	z = k
	while k < 10 ** 16:
		k *= z
	while k >= 1:
		count = 0
		for i in range(n):
			if x[i] >= k:
				x[i] = x[i] - k
				count += 1
		if count > 1:
			print('NO ')
			return
		k = k // z
	if min(x) != 0 or max(x) != 0:
		print('NO')
		return
	print('YES')
while t:
	t -= 1
	fn()


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, x) = MAP()
	A = LIST()
	k = 1
	MAX = 10 ** 16
	while x ** k <= MAX:
		k += 1
	A.sort()
	for i in range(k, -1, -1):
		for j in range(N - 1, -1, -1):
			if A[j] >= x ** i:
				A[j] -= x ** i
				break
	if sum(A) == 0:
		YES()
	else:
		NO()


def conv(n, base):
	ans = 0
	mul = 1
	while n:
		ans += n % base * mul
		mul *= 10
		n //= base
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	a = [conv(int(i), k) for i in b]
	used = set()
	usedL = [[] for i in range(n)]
	flag = 0
	j = 0
	for i in a:
		num = i
		bit = 0
		while num:
			digit = num % 10
			if digit != 0:
				if digit != 1:
					flag = 1
					break
				elif bit in used:
					flag = 1
					break
				else:
					used.add(bit)
					usedL[j].append(bit)
			num //= 10
			bit += 1
		j += 1
	if flag:
		print('NO')
		continue
	for i in range(n):
		num = b[i]
		gg = 0
		for j in usedL[i]:
			gg += k ** j
		if gg != num:
			flag = 1
	print('YES' if not flag else 'NO')


from math import log
MAX_EXP = 0
used = []

def getExpo(x, k):
	global MAX_EXP
	(l, r) = (0, MAX_EXP)
	while l <= r:
		mid = (l + r + 1) // 2
		if x % k ** mid == 0 and x % k ** (mid + 1) != 0:
			return mid
		if x % k ** mid == 0:
			l = mid
		else:
			r = mid - 1
	return -1

def test(x, k):
	global used
	D = {}
	cumExp = 0
	while x > 0:
		exp = getExpo(x, k)
		if exp == -1:
			return False
		x //= k ** exp
		x -= 1
		cumExp += exp
		D[cumExp] = D.get(cumExp, 0) + 1
		if D[cumExp] > 1:
			return False
	for k in D.keys():
		if used[k] == 1:
			return False
	for k in D.keys():
		used[k] = 1
	return True

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	global used
	used = [0] * 64
	global MAX_EXP
	MAX_EXP = int(log(max(a) + 1, k)) + 5
	for x in a:
		if test(x, k) == False:
			print('NO\n')
			return
	print('YES\n')
t = int(input())
while t > 0:
	t -= 1
	solve()


T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	V = [0] * 100
	for n in range(N):
		S = A[n]
		c = 0
		while S > 0:
			V[c] += S % K
			c += 1
			S = S // K
	fl = 0
	for v in range(100):
		if V[v] > 1:
			fl = 1
			break
	if fl == 0:
		print('YES')
	else:
		print('NO')


def giveb(num, k):
	l = []
	while num > 0:
		if num % k not in [0, 1]:
			return 'notvalid'
		else:
			l.append(str(num % k))
			num = num // k
	return ''.join(l[::-1])
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = []
	used = set()
	valid = True
	for i in l:
		ans.append(giveb(i, k))
	for i in ans:
		for (idx, j) in enumerate(i[::-1]):
			if j == '0':
				continue
			if j != '1' or idx in used:
				valid = False
				break
			else:
				used.add(idx)
	if valid:
		print('YES')
	else:
		print('NO')


import math
from decimal import *
import random
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ok = True
	arr = list(map(int, input().split()))
	mrk = [0 for i in range(60)]
	for i in range(n):
		if arr[i] % k >= 2:
			ok = False
			break
		else:
			while arr[i] > 0:
				j = 1
				cnt = 0
				while j * k <= arr[i]:
					j *= k
					cnt += 1
				mrk[cnt] += 1
				arr[i] -= j
	if ok:
		for i in range(60):
			if mrk[i] > 1:
				ok = False
				print('NO')
				break
		if ok:
			print('YES')
	else:
		print('NO')


from math import log, ceil

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		s = set()
		ok = True
		for i in a:
			p = i
			if p == 0:
				continue
			m = int(ceil(log(p) / log(k)))
			l = k ** m
			while m >= 0 and p > 0:
				if p >= l and m not in s:
					p -= l
					s.add(m)
				m -= 1
				l //= k
			if p != 0:
				ok = False
				break
		print('YES' if ok else 'NO')
	return
main()


def _add_power(arr, base, arr_len):
	max_n = max(arr)
	res = [1]
	while res[-1] * base <= max_n:
		res.append(res[-1] * base)

	def dfs(arr, base, res, visited):
		if not arr:
			return True
		if arr[0] == 0:
			return dfs(arr[1:], base, res, visited)
		if arr[0] > sum([res[i] for i in range(len(res)) if not visited[i]]):
			return False
		ans = [False]
		for i in range(len(res)):
			if visited[i] == 1:
				continue
			if arr[0] == res[i]:
				visited[i] = 1
				ans.append(dfs(arr[1:], base, res, visited))
				break
			if arr[0] > res[i]:
				arr[0] = arr[0] - res[i]
				visited[i] = 1
				ans.append(dfs(arr, base, res, visited))
				visited[i] = 0
				arr[0] = arr[0] + res[i]
		return any(ans)
	arr.sort()
	res.sort(reverse=True)
	visited = [0] * len(res)
	return dfs(arr, base, res, visited)

def add_power(arr, base, arr_len):
	max_n = max(arr)
	res = [1]
	while res[-1] * base <= max_n:
		res.append(res[-1] * base)

	def dfs(n, res, visited, used):
		if n == 0:
			for i in visited:
				used.append(i)
			return True
		if n < 0:
			return False
		if not res or sum(res) < n:
			return False
		return dfs(n - res[-1], res[:-1], [res[-1]] + visited, used) or dfs(n, res[:-1], visited, used)
	arr.sort(reverse=True)
	res.sort()
	for n in arr:
		memo = {}
		used = []
		if not dfs(n, res, [], used):
			return False
		res = [i for i in res if i not in used]
	return True
t = int(input())
for i in range(1, t + 1):
	(arr_len, base) = [int(s) for s in input().split(' ')]
	arr = [int(s) for s in input().split(' ')]
	h = add_power(arr, base, arr_len)
	ans = ['NO', 'YES'][h]
	print(ans)


def base_10_to_n(x, n):
	if int(x / n):
		return base_10_to_n(int(x / n), n) + [x % n]
	return [x % n]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = map(int, input().split())
	A = [base_10_to_n(a, k) for a in A]
	d = {}
	for i in range(n):
		a = A[i]
		a.reverse()
		for j in range(len(a)):
			if a[j] != 0:
				if j not in d:
					d[j] = int(a[j])
				else:
					d[j] += int(a[j])
	v = d.values()
	if len(v) == 0 or max(v) == 1:
		print('YES')
	else:
		print('NO')


from math import log
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [*map(int, input().split())]
	for i in range(60, -1, -1):
		p = k ** i
		for j in range(n):
			if l[j] >= p:
				l[j] -= p
				break
	print('YES' if all((i == 0 for i in l)) else 'NO')


def power(n, k):
	aa = 0
	while n % k == 0:
		n /= k
		aa += 1
	return aa

def xxx(n, k):
	ans = []
	x = 1
	land = n
	if n == 1:
		return [0]
	ans = []
	x = 1
	if n % k != 0:
		n -= 1
		ans.append(0)
	while x:
		temp = power(n, k)
		ans.append(temp)
		zz = n
		n /= k ** temp
		if zz == n:
			break
		if n == 1:
			break
		if n < k:
			break
		n -= 1
	axy = [x for x in ans]
	for i in range(0, len(axy) - 1):
		for j in range(i + 1, len(ans)):
			axy[j] += ans[i]
	test = 0
	for j in axy:
		test += k ** j
	if test != land:
		return -1
	if len(set(axy)) != len(axy):
		return -1
	return axy
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	y = set(arr)
	y = list(y)
	if y[0] == 0 and len(y) == 1:
		print('YES')
		continue
	else:
		ans_l = []
		flag = 0
		for i in range(0, n):
			if arr[i] == 0:
				continue
			if flag:
				break
			z = xxx(arr[i], k)
			if z == -1:
				flag = 1
				break
			for m in z:
				if m in ans_l:
					flag = 1
					break
			ans_l += z
		if flag:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(60, -1, -1):
		m = k ** i
		for j in range(n):
			if a[j] >= m:
				a[j] -= m
				break
	if all((i == 0 for i in a)):
		print('YES')
	else:
		print('NO')


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect

def factor(i):
	x = a[i]
	cnt = 0
	while x > 0:
		u = x % k
		x //= k
		deg[cnt] += u
		cnt += 1
for _ in range(I()):
	(n, k) = R()
	a = L()
	deg = [0] * 1000
	for i in range(n):
		factor(i)
	fl = True
	for i in range(1000):
		if deg[i] > 1:
			print('NO')
			fl = False
			break
	if fl:
		print('YES')


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	f = False
	s = set()
	a = list(map(int, input().split()))
	for i in range(n):
		(c, c1) = (a[i], 0)
		while c:
			d = c % k
			if d > 1:
				f = True
				break
			elif d == 1:
				if c1 in s:
					f = True
					break
				else:
					s.add(c1)
			c //= k
			c1 += 1
	if not f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = (int(x) for x in input().strip().split(' '))
	L = [int(x) for x in input().strip().split(' ')]
	res = True
	S = set()
	for x in L:
		y = x
		i = 0
		while y:
			i += 1
			if y % k > 1:
				res = False
				break
			elif y % k == 1 and i in S:
				res = False
				break
			elif y % k == 1:
				S.add(i)
			y = y // k
	if res:
		print('YES')
	else:
		print('NO')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def convert_check(num, base):
	base_rev = ''
	if num == 0:
		base_rev = '0'
	while num > 0:
		r = num % base
		if r > 1:
			return 'NO'
		num = num // base
		base_rev += str(r)
	return base_rev[::-1]
(t,) = I()
for test in range(t):
	(n, k) = I()
	arr = I()
	d = dd(int)
	possible = True
	for elt in arr:
		pos = 0
		while elt > 0:
			r = elt % k
			elt = elt // k
			if r > 1:
				possible = False
				break
			if r:
				d[pos] += 1
			pos += 1
		if not possible:
			print('NO')
			break
	if possible:
		for key in d:
			if d[key] > 1:
				possible = False
				print('NO')
				break
		if possible:
			print('YES')


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	al = set()
	ch = True
	for j in a:
		while j != 0:
			h = 1
			ans = 0
			while h * m <= j:
				h *= m
				ans += 1
			j -= h
			if ans in al:
				ch = False
				break
			al.add(ans)
	if ch:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from collections import *
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	s = set()
	for ai in a:
		l = []
		while ai >= k:
			l.append(ai % k)
			ai //= k
		l.append(ai)
		for i in range(len(l)):
			if l[i] > 1:
				flag = False
				break
			if l[i] == 1:
				if i in s:
					flag = False
					break
				s.add(i)
	if flag:
		print('YES')
	else:
		print('NO')


from math import sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(a) for a in input().split()]
	flag = True
	s = 0
	while k ** s <= 10 ** 16:
		s += 1
	while s >= 0:
		for i in range(n):
			if A[i] >= k ** s:
				A[i] -= k ** s
				break
		s -= 1
	for i in range(n):
		if A[i] != 0:
			flag = False
	print('YES' if flag else 'NO')


for _ in range(int(input())):

	def fm(a):
		jj = a[0]
		j = 0
		for i in range(1, len(a)):
			if a[i] > jj:
				jj = a[i]
				j = i
		return j
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = 0
	d = max(a)
	while k ** s < d:
		s += 1
	check = True
	for i in range(s + 1):
		while k ** s > a[fm(a)]:
			s -= 1
		a[fm(a)] -= k ** s
		s -= 1
		if a[fm(a)] > k ** s:
			check = False
	if check or sum(a) == 0:
		print('YES')
	else:
		print('NO')


def l(n, k):
	i = 0
	while k ** i <= n:
		i += 1
	return i - 1
from math import log
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a)
	possible = True
	if m != 0:
		m = l(m, k) + 1
		used = [0] * m
		for i in range(n):
			if a[i] != 0:
				while a[i] != 0:
					j = l(a[i], k)
					d = a[i] // k ** j
					if d > 1:
						possible = False
						break
					elif d == 1:
						if used[j]:
							possible = False
							break
						else:
							used[j] = 1
					a[i] -= d * k ** j
				if not possible:
					break
	if possible:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	h = set()
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	res = True
	j = 0
	while j < n and res:
		c = a[j]
		p = 0
		while c != 0 and res:
			rest = c % k
			if rest in [0, 1]:
				if rest == 1 and p in h:
					res = False
				elif rest == 1:
					h.add(p)
			else:
				res = False
			c //= k
			p += 1
		j += 1
	if res:
		print('YES')
	else:
		print('NO')


import sys
from math import log
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	(n, k) = MI()
	a = LI()
	p = int(log(int(1e+16), k))
	ok = True
	while p >= 0:
		x = k ** p
		cnt = 0
		for i in range(n):
			if a[i] >= x:
				cnt += 1
				a[i] -= x
		if cnt > 1:
			ok = False
		p -= 1
	if sum(a) > 0:
		ok = False
	print('yes' if ok else 'no')


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
tests = read_int()
for t in range(tests):
	(n, k) = read_int_array()
	arr = read_int_array()
	used = [False] * 64
	can = True
	for ai in arr:
		if not can:
			break
		if ai == 0:
			continue
		power = 0
		while can and ai > 0:
			(q, r) = divmod(ai, k)
			if r > 1:
				can = False
			if r == 1:
				if used[power]:
					can = False
				used[power] = True
			ai = q
			power += 1
	print('YES' if can else 'NO')


import sys

def get(target, k):
	num = 0
	val = 1
	while val * k <= target:
		val *= k
		num += 1
	return num
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	l = list(map(int, sys.stdin.readline().split()))
	used = set()
	flag = True
	for i in range(n):
		while l[i] > 0 and flag:
			log = get(l[i], k)
			if log in used:
				flag = False
			used.add(log)
			l[i] -= k ** log
	if flag:
		print('YES')
	else:
		print('NO')


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	if n == 1:
		return 0
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [digit[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [digit[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matridigit[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matridigit[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matridigit[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] + other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] - other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matridigit[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matridigit[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matridigit[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)
from collections import deque

class Dinic:

	def __init__(self, N):
		self.N = N
		self.G = [[] for i in range(N)]

	def add_edge(self, fr, to, cap):
		forward = [to, cap, None]
		forward[2] = backward = [fr, 0, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def add_multi_edge(self, v1, v2, cap1, cap2):
		edge1 = [v2, cap1, None]
		edge1[2] = edge2 = [v1, cap2, edge1]
		self.G[v1].append(edge1)
		self.G[v2].append(edge2)

	def bfs(self, s, t):
		self.level = level = [None] * self.N
		deq = deque([s])
		level[s] = 0
		G = self.G
		while deq:
			v = deq.popleft()
			lv = level[v] + 1
			for (w, cap, _) in G[v]:
				if cap and level[w] is None:
					level[w] = lv
					deq.append(w)
		return level[t] is not None

	def dfs(self, v, t, f):
		if v == t:
			return f
		level = self.level
		for e in self.it[v]:
			(w, cap, rev) = e
			if cap and level[v] < level[w]:
				d = self.dfs(w, t, min(f, cap))
				if d:
					e[1] -= d
					rev[1] += d
					return d
		return 0

	def flow(self, s, t):
		flow = 0
		INF = 10 ** 9 + 7
		G = self.G
		while self.bfs(s, t):
			(*self.it,) = map(iter, self.G)
			f = INF
			while f:
				f = self.dfs(s, t, INF)
				flow += f
		return flow
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	(n, k) = mi()
	A = li()
	memo = [0 for i in range(60)]
	for a in A:
		cnt = 0
		while a:
			memo[cnt] += a % k
			a //= k
			cnt += 1
	if max(memo) <= 1:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import math

def isprime(n):
	for x in range(2, math.floor(math.sqrt(n) + 1)):
		if n % x == 0:
			return False
	return True

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		mult = 1
		powers = []
		while mult < int(1e+17):
			powers.append(mult)
			mult *= k
		m = len(powers)
		powers.reverse()
		for x in range(n):
			for y in range(m):
				if a[x] - powers[y] >= 0:
					a[x] = a[x] - powers[y]
					powers[y] = 0
		print('YES' if sum(a) == 0 else 'NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline

def b(n, k):
	if n == 0:
		return [0] * 100
	digits = []
	while n:
		digits.append(n % k)
		n //= k
	return [0] * (100 - len(digits)) + digits[::-1]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	arr = [0 for i in range(101)]
	for v in a:
		curr = b(v, k)
		for i in range(100):
			arr[i] += curr[i]
	ans = 'YES'
	for i in arr:
		if i > 1:
			ans = 'NO'
	print(ans)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	Query.append((N, K, A))
L = 100
for (N, K, A) in Query:
	ok = True
	B = [0] * L
	for a in A:
		ind = 0
		while a:
			if a % K == 1:
				B[ind] += 1
			elif a % K != 0:
				ok = False
				break
			ind += 1
			a //= K
	for b in B:
		if b > 1:
			ok = False
			break
	print('YES' if ok else 'NO')


t = int(input())
b = []
for i in range(0, 50):
	b.append(0)
for i in range(0, t):
	b = []
	for i in range(0, 200):
		b.append(0)
	(n, k) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	if len(set(a)) == 1 and a[0] == 0:
		print('YES')
	elif len(set(a)) < n - a.count(0) + 1 and a.count(0) != 0:
		print('NO')
	else:
		f = 1
		for i in range(0, len(a)):
			if a[i] == 0:
				continue
			else:
				j = 0
				g = a[i]
				while g != 0:
					if g % k != 0 and g % k != 1:
						f = 0
						break
					b[j] = b[j] + g % k
					j = j + 1
					g = g // k
				if f == 0:
					break
		if f == 1 and len(b) == b.count(1) + b.count(0):
			print('YES')
		else:
			print('NO')


check = True

def conversion(x, k):
	global check
	s = ''
	if x == 0:
		return '0'
	while x != 0:
		if x % k > 1:
			check = False
			return ''
		s = str(x % k) + s
		x = x // k
	return s
t = int(input())
for i in range(t):
	check = True
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	used = [0] * 100
	for j in range(len(a)):
		ans = conversion(a[j], k)
		if len(ans) == 0:
			check = False
			break
		else:
			ans = ans[-1::-1]
			for r in range(len(ans)):
				used[r] += int(ans[r])
	if used.count(0) + used.count(1) == len(used) and check:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	bits = [0 for i in range(66)]
	ok = True
	for x in a:
		for j in range(66):
			bits[j] += x % k
			x = x // k
	if max(bits) >= 2:
		print('NO')
	else:
		print('YES')


def solve():
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	ans = [[0 for i in range(56)] for q in range(n)]
	ans2 = [0 for i in range(56)]
	for i in range(n):
		pos = 0
		while lst[i]:
			ans[i][pos] += lst[i] % k
			ans2[pos] += ans[i][pos]
			lst[i] //= k
			pos += 1
	for i in ans2:
		if i > 1:
			print('NO')
			return 0
	print('YES')
for i in range(int(input())):
	solve()


from sys import stdout, stdin
input = lambda : stdin.readline()

def t(x):
	kk = k
	ans = 1
	while kk < x:
		kk *= k
		ans += 1
	return ans

def f(x):
	if x == 0:
		return True
	ans = []
	kk = k ** t(x)
	T = t(x)
	for i in range(T + 1):
		if x // kk > 1:
			return False
		elif x // kk:
			if T - i - 1 in used:
				return False
			used.add(T - i - 1)
			x -= kk
		kk //= k
	return True
for i in range(int(input())):
	used = set()
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	for i in a:
		if not f(i):
			flag = False
			print('NO')
			break
	if flag:
		print('YES')


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	a = (*R(),)
	r = 0
	s = 1
	while s:
		z = sum(a)
		a = [x // k for x in a]
		r |= s > k * z + 1
		s = z
	print('YNEOS'[r::2])


from sys import stdin
for testcase in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	has_ans = True
	picked = set()
	for num in map(int, stdin.readline().split()):
		i = 0
		while num > 0 and has_ans:
			while num % k == 0:
				num //= k
				i += 1
			if i in picked:
				has_ans = False
				break
			picked.add(i)
			num -= 1
		if not has_ans:
			break
	print('YES' if has_ans else 'NO')


for z in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	while a != [0 for i in a]:
		b = [x % k for x in a]
		if sum(b) > 1:
			print('NO')
			break
		a = [x // k for x in a]
	else:
		print('YES')


def block(l, x, k):
	orig = x
	xx = []
	v = []
	while x > 0:
		v.append(int(x % k))
		x = int(x / k)
	for i in range(0, len(v)):
		if v[i] == 1:
			xx.append(i)
	SUM = 0
	for i in range(len(xx)):
		SUM += k ** xx[i]
	if SUM == orig:
		l.extend(xx)
		return l
	else:
		return [-69]
t = int(input())
for i in range(t):
	DADDY = 0
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	finale = []
	for j in range(len(l)):
		VALUE = block(finale, l[j], k)
		if len(VALUE) > 0 and VALUE[0] == -69:
			DADDY = 1
	if DADDY == 1:
		print('NO')
		continue
	if len(VALUE) == 0:
		print('YES')
		continue
	temp = set(finale)
	if len(finale) == len(temp):
		print('YES')
	else:
		print('NO')


from math import *
from collections import Counter

def base(n, b):
	x = []
	while n != 0:
		x.append(n % b)
		n = n // b
	return x
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = Counter()
	ans = 'YES'
	for j in a:
		z = base(j, k)
		for i in range(len(z)):
			if z[i] != 0:
				if z[i] == 1:
					y = z[i] * pow(k, i)
					b[y] += 1
					if b[y] > 1:
						ans = 'NO'
						break
				else:
					ans = 'NO'
					break
		if ans == 'NO':
			break
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = [0] * 1001
	for i in range(n):
		x = int(a[i])
		c = 0
		while x > 0:
			d[c] += x % k
			c += 1
			x //= k
	if max(d) > 1:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	count = 0
	free = []
	proceed = True
	for i in range(n):
		goal = arr[i]
		if goal == 0:
			continue
		while True:
			curr = k ** count
			count += 1
			if curr == arr[i]:
				break
			elif curr > arr[i]:
				free.append(curr)
				summ = 0
				proceed = False
				for j in range(len(free) - 1, -1, -1):
					if summ + free[j] == goal:
						free.pop(j)
						proceed = True
						break
					elif summ + free[j] < goal:
						summ += free[j]
						free.pop(j)
				break
			else:
				free.append(curr)
		if not proceed:
			break
	if not proceed:
		print('NO')
	else:
		print('YES')


t = int(input())
for case_num in range(t):
	(n, k) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	d = dict()
	for i in a:
		num = i
		level = 0
		while num > 0:
			if not level in d:
				d[level] = 0
			d[level] += num % k
			num //= k
			level += 1
	ok = True
	for i in d:
		if d[i] > 1:
			ok = False
			break
	print('YES' if ok else 'NO')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(a) for a in input().split()]
	ls1 = []
	p = 0
	for i in range(n):
		while ls[i] != 0:
			pw = math.ceil(math.log10(ls[i]) / math.log10(k))
			if k ** pw > ls[i]:
				pw -= 1
			k1 = k ** pw
			if pw not in ls1:
				ls[i] -= k1
				ls1.append(pw)
			else:
				print('NO')
				p = 1
				break
		if p:
			break
	if p == 0:
		print('YES')


import math
t = int(input())

def to(x, K):
	array = []
	while x != 0:
		array.append(x % K)
		x //= K
	return array
for abc in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a)
	one = a.count(1)
	if m > 1:
		cnt_of_power = [0] * (int(math.log2(m)) + 2)
	elif one < 2:
		print('Yes')
		continue
	else:
		print('No')
		continue
	for i in range(n):
		num = to(a[i], k)
		for j in range(len(num)):
			cnt_of_power[j] += num[j]
	f = 0
	for i in range(len(cnt_of_power)):
		if cnt_of_power[i] > 1:
			f = 1
	print('Yes' if f == 0 else 'No')


t = int(input())
for i in range(t):
	list = input().split(' ')
	k = int(list[1])
	entry = input().split(' ')
	flag = []
	entry.sort()
	B = True
	for e in entry:
		j = 0
		e = int(e)
		while e > 0:
			while e % pow(k, j) == 0:
				if len(flag) <= j:
					flag.append(False)
				j += 1
			while j > 0:
				if flag[j - 1] == False:
					e -= pow(k, j - 1)
					flag[j - 1] = True
					break
				else:
					j -= 1
			if j == 0:
				break
		if e != 0:
			B = False
			break
		if len(flag) < j:
			flag.append(False)
		j += 1
	if B == True:
		print('YES')
	else:
		print('NO')


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def case():
	(n, m) = li()
	a = li()
	arr = [0] * 55
	for i in range(n):
		k = a[i]
		j = 0
		while k:
			temp = k % m
			arr[j] += temp
			k = k // m
			j += 1
	flag = 0
	for i in arr:
		if i > 1:
			flag = 1
	if flag:
		print('NO')
	else:
		print('YES')
for _ in range(int(input())):
	case()


t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	k = nk[1]
	c = -1
	f = True
	l = list(map(int, input().split()))
	while max(l) != 0:
		mm = max(l)
		if mm == 0:
			break
		j = l.index(mm)
		temp = 0
		while k ** temp <= mm:
			temp += 1
		temp -= 1
		if c == -1:
			c = temp
			mm -= k ** temp
			l[j] = mm
		elif temp >= c:
			f = False
			break
		else:
			mm -= k ** temp
			l[j] = mm
			c = temp
	if f:
		print('YES')
	else:
		print('NO')


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		(n, k) = RL()
		arr = list(RL())
		rec = 0

		def c(num):
			res = 0
			pos = 0
			while num > 0:
				if num % k != 0:
					if num % k > 1:
						return -1
					res |= 1 << pos
				num //= k
				pos += 1
			return res
		for i in arr:
			rt = c(i)
			if rec & rt != 0 or rt == -1:
				print('NO')
				break
			rec |= rt
		else:
			print('YES')
main()


T = int(input())
ans_j = []
for j in range(T):
	(n, k) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	pw = 1
	s = 0
	while max(A) >= pw:
		pw *= k
		s += 1
	if max(A) == 0:
		ans = 'YES'
	else:
		for i in range(s - 1, -1, -1):
			if max(A) < k ** i:
				continue
			A[A.index(max(A))] -= k ** i
			if max(A) >= k ** i:
				ans = 'NO'
				break
			elif max(A) == 0:
				ans = 'YES'
				break
	ans_j.append(ans)
print(*ans_j, sep='\n')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	freq = [0] * 100
	next = 0
	for x in lst:
		base = []
		while 1:
			m = x % k
			x = x // k
			base.append(m)
			if x == 0:
				break
		for (idx, val) in enumerate(base):
			if val > 0:
				freq[idx] += val
				if freq[idx] > 1:
					print('NO')
					next = 1
					break
		if next:
			break
	if next:
		continue
	print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	f = 0
	d = {i: 0 for i in range(100)}
	while a != []:
		if f == 1:
			break
		x = a.pop()
		s = ''
		while x != 0:
			q = x // k
			r = x % k
			x = q
			if r > 1:
				f = 1
				break
			s += str(r)
		for i in range(len(s)):
			if s[i] == '1':
				d[i] += 1
			if d[i] > 1:
				f = 1
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
t = inn()
for tt in range(t):
	(n, k) = inm()
	a = inl()
	b = [0] * 60
	for x in a:
		for i in range(60):
			b[i] += x % k
			x //= k
			if x == 0:
				break
	print('YES' if max(b) <= 1 else 'NO')


import sys
t = int(input())
g = sys.stdin.readlines()
y = 0
for _ in range(t):
	(n, k) = map(int, g[y].split())
	y += 1
	a = list(map(int, g[y].split()))
	y += 1
	p = {1}
	x = 1
	m = max(a)
	while x <= m:
		p.add(x)
		x *= k
	f = True
	i = 0
	while i < n and f:
		while a[i] != 0:
			m = 0
			for p1 in p:
				if m < p1 <= a[i]:
					m = p1
			if m == 0:
				f = False
				break
			a[i] -= m
			p.remove(m)
		i += 1
	if f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	data = list(map(int, input().split()))
	flag = True
	count = 0
	maximum = pow(10, 16)
	w = 8
	while pow(y, w) < maximum:
		w += 1
	if data.count(0) != x:
		while count < 2 and w >= 0:
			temp = pow(y, w)
			for i in range(len(data)):
				if data[i] >= temp:
					count += 1
					data[i] -= temp
			if count >= 2:
				flag = False
				break
			w -= 1
			count = 0
	print('YES' if data.count(0) == x and flag == True else 'NO')


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	A = [int(i) for i in input().split()]
	B = [0] * 100
	for a in A:
		ct = 0
		while a:
			B[ct] += a % k
			a //= k
			ct += 1
	print('YES' if max(B) <= 1 else 'NO')


T = int(input())
max_val = int(1e+25)
for case in range(T):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	k1 = k
	possible = True
	while k1 < max_val:
		cnt = 0
		for i in range(n):
			if arr[i] % k1 not in [0, k1 // k]:
				possible = False
				break
			if arr[i] % k1 == k1 // k:
				cnt += 1
				arr[i] -= k1 // k
		if not possible:
			break
		if cnt > 1:
			possible = False
			break
		k1 *= k
	if possible:
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	flag = 0
	if l[0] == 0:
		n = 0
		y = 0
	else:
		x = math.ceil(math.log(l[0], k))
		y = [0 for i in range(x + 1)]
	for i in range(n):
		for j in range(x, -1, -1):
			if l[i] >= k ** j:
				if y[j] == 1:
					flag = 1
					break
				else:
					y[j] = 1
					l[i] -= k ** j
			if l[i] == 0:
				break
			if l[i] < k and l[i] != 1:
				flag = 1
				break
		if flag == 1:
			break
	if flag or sum(l):
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	arr = [int(c) for c in input().split()]
	for j in range(54, -1, -1):
		u = k ** j
		a = [i for i in range(len(arr)) if arr[i] >= u]
		if len(a) > 1:
			print('NO')
			break
		else:
			for i in a:
				arr[i] -= u
	else:
		if arr == [0] * n:
			print('YES')
		else:
			print('NO')


from math import *
NTC = int(input())

def testcase():
	powers = set()
	for x in a:
		if x == 0:
			continue
		power = ceil(log(x, k))
		while power >= 0:
			sub = k ** power
			if sub > x:
				power -= 1
				continue
			x -= sub
			if power in powers:
				print('NO')
				return
			powers.add(power)
			power -= 1
		if x != 0:
			print('NO')
			return
	print('YES')
for _ in range(NTC):
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	testcase()


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, k) = Read.list_int()
	a = Read.list_int()
	t = {}
	for i in a:
		if i == 0:
			continue
		if i == 1:
			if 0 in t:
				print('NO')
				return
			t[0] = True
			continue
		r = i
		if i % k != 0:
			if (i - 1) % k == 0 and 0 not in t:
				r -= 1
				t[0] = True
			else:
				print('NO')
				return
		while True:
			v = r
			c = 0
			while v % k == 0:
				v = v / k
				c += 1
			if c in t:
				print('NO')
				return
			t[c] = True
			if v == 1:
				break
			else:
				r = r - r / v
	print('YES')
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = [0] * 60
	for i in range(n):
		j = 0
		while a[i]:
			c[j] += a[i] % k
			j += 1
			a[i] = a[i] // k
	flag = 0
	for i in range(60):
		if c[i] > 1:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin, stdout
import math

def mylog(a, b):
	if a == 0:
		return True
	x = math.ceil(math.log(a, b))
	if k ** x > a:
		x -= 1
	if x in lst:
		return False
	lst.append(x)
	return mylog(a - k ** x, b)
lst = []
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	lst.clear()
	for val in a:
		f = mylog(val, k)
		if not f:
			stdout.write('no\n')
			break
	else:
		stdout.write('yes\n')


from math import *

def convert(x, k):
	if x == 0:
		return [0]
	a = []
	cp = 1
	sx = x
	while x > 0:
		cp *= k
		a.append(x % cp // (cp // k))
		x -= x % cp
	return a
zzz = int(input())
for zz in range(zzz):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	t = {}
	for x in a:
		tx = convert(x, k)
		for i in range(len(tx)):
			if i not in t:
				t[i] = tx[i]
			else:
				t[i] += tx[i]
	ha = True
	for i in t:
		if t[i] > 1:
			ha = False
			break
	if ha:
		print('YES')
	else:
		print('NO')


from math import log

def find_log(v, k, i):
	while i >= 0:
		if k ** i <= v:
			return i
		i -= 1
	return 0

def solve(n, k, a):
	used = set()
	for v in a:
		while v:
			MAX = int(log(v, k)) + 1
			i = find_log(v, k, MAX)
			if i in used:
				return 'NO'
			v -= k ** i
			used.add(i)
	return 'YES'

def main():
	inp = lambda : [int(x) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		(n, k) = inp()
		a = inp()
		print(solve(n, k, a))
main()


def ternary(n, k):
	l = []
	while n > 0:
		l.append(n % k)
		n = n // k
	return l
t = int(input())
from collections import defaultdict
for _ in range(t):
	d = defaultdict(int)
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	f = False
	for x in a:
		l = ternary(x, k)
		cnt = 0
		for y in l:
			if y == 1:
				d[cnt] += 1
			elif y != 0:
				f = True
			cnt += 1
		if f:
			break
	if f:
		print('NO')
		continue
	for k in d.keys():
		if d[k] > 1:
			print('NO')
			break
	else:
		print('YES')


import sys
from math import *
from collections import defaultdict
from queue import deque
from heapq import heappush, heappop
lines = [line.strip() for line in sys.stdin.readlines()]

def f(x, k):
	ret = 0
	pos = 0
	kk = 1
	while x > kk:
		kk *= k
		pos += 1
	while pos >= 0:
		if x >= kk:
			x -= kk
			ret |= 1 << pos
		kk //= k
		pos -= 1
	return -1 if x != 0 else ret
t = int(lines[0])
for tt in range(t):
	(n, k) = list(map(int, lines[tt * 2 + 1].split()))
	xs = list(map(int, lines[tt * 2 + 2].split()))
	sofar = 0
	for x in xs:
		flg = f(x, k)
		if flg < 0 or sofar & flg != 0:
			sofar = -1
			break
		sofar |= flg
	print('NO' if sofar < 0 else 'YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	cnt = {}
	flag = False
	for i in range(n):
		tmp = 0
		while a[i]:
			if a[i] % k == 1:
				if tmp not in cnt:
					cnt[tmp] = 1
				else:
					flag = True
			elif a[i] % k == 0:
				pass
			else:
				flag = True
			a[i] = a[i] // k
			tmp += 1
	if flag:
		print('NO')
	else:
		print('YES')


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(n, k) = map(int, input().split())
		aa = [int(a) for a in input().split()]
		x = 1
		while x <= max(aa):
			count = 0
			for i in range(n):
				a = aa[i]
				rem = a % (x * k)
				if rem == x:
					if count == 1:
						print('NO')
						return
					else:
						count += 1
						aa[i] -= rem
				elif rem != 0:
					print('NO')
					return
			x = x * k
		print('YES')
		return
	q = int(input())
	for _ in range(q):
		solve()
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
from math import log
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	p = set()
	flag = 0
	while a:
		if a[0] < 0:
			flag = 1
			break
		if a[0] == 0:
			a.pop(0)
		else:
			while a[0] > 0:
				z = 0
				while pow(k, z) <= a[0]:
					z += 1
				z -= 1
				a[0] -= pow(k, z)
				if z not in p:
					p.add(z)
				else:
					flag = 1
					break
		if flag == 1:
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


from math import ceil, log
from bisect import bisect_left
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [k ** x for x in range(70)]
	br = [x for x in range(70)]
	bad = False
	c = set()
	for e in a:
		if e == 0:
			continue
		while e > 0:
			i = bisect_left(b, e)
			if b[i] > e:
				i -= 1
			e -= b[i]
			if i in c:
				bad = True
				break
			c.add(i)
	if bad:
		print('NO')
	else:
		print('YES')


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def pw(a, b):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
		a *= a
		b //= 2
	return result

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = inpt()
		ar = inpt()
		d = {}
		ok = True
		for j in range(n):
			rem = ar[j]
			if rem == 0:
				continue
			while ok:
				(p, val) = (0, 0)
				while pw(k, p) <= rem:
					val = pw(k, p)
					p += 1
				if val in d:
					ok = False
					break
				rem -= val
				d[val] = j
				if rem == 0:
					break
		if ok:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for test_i in range(int(input())):
	(n, k) = map(int, input().split())
	deg_arr = [False for i in range(54)]
	arr = list(map(int, input().split()))
	ans = True
	for el in arr:
		if el > 0:
			deg_arr_cur = []
			while el:
				remainder = el % k
				if remainder > 1:
					ans = False
					break
				else:
					deg_arr_cur.append(bool(remainder))
				el = (el - remainder) // k
			if not ans:
				break
			for i in range(len(deg_arr_cur)):
				if deg_arr[i]:
					if deg_arr_cur[i]:
						ans = False
						break
				else:
					deg_arr[i] = deg_arr_cur[i]
			if not ans:
				break
	print('YES' if ans else 'NO')


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, k) = RI()
	a = RI()
	arr = []
	flag = True
	s = set()
	for i in a:
		temp = i
		flag = True
		ite = 0
		while temp > 0:
			temp1 = temp % k
			if temp1 != 0 and temp1 != 1 or (temp1 == 1 and ite in s):
				flag = not flag
				break
			if temp1 == 1:
				s.add(ite)
			temp = temp // k
			ite += 1
		if not flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


def testTargetL(n, tempC, tarL, tempL):
	for j in range(n):
		for t in range(tempC):
			if tempL[t] <= tarL[j]:
				tarL[j] -= tempL[t]
				tempL[t] = 0
	for m in range(n):
		if tarL[m] != 0:
			return False
	return True
tempL = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	tarL = sorted(map(int, input().split()), reverse=True)
	power = -1
	temp = 0
	tempL.clear()
	while temp <= tarL[0]:
		if temp != 0:
			tempL.append(temp)
		power += 1
		temp = k ** power
	tempC = len(tempL)
	if tempC == 0:
		print('YES')
	elif testTargetL(n, tempC, tarL, tempL[::-1]):
		print('YES')
	else:
		print('NO')


from sys import exit as sys_return
requests = int(input())
while requests > 0:
	requests -= 1
	(size, power) = map(int, input().split())
	(sums, numbers) = ([0 for i in range(100)], list(map(int, input().split())))
	for i in range(size):
		j = 0
		while numbers[i] != 0:
			sums[j] += numbers[i] % power
			numbers[i] //= power
			j += 1
	flag = 1
	for x in range(100):
		if sums[x] > 1:
			flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for __ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	stn = set()
	flag = False
	for e in a:
		i = 0
		while e > 0:
			x = e % k
			if x != 0 and (x > 1 or i in stn):
				print('NO')
				flag = True
				break
			if x != 0:
				stn.add(i)
			e //= k
			i += 1
		if flag:
			break
	else:
		print('YES')


def Base_10_to_n(num, n):
	out = []
	while num > 0:
		(num, mod) = divmod(num, n)
		if mod == 2:
			return -1
		out.append(mod)
	return out

def solve(n, k, a):
	flg = [0] * 60
	for i in range(n):
		p = Base_10_to_n(a[i], k)
		if p == -1:
			return 0
		else:
			for j in range(len(p)):
				flg[-(j + 1)] += p[j]
				if flg[-(j + 1)] > 1:
					return 0
	return 1
t = int(input())
ans = []
for _ in range(t):
	(tn, tk) = map(int, input().split())
	ta = list(map(int, input().split()))
	ans.append(solve(tn, tk, ta))
for cond in ans:
	if cond:
		print('YES')
	else:
		print('NO')


import sys
import math

def dec2basek(decnum, k, used):
	if decnum == 0:
		return True
	ul = math.log(decnum, k)
	indx = int(ul) + 2
	while indx >= 0:
		temp = k ** indx
		if decnum >= temp and used[indx] == False:
			decnum -= temp
			used[indx] = True
		indx -= 1
	if decnum == 0:
		return True
	else:
		return False

def answer(n, k, a):
	used = [False for _ in range(60)]
	for e in a:
		if dec2basek(e, k, used):
			pass
		else:
			return 'NO'
	return 'YES'

def main():
	T = int(sys.stdin.readline())
	while T:
		(n, k) = map(int, sys.stdin.readline().split())
		a = list(map(int, sys.stdin.readline().split()))
		print(answer(n, k, a))
		T -= 1
	return
main()


def to_base_k(n, k):
	s = '01' + 'x' * (k - 2)
	r = ''
	if n == 0:
		return '0'
	while n != 0:
		(d, m) = divmod(n, k)
		n = d
		r = s[m] + r
	return r
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = map(lambda x: to_base_k(int(x), k), input().split())
	l = ['0'] * 54
	f = False
	for a in arr:
		if 'x' in a:
			f = True
			break
		else:
			for i in range(1, len(a) + 1):
				if l[-i] == '0':
					l[-i] = a[-i]
				elif l[-i] == '1' and a[-i] == '1':
					f = True
					break
		if f:
			break
	if f:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	ok = True
	bit = [0] * 100
	for x in L:
		while x > 0:
			base = 1
			p = 0
			while base * k <= x:
				base *= k
				p += 1
			bit[p] += 1
			x -= base
	for i in range(100):
		if bit[i] > 1:
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')


import sys
import math

def check(l):
	arr = []
	for i in range(len(l)):
		l[i].reverse()
		arr.append(len(l[i]))
	arr.sort()
	n = len(l)
	for i in range(arr[-1]):
		count = 0
		for k in range(n):
			if len(l[k]) > i:
				if l[k][i] == 1:
					count += 1
		if count > 1:
			return False
	return True

def make(num, n):
	if num == 0:
		return [0]
	l = []
	while num != 0:
		a = num % n
		if a > 1:
			return False
		l.append(a)
		num = num // n
	l.reverse()
	return l
t = int(sys.stdin.readline())
for _ in range(t):
	z = True
	(n, k) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	arr = []
	for i in range(n):
		l = make(a[i], k)
		if l:
			arr.append(l)
		else:
			z = False
			break
	if not z:
		print('NO')
	elif check(arr):
		print('YES')
	else:
		print('NO')


tt = int(input())
for cas in range(tt):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	cnt = [0 for i in range(60)]
	for x in l:
		i = 0
		while x > 0:
			cnt[i] += x % k
			x //= k
			i += 1
	isok = True
	for i in cnt:
		if i > 1:
			isok = False
			break
	if isok:
		print('YES')
	else:
		print('NO')


def addPowers(n, k, a):
	c = [0 for i in range(60)]
	for i in range(n):
		j = 0
		while a[i] != 0:
			c[j] += a[i] % k
			if c[j] > 1:
				print('No')
				return
			j += 1
			a[i] //= k
	print('YES')
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	addPowers(n, k, a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = [0] * 60
	for x in a:
		i = 0
		while x > 0:
			r[i] += x % k
			x //= k
			i += 1
	f = False
	for i in r:
		if i > 1:
			f = True
			break
	print('NO' if f else 'YES')


import math
ll = 10 ** 16
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	zz = [1]
	for i in range(100):
		zz.append(zz[-1] * k)
		if zz[-1] > ll:
			break
	pp = len(zz)
	s = set([])
	ans = 0
	for i in li:
		if i != 0:
			for mp in range(pp - 1, -1, -1):
				if zz[mp] <= i:
					i -= zz[mp]
					ans += 1
					s.add(mp)
			if i != 0:
				ans += 2
	if len(s) == ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	cntPot = [0] * 55
	a = [int(x) for x in input().split()]
	for x in a:
		for i in range(55):
			cntPot[i] = cntPot[i] + x % k
			x //= k
	pos = True
	for i in range(55):
		if cntPot[i] >= 2:
			pos = False
			print('NO')
			break
	if pos:
		print('YES')


from math import log, ceil

def func(i, k, ans):
	global answer
	try:
		x = log(i, k)
		if k ** ceil(x) > i:
			if k ** (ceil(x) - 1) > i:
				x = ceil(x) - 2
			else:
				x = ceil(x) - 1
		else:
			x = ceil(x)
		x = int(x)
		if x in ans:
			answer = False
			return
		else:
			ans[int(x)] = 1
			func(i - k ** int(x), k, ans)
	except:
		pass
t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = {}
	answer = True
	for i in a:
		func(i, k, ans)
	if answer:
		print('YES')
	else:
		print('NO')


def block(x, n):
	v = []
	while x > 0:
		v.append(int(x % n))
		x = int(x / n)
	return v
for _ in range(int(input())):
	(n, k) = [int(s) for s in input().split()]
	arr = [int(s) for s in input().split()]
	freq = [0] * 100
	flag = False
	for i in arr:
		v = block(i, k)
		for j in range(len(v)):
			if v[j] == 1:
				if freq[j] != 0:
					flag = True
					break
				else:
					freq[j] = 1
			if v[j] > 1:
				flag = True
				break
		if flag:
			break
	if flag:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, k) = int_array()
	a = int_array()
	f = 1
	powers = set()
	for i in a:
		if i == 0:
			continue
		if i == 1:
			if 0 in powers:
				f = 0
				break
			else:
				powers.add(0)
				continue
		count = 0
		while i != 0:
			while i % k == 0:
				count += 1
				i = i // k
			if count in powers:
				f = 0
				break
			else:
				powers.add(count)
				i -= 1
			if i == 1 and count == 0:
				if 0 in powers:
					f = 0
					break
				else:
					powers.add(0)
					i -= 1
			elif i % k != 0:
				f = 0
				break
		if f == 0:
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	used = [0] * 58
	for a in A:
		i = 0
		while a:
			(d, m) = divmod(a, k)
			if m > 1 or (m == 1 and used[i]):
				print('NO')
				break
			if m == 1:
				used[i] = 1
			a = d
			i += 1
		else:
			continue
		break
	else:
		print('YES')


import sys
input = sys.stdin.buffer.readline

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(n, k) = I()
	arr = I()
	c = 1
	used = [0] * 100
	ans = 'YES'
	for i in range(n):
		a = arr[i]
		basek = []
		i = 0
		while a:
			if a % k != 0:
				if used[i] == 1 or a % k > 1:
					ans = 'NO'
				used[i] = 1
			i += 1
			a //= k
	print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = []
	flag = 0
	for x in a:
		if x == 0:
			continue
		count = 0
		if x == 1:
			l.append(count)
			continue
		while 1:
			while x % k == 0:
				count += 1
				x = x // k
			if x == 1:
				l.append(count)
				break
			x -= 1
			l.append(count)
	s = set(l)
	if len(l) == len(s) and flag == 0:
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	ss = int(math.log10(1e+16) / math.log10(k)) + 1
	bi = [[0 for i in range(ss)] for i in range(n)]
	pos = 1
	for i in range(n):
		no = lis[i]
		j = 0
		l = k
		while no:
			bi[i][j] = no % l
			no = no // l
			j += 1
	for i in range(ss):
		s = 0
		for j in range(n):
			s += bi[j][i]
			if s > 1:
				pos = 0
				break
		if s > 1:
			pos = 0
			break
	if pos:
		print('YES')
	else:
		print('NO')


t = int(input())
res = ''
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = input().split()
	c = [0] * 100
	for j in range(n):
		a[j] = int(a[j])
		check = True
		index = 0
		while check and a[j] != 0:
			if a[j] % k == 0:
				a[j] = a[j] / k
			elif a[j] % k == 1:
				a[j] = (a[j] - 1) / k
				c[index] += 1
			else:
				c[50] = 2
				check = False
			index += 1
	if max(c) > 1:
		res += 'NO'
	else:
		res += 'YES'
	res += '\n'
print(res, end='')


def power(n, k):
	p = [1]
	x = 1
	ans = []
	for i in range(60):
		p.append(x * k)
		x = x * k
	for i in range(60, -1, -1):
		if p[i] <= n:
			n -= p[i]
			ans.append(i)
	if n > 0:
		return -1
	else:
		return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = [0] * 60
	f = 1
	for i in range(n):
		if a[i] != 0:
			l = power(a[i], k)
			if l == -1:
				f = 0
				break
			else:
				for i in range(len(l)):
					cnt[l[i]] += 1
	for i in range(60):
		if cnt[i] > 1:
			f = 0
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		c = [0] * 60
		for i in range(n):
			j = 0
			while a[i]:
				c[j] += a[i] % k
				j += 1
				a[i] //= k
		f = 0
		for i in c:
			if i > 1:
				print('NO')
				f = 1
				break
		if f == 0:
			print('YES')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = []
	c = []
	num = 1
	while num <= max(a):
		s.append(num)
		c.append(True)
		num *= k
	ok = True
	for i in range(n):
		for j in range(len(s)):
			k = len(s) - j - 1
			if c[k] and a[i] >= s[k]:
				a[i] -= s[k]
				c[k] = False
		if a[i] != 0:
			ok = False
	print('YES' if ok else 'NO')


def get_max(t, k):
	val = 0
	rem = 0
	while t >= k:
		rem += t % k
		t = t // k
		val += 1
	return val

def get_ans(n, k, arr):
	hash_a = {}
	for i in range(n):
		j = 0
		t = arr[i]
		while t > 0:
			try:
				hash_a[j] += t % k
			except KeyError:
				hash_a[j] = t % k
			t = t // k
			j += 1
	for i in hash_a:
		if hash_a[i] > 1:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if get_ans(n, k, arr):
		print('YES')
	else:
		print('NO')


from sys import stdin

def to_ternary(n, x):
	l = []
	while n > 0:
		y = n % x
		if y > 1:
			l = []
			break
		l.append(str(y))
		n = n // x
	return list(reversed(l))
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	z = []
	r = 'YES'
	for i in range(n):
		if l[i] != 0:
			test = to_ternary(l[i], k)
			if not test:
				r = 'NO'
				break
			else:
				z.append(''.join(test))
	if r == 'NO':
		print('NO')
	else:
		for i in range(len(z) - 1):
			for j in range(i + 1, len(z)):
				if int(z[i], 2) & int(z[j], 2):
					r = 'NO'
					break
		if r == 'YES':
			print('YES')
		else:
			print('NO')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = math.floor(math.log(pow(10, 16), k))
	k_max = pow(k, s)
	count = 0
	a = list(map(int, input().split()))
	while True:
		count = 0
		for i in range(len(a)):
			if a[i] >= k_max:
				count += 1
				a[i] = a[i] - k_max
		if count > 1:
			print('NO')
			break
		if s < 0:
			if a == [0] * n:
				print('YES')
			else:
				print('NO')
			break
		s = s - 1
		k_max = pow(k, s)


def max_position(x):
	limit = 10 ** 16
	curr = x
	i = 1
	while curr <= limit:
		i += 1
		curr *= x
	return i - 1

def is_zeros(x):
	flag = True
	for x_i in x:
		if x_i != 0:
			flag = False
			break
	return flag
t = int(input())
for i in range(t):
	(n, k) = map(int, input().rsplit())
	a = list(map(int, input().rsplit()))
	i_max = max_position(k)
	for j in range(i_max, -1, -1):
		tmp = []
		for l in range(n):
			if a[l] >= k ** j:
				a[l] -= k ** j
				tmp.append(True)
		if sum(tmp) > 1:
			break
	if is_zeros(a) and (not sum(tmp) > 1):
		print('Yes')
	else:
		print('No')


def fn(num, k):
	l = []

	def get_nearest_pow(a, k):
		p = 0
		while k ** p <= a:
			p += 1
		return p - 1

	def f(a):
		if a == 0:
			return True
		x = get_nearest_pow(a, k)
		if x not in l:
			l.append(x)
		else:
			return False
		if x == 0:
			if a != 1:
				return False
			if a == 1:
				return True
		return f(a - k ** x)
	if f(num) == False:
		return False
	else:
		return l
for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	goal = list(map(int, input().split()))
	done = []
	ans = 'YES'
	for i in range(n):
		get_powers = fn(goal[i], k)
		if get_powers == False:
			ans = 'NO'
			break
		for i in get_powers:
			if i in done:
				ans = 'NO'
				break
			done.append(i)
	print(ans)


def f(b, k):
	t = 0
	while b != 0:
		if b % k == 0:
			b //= k
			t += 1
		elif b % k == 1:
			if used[t] == 1:
				return False
			used[t] = 1
			b -= 1
		else:
			return False
	return True
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	used = [0] * 100
	flag = True
	for i in a:
		if not f(i, k):
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


def f(x, k):
	if x == 0:
		return '0'
	else:
		l = []
		while x > 0:
			if x % k // 10 >= 1:
				l.append('9')
			else:
				l.append(str(x % k))
			x = x // k
		return ''.join(l)

def p(a):
	for i in a:
		if int(i) > 1:
			return False
	return True

def g(a, b):
	n = min(len(a), len(b))
	for i in range(n):
		if a[i] == b[i] != '0':
			return False
		elif int(a[i]) > 1 or int(b[i]) > 1:
			return False
	return True
t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	a = input()
	A = list(map(int, list(a.split())))
	flag = 0
	B = [0] * n
	for i in range(n):
		B[i] = f(A[i], k)
	for i in range(n):
		if p(B[i]) == False:
			print('NO')
			flag = 1
			break
		for j in range(i + 1, n):
			c = g(B[i], B[j])
			if c == False:
				print('NO')
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('YES')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	if sum(a) > 0:
		f = True
		for j in a:
			x = []
			m = 0
			while k ** m <= j:
				x.append(k ** m)
				m += 1
			y = 0
			while j != 0:
				if x[m - 1 - y] <= j:
					j -= x[m - 1 - y]
					if m - 1 - y in dic:
						dic[m - 1 - y] += 1
					else:
						dic[m - 1 - y] = 1
				else:
					y += 1
		for j in dic:
			if dic[j] > 1:
				print('NO')
				f = False
				break
		if f:
			print('YES')
	else:
		print('YES')


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	qq = []
	(n, k) = map(int, input().strip().split(' '))
	qq = [0] * 100
	a = list(map(int, input().strip().split(' ')))
	for i in a:
		j = 0
		while i:
			qq[j] += i % k
			i = i // k
			j += 1
	print('YES' if max(qq) <= 1 else 'NO')


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = [True] * 100
	bad = False
	for v in a:
		(i, pk) = (0, 1)
		while pk <= v:
			i += 1
			pk *= k
		while v > 0 and i >= 0:
			if pk <= v:
				v -= pk
				if p[i]:
					p[i] = False
				else:
					bad = True
					break
			pk //= k
			i -= 1
		if v > 0:
			bad = True
		if bad:
			break
	print('NO' if bad else 'YES')


def baser(n, base):
	x = [0 for i in range(70)]
	i = 0
	while n != 0:
		x[i] = n % base
		n = n // base
		i = i + 1
	return x
a = int(input())
for i in range(a):
	gam = []
	flag = 0
	(x, y) = map(int, input().split())
	z = list(map(int, input().split()))
	for i in range(len(z)):
		ans = baser(z[i], y)
		if len(gam) == 0:
			gam.append(ans)
			for i in range(len(ans)):
				if ans[i] > 1:
					flag = 1
					break
		else:
			gam.append(ans)
			for j in range(len(gam) - 1):
				for s in range(len(gam[j])):
					if ans[s] + gam[j][s] > 1:
						flag = 1
						break
	if flag == 1:
		print('NO')
	else:
		print('YES')


import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def slv(N, K, A):
	ma = max(A)
	for i in range(100000):
		if K ** i > ma:
			break
	mk = i - 1
	used = set()
	for a in A:
		for j in range(mk, -1, -1):
			t = K ** j
			if a >= t:
				if j in used:
					return 'NO'
				used.add(j)
				a -= t
		if a != 0:
			return 'NO'
	return 'YES'

def main():
	T = read_int()
	for _ in range(T):
		(N, K) = read_int_n()
		A = read_int_n()
		print(slv(N, K, A))
main()


import sys
readline = sys.stdin.buffer.readline
T = int(readline())
Ans = [None] * T
mi = 60
for qu in range(T):
	(N, K) = map(int, readline().split())
	A = list(map(int, readline().split()))
	table = [0] * mi
	pk = [1] * mi
	ans = 'YES'
	for i in range(1, mi):
		pk[i] = K * pk[i - 1]
	for a in A:
		for j in range(mi - 1, -1, -1):
			if a >= pk[j]:
				table[j] += 1
				a -= pk[j]
			if table[j] > 1:
				ans = 'NO'
				break
		else:
			if a:
				ans = 'NO'
				break
			continue
		break
	Ans[qu] = ans
print('\n'.join(Ans))


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	(n, m) = sep()
	a = lis()
	maxx = max(a)
	x = 0
	while m ** x <= maxx:
		x += 1
	x = x - 1
	f = False
	while x >= 0:
		cnt = 0
		for i in range(0, n):
			if a[i] >= m ** x:
				cnt += 1
				a[i] -= m ** x
		if cnt > 1:
			f = True
			break
		x -= 1
	if f:
		print('NO')
	elif a.count(0) == len(a):
		print('YES')
	else:
		print('NO')
testcase(int(inp()))


def cream(x, k):
	how = []
	while x != 0:
		how.append(x % k)
		x //= k
	return how
I = lambda : list(map(int, input().split()))
for _ in [0] * int(input()):
	(n, k) = I()
	array = I()
	pows = [1] * 60
	for e in array:
		how = cream(e, k)
		i = 0
		for y in how:
			pows[i] -= y
			i += 1
	res = True
	for x in pows:
		res &= x > -1
	if res:
		print('YES')
	else:
		print('NO')


import sys

def base(a, b):
	global potenze
	s = []
	while a // b != 0:
		s.append(a % b)
		a = a // b
	s.append(a % b)
	return s
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort()
	pot = 0
	while k ** pot <= L[-1]:
		pot += 1
	max_pot = pot + 1
	potenze = [0] * max_pot
	esito = True
	for a in L:
		if a != 0:
			s = base(a, k)
			for i in range(len(s)):
				if s[i] > 1:
					esito = False
					break
				elif s[i] == 1:
					if potenze[i] == 1:
						esito = False
						break
					else:
						potenze[i] = 1
	if not esito:
		print('NO')
	else:
		print('YES')


from collections import defaultdict

def call(n, k):
	i = 0
	while n:
		r = n % k
		if r == 0:
			pass
		elif r == 1:
			dp[i] += 1
			if dp[i] > 1:
				return False
		else:
			return False
		n //= k
		i += 1
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = defaultdict(int)
	tg = True
	for p in a:
		if p != 0:
			if call(p, k):
				pass
			else:
				tg = False
				break
	if tg:
		print('YES')
	else:
		print('NO')


import math

def is_ok(n, k, array):
	used_powers = []
	for x in array:
		tmp = x
		all_numbers = 0
		while tmp > 0:
			power = math.floor(math.log(tmp, k))
			powed = math.pow(k, power)
			if powed > tmp:
				powed = powed / k
				power -= 1
			elif powed * k <= tmp:
				powed = powed * k
				power += 1
			used_powers.append(power)
			tmp -= powed
			all_numbers += powed
		if x != all_numbers:
			print('NO')
			return
	if len(used_powers) > len(set(used_powers)):
		print('NO')
		return
	print('YES')
T = int(input())
b = []
n_k = []
i = T
while i > 0:
	i = i - 1
	n_k.append([int(a) for a in input().split(' ')])
	b.append([int(a) for a in input().split(' ')])
while i < T:
	n = n_k[i][0]
	k = n_k[i][1]
	array = b[i]
	is_ok(n, k, array)
	i = i + 1


for x in range(int(input())):
	(n, k) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	b = max(m)
	c = 0
	while k ** c <= b:
		c += 1
	a = [0] * (c + 2)
	for j in range(c + 1, -1, -1):
		l = k ** j
		cnt = 0
		for i in range(n):
			if m[i] / l >= 1:
				m[i] -= l
				cnt += 1
		a[j] += cnt
	if max(a) > 1 or max(m) > 0:
		print('NO')
	else:
		print('YES')


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(n, k) = list(map(int, sys.stdin.readline().rstrip().split()))
	num = list(map(int, sys.stdin.readline().rstrip().split()))
	num.sort()
	check = []
	result = True
	for i in num:
		if i == 0:
			continue
		chk = i
		re = True
		cnt = 0
		while True:
			if chk % k > 1:
				re = False
				break
			if chk % k == 1:
				if k ** cnt in check:
					re = False
					break
				check.append(k ** cnt)
			chk = int(chk / k)
			cnt += 1
			if chk < k:
				if chk % k > 1:
					re = False
					break
				if chk % k == 1:
					if k ** cnt in check:
						re = False
						break
					check.append(k ** cnt)
				break
		if not re:
			result = False
			break
	if result:
		print('YES')
	else:
		print('NO')


def f(n):
	d = []
	while n != 0:
		(x, y) = divmod(n, k)
		d.append(y)
		n = x
	return d
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = {}
	for i in a:
		x = f(i)
		for j in range(len(x)):
			if x[j] > 0:
				l[j] = l.get(j, 0) + x[j]
	if any((l[i] != 1 for i in l)):
		print('NO')
	else:
		print('YES')


q = int(input())
while q > 0:
	qq = 1
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l2 = [0] * 60
	for i in range(60):
		l2[i] = k ** (60 - i - 1)
	for i in range(60):
		for j in range(n):
			if l[j] >= l2[i] and l2[i] != 0:
				l[j] -= l2[i]
				l2[i] = 0
	for i in range(n):
		if l[i] != 0:
			print('NO')
			qq = 0
			break
	if qq == 1:
		print('YES')
	q -= 1


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	used = [False] * 1000
	a = list(map(int, input().split()))
	done = True
	for i in range(n):
		ai = a[i]
		p = 0
		while ai > 0:
			r = ai % k
			if r == 0:
				p += 1
				ai = ai // k
				continue
			if r != 1:
				done = False
				break
			if used[p]:
				done = False
				break
			used[p] = True
			ai = ai // k
			p += 1
		if not done:
			break
	if done:
		print('YES')
	else:
		print('NO')


for _ in ' ' * int(input()):
	z = [0] * 55
	b = int(input().split()[1])
	c = list(map(int, input().split()))
	for i in c:
		j = 0
		while i:
			z[j] += i % b
			i //= b
			j += 1
	print('NO' if max(z) > 1 else 'YES')


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(n, k) = ilele()
	A = alele()
	num = 1
	while num * k <= 10 ** 16:
		num *= k
	while num:
		m = max(A)
		loc = A.index(m)
		if m >= num:
			A[loc] -= num
		num //= k
	Y(A.count(0) == n)


n = int(input())

def parse_number(x, base):
	result = []
	while x > 0:
		(x, r) = divmod(x, base)
		if r not in [0, 1]:
			return -1
		result.append(r)
	return result

def solve(array, base):
	(results, max_len) = ([], 0)
	for num in array:
		result = parse_number(num, base)
		if result == -1:
			return False
		results.append(result)
		max_len = max(len(result), max_len)
	new_results = []
	for result in results:
		len_result = len(result)
		new_result = [0] * (max_len - len_result) + list(reversed(result))
		new_results.append(new_result)
	for i in range(max_len):
		flag = False
		for new_result in new_results:
			if new_result[i] == 1:
				if flag:
					return False
				flag = True
	return True
for _ in range(n):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	array = input().split(' ')
	array = [int(x) for x in array if x != '0']
	if len(array) == 0:
		print('YES')
	elif solve(array, k):
		print('YES')
	else:
		print('NO')


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	c = 0
	s = set()
	for i in l:
		if i == 0:
			continue
		else:
			num = i
			while num != 0:
				p = math.log(num, k)
				one = int(p // 1)
				two = int(one + 1)
				th = one - 1
				if pow(k, two) <= num and two not in s:
					s.add(two)
					num = num - pow(k, two)
				elif pow(k, one) <= num and one not in s:
					s.add(one)
					num = num - pow(k, one)
				elif pow(k, th) <= num and th not in s:
					s.add(th)
					num = num - pow(k, th)
				else:
					c = 1
					break
		if c:
			break
	if c:
		print('NO')
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))

	def convert(x, k):
		if x == 0:
			return (True, [])
		ans = 0
		start = 0
		an = []
		while x:
			ans = max(ans, x % k)
			if x % k:
				an += [start]
			start += 1
			x = x // k
		if ans > 1:
			return (False, [])
		else:
			return (True, an)
	pos = True
	b = []
	for each in a:
		(p, q) = convert(each, k)
		if not p:
			pos = False
			break
		else:
			for nn in q:
				b += [nn]
	if pos and len(set(b)) == len(b):
		print('YES')
	else:
		print('NO')


used = []

def maxpower(n, k):
	p = 1e+16
	while n > 0:
		q = 0
		while k ** q <= n:
			q += 1
		q -= 1
		if q < p and used[q] == 0:
			p = q
			used[p] = 1
		else:
			return 'NO'
		n -= k ** p
	return 'YES'
I = input
import math
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	globals()
	a = list(map(int, I().split(' ')))
	a.sort()
	if a[n - 1] == 0:
		print('YES')
	else:
		used = [0 for i in range(math.ceil(math.log(a[n - 1], k)) + 1)]
		temp = 0
		for i in range(n - 1, -1, -1):
			if maxpower(a[i], k) == 'NO':
				temp = 1
				break
		if temp == 0:
			print('YES')
		else:
			print('NO')


def solve(k, a):
	p = 1
	while p < max(a):
		p *= k
	while p > 0:
		for (idx, e) in enumerate(a):
			if e >= p:
				a[idx] -= p
				break
		p = p // k
	if max(a) > 0:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(k, a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	kbits = [0] * 55
	for x in a:
		t = x
		i = 0
		while t:
			kbits[i] += t % k
			t = t // k
			i += 1
	m = max(kbits)
	if m > 1:
		print('NO')
	else:
		print('YES')


import sys

def get_coefs(n, b):
	coefs = []
	while n > 0:
		coefs.insert(0, n % b)
		n = n // b
	return coefs
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	coefs = []
	possible = True
	for num in arr:
		coefs.append(get_coefs(num, k))
	m = 0
	for x in coefs:
		if len(x) > 0:
			m = max(len(x), m)
	if m == 0:
		print('YES')
		continue
	else:
		for i in range(n):
			while len(coefs[i]) < m:
				coefs[i].insert(0, 0)
	sum_arr = [0] * m
	for y in range(m):
		for x in range(n):
			sum_arr[y] += coefs[x][y]
	for a in sum_arr:
		if a > 1:
			possible = False
			break
	if possible:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import traceback
from collections import Counter
read = stdin.readline
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

class Sol:

	@classmethod
	def input(cls):
		s = cls()
		return s

	def solve(self):
		(n, k) = reads()
		aa = reads()
		c = Counter()
		aa = sorted(aa)
		while aa[-1] > 0:
			sums = sum([ai % k for ai in aa])
			if sums > 1:
				return False
			aa = [ai // k for ai in aa]
		return True
try:
	for _ in range(int(read())):
		writeln('YES' if Sol.input().solve() else 'NO')
except Exception as e:
	print('Got exception:', repr(e))
	print(traceback.format_exc())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = []
	for i in range(100):
		d.append(0)
	f = 0
	for i in range(n):
		c = 0
		while l[i] > 0:
			ans = l[i] % k
			if ans > 1:
				f = 1
				break
			elif d[c] == 1 and ans != 0:
				f = 1
				break
			if ans == 1:
				d[c] = 1
			l[i] = l[i] // k
			c += 1
		if f == 1:
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


lim = 10 ** 16
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(filter(lambda x: x, map(int, input().split())))
	ks = []
	m = 1
	while m <= lim:
		ks.append(m)
		m *= k
	ks.reverse()
	narr = []
	for a in arr:
		while a > 0:
			for x in ks:
				if x <= a:
					narr.append(x)
					a -= x
					break
	print('NO' if len(narr) > len(set(narr)) else 'YES')


t = int(input())

def base_k(ch10, k0):
	res = []
	fl = True
	while fl:
		d = ch10 // k0
		ost = ch10 % k0
		ch10 = d
		if d == 0:
			fl = False
		res.append(ost)
	res.reverse()
	return res
for t0 in range(t):
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	f = True
	fr = True
	ind = 0
	sk = 0
	while f:
		a = A[ind]
		ak = base_k(a, k)
		if len(set(ak) - {0, 1}) > 0:
			f = False
			fr = False
		else:
			s = [str(x) for x in ak]
			sk1 = ''.join(s)
			if sk & int(sk1, 2) == 0:
				sk = int(sk1, 2) | sk
			else:
				fr = False
				f = False
		ind += 1
		if ind == n:
			f = False
	if fr:
		print('Yes')
	else:
		print('No')


T = int(input())
for loop in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	able = []
	i = 1
	while i <= max(a):
		dic[i] = 0
		able.append(i)
		i *= k
	able.reverse()
	ans = 'YES'
	for j in a:
		for x in able:
			if x <= j:
				if dic[x] > 0:
					ans = 'NO'
					break
				else:
					dic[x] = 1
					j -= x
		if j > 0 or ans == 'NO':
			ans = 'NO'
			break
	print(ans)


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	a = (*R(),)
	r = 0
	while any(a):
		(a, b) = zip(*(divmod(x, k) for x in a))
		r |= sum(b) > 1
	print('YNEOS'[r::2])


def get(num, k):
	n = 0
	while num % k == 0:
		num = num / k
		n += 1
	return (int(num), n)
t = input()
for i in range(int(t)):
	(n, k) = map(int, input().split())
	num = [int(n) for n in input().split()]
	line = []
	for i in range(0, 10000):
		line.append(0)
	judge = 1
	for j in range(0, n):
		if num[j] == 0 or judge == 0:
			continue
		if num[j] < k and num[j] % k != 0 and (num[j] != 1):
			judge = 0
		base = 0
		while num[j] != 0:
			(num[j], temp) = get(num[j], k)
			if temp != 0:
				base = base + temp
				if line[base] == 0:
					line[base] += 1
				else:
					judge = 0
			elif line[0] == 0:
				line[0] += 1
			else:
				judge = 0
			if num[j] % k != 1:
				judge = 0
			num[j] = num[j] - num[j] % k
	if judge == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	while any(a):
		flg = 0
		for i in range(n):
			if flg and a[i] % k == 1 or a[i] % k > 1:
				print('NO')
				break
			elif a[i] % k == 1:
				flg = 1
			a[i] //= k
		else:
			continue
		break
	else:
		print('YES')


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = [int(x) for x in stdin.readline().split()]
	arr = [int(x) for x in stdin.readline().split()]
	ma = max(arr)
	(exp, p) = (0, 1)
	while p <= ma:
		(exp, p) = (exp + 1, p * k)
	base = [[0 for _ in range(exp + 1)] for _ in range(n)]
	for e in range(exp, -1, -1):
		for i in range(n):
			base[i][e] = arr[i] // p
			arr[i] -= base[i][e] * p
		p = p // k
	flag = True
	for e in range(exp):
		a = 0
		for i in range(n):
			a += base[i][e]
		if a > 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


T = int(input())

def findNears(a, pows, j, used):
	while (a < pows[j] or j in used) and j < 64:
		j += 1
	return j
for t in range(T):
	(n, k) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	pows = [k ** i for i in range(64, -1, -1)]
	a = sorted(a)
	used = []
	ok = True
	for i in range(n - 1, -1, -1):
		j = 0
		while a[i] > 0:
			j = findNears(a[i], pows, j, used)
			if j in used:
				break
			used.append(j)
			a[i] -= pows[j]
		if a[i] != 0:
			ok = False
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
from collections import Counter
for i in range(t):
	inp = list(map(int, input().split()))
	n = inp[0]
	k = inp[1]
	inp = list(map(int, input().split()))
	c = Counter([])
	flag = 1
	j = len(inp) - 1
	while j >= 0:
		now = 0
		while inp[j] > 0:
			m = inp[j] % k
			if m != 0 and m != 1:
				flag = 0
				break
			elif m == 1:
				if c[now] == 1:
					flag = 0
					break
				else:
					c[now] = 1
			now += 1
			inp[j] = inp[j] // k
		j -= 1
		if flag == 0:
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


import bisect
from collections import defaultdict
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	power = [1]
	index = 1
	while power[-1] <= 10 ** 16:
		power.append(k ** index)
		index += 1
	l = list(map(int, input().split()))
	val = []
	flag = 0
	done = defaultdict(bool)
	for j in l:
		value = j
		while value != 0:
			x = bisect.bisect_left(power, value)
			if power[x] != value:
				x -= 1
			if done[x] == False:
				value -= k ** x
				val.append(x)
				done[x] = True
			else:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = math.floor(16 / math.log10(k))
	flag = True
	while cnt != -1:
		inc = 0
		for i in range(len(a)):
			if a[i] >= pow(k, cnt):
				inc += 1
				a[i] -= pow(k, cnt)
		if inc >= 2:
			print('NO')
			flag = False
			break
		cnt -= 1
	if flag:
		flag2 = True
		for i in a:
			if i != 0:
				print('NO')
				flag2 = False
		if flag2:
			print('YES')


import sys

def solve():
	t = int(sys.stdin.readline().strip())
	for tc in range(t):
		(n, k) = map(int, sys.stdin.readline().split())
		arr = list(map(int, sys.stdin.readline().split()))
		unique_arr = list(set(arr))
		arr = sorted(arr, reverse=True)
		S = sum(arr)
		temp = 0
		for i in arr:
			if i == 0:
				temp += 1
		if S == 0:
			print('YES')
			continue
		if k == 1:
			print('YES')
			continue
		if temp != 0:
			if len(arr) - (temp - 1) != len(unique_arr):
				print('No')
				continue
		temp = 1
		while True:
			if temp >= arr[0]:
				break
			temp *= k
		while temp >= 1:
			for i in range(n):
				if arr[i] >= temp:
					arr[i] -= temp
					break
			temp //= k
		if sum(arr) != 0:
			print('NO')
		else:
			print('YES')
solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	bits = [0] * 60
	for i in arr:
		j = 0
		while i:
			bits[j] += i % k
			i //= k
			j += 1
	for i in bits:
		if i > 1:
			print('NO')
			break
	else:
		print('YES')


import math
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	q = max(a)
	if q != 0:
		l = int(math.log(q, k)) + 1
		for j in range(0, l + 1):
			b.append(1)
		a.sort()
		flag = 0
		for j in range(n - 1, -1, -1):
			for p in range(l, -1, -1):
				if a[j] >= k ** p:
					if b[p] == 0:
						flag = 1
						break
					else:
						a[j] = a[j] - k ** p
						b[p] = 0
				if a[j] == 0:
					break
			if flag == 1 or a[j] != 0:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	f = 1
	while max(l) > 0:
		f = 1
		s = 0
		for i in range(n):
			s += l[i] % k
			if s > 1:
				f = 0
				break
			l[i] //= k
		if not f:
			break
	if f:
		print('YES')
	else:
		print('NO')


from math import log
lo = log
t = int(input())
while t != 0:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	flag = 0
	a = [int(i) for i in input().split()]
	power = 1
	powers = [1]
	while power < int(1e+17):
		power *= k
		powers.append(power)
	m = len(powers)
	powers.reverse()
	for i in range(n):
		for j in range(m):
			if a[i] - powers[j] >= 0:
				a[i] = a[i] - powers[j]
				powers[j] = 0
	print('YES' if sum(a) == 0 else 'NO')


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def kbins(v, k):
	c = []
	while v:
		c.append(v % k)
		v //= k
	p = []
	j = 0
	bl = True
	for i in c:
		if i == 1:
			p.append(j)
		elif i > 1:
			bl = False
		j += 1
	return (p, bl)
cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = {}
	f = 0
	for i in a:
		(b, bl) = kbins(i, k)
		if bl:
			for j in b:
				if j in d:
					f = 1
					break
				else:
					d[j] = True
		else:
			f = 1
		if f == 1:
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


def find_heigest(i, y):
	t = 0
	k = 0
	while i >= t:
		maxvalue = t
		t = y ** k
		k += 1
	return maxvalue
import math
N = int(input())
for i in range(N):
	(x, y) = map(int, input().split())
	L = list(map(int, input().split()))
	arraywithpowers = []
	key = 0
	t = 0
	while t < len(L):
		if L[t] != 0:
			if find_heigest(L[t], y) not in arraywithpowers:
				arraywithpowers.append(find_heigest(L[t], y))
				L.append(L[t] - find_heigest(L[t], y))
			elif key == 0:
				print('NO')
				key = 1
		t += 1
	if key == 0:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ma = max(a)
	p = 0
	while k ** p < ma:
		p += 1
	while p >= 0:
		count = 0
		for i in range(n):
			if a[i] >= k ** p:
				count += 1
				if count <= 1:
					a[i] -= k ** p
				else:
					break
		p -= 1
	if a.count(0) == n:
		print('YES')
	else:
		print('NO')


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * 100
	for x in a:
		i = 0
		while x:
			b[i] += x % k
			x //= k
			i += 1
	print('YES' if max(b) <= 1 else 'NO')
for _ in range(int(input())):
	solve()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(a)
	m = max(a)
	if m != 0:
		p = math.ceil(math.log(m, k))
	else:
		print('YES')
		continue
	flag = 'YES'
	for i in range(p, -1, -1):
		f = 0
		for j in range(n):
			if a[j] >= k ** i and f == 1:
				flag = 'NO'
				break
			if a[j] >= k ** i:
				a[j] -= k ** i
				f = 1
	if a != [0] * n:
		if n == 1 and b[0] == 1:
			print('YES')
		else:
			print('NO')
	else:
		print(flag)


from collections import defaultdict
t = int(input())

def decomp(l, k):
	lgs = []
	i = 0
	while l > 0:
		if l % k == 1:
			lgs.append(i)
		elif l % k > 1:
			return None
		l //= k
		i += 1
	return lgs
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	assert len(a) == n
	cnt = defaultdict(int)
	for z in a:
		res = decomp(z, k)
		if res == None:
			print('NO')
			break
		for r in res:
			cnt[r] += 1
	else:
		for (k, v) in cnt.items():
			if v > 1:
				print('NO')
				break
		else:
			print('YES')


t = int(input())

def POWERS(x, k):
	p = 0
	powers = {}
	cur = 0
	while x != 0:
		powers[cur] = x % k
		x //= k
		cur += 1
	res = set()
	for (key, val) in powers.items():
		if val == 1:
			res.add(key)
		elif val > 1:
			return -1
	return res
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	As = list(map(int, input().split()))
	sofar = set()
	flag = True
	for a in As:
		mb = POWERS(a, k)
		if mb == -1:
			print('NO')
			flag = False
			break
		elif len(mb.intersection(sofar)) != 0:
			print('NO')
			flag = False
			break
		else:
			for m in mb:
				sofar.add(m)
	if flag:
		print('YES')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	flag = False
	for i in range(n):
		while a[i] > 1:
			temp = math.ceil(math.log(a[i], k))
			while k ** temp > a[i]:
				temp -= 1
			if temp in d:
				flag = True
			else:
				d[temp] = i
			a[i] -= k ** temp
		if a[i] == 1:
			if 0 in d:
				flag = True
			else:
				a[i] = 0
				d[0] = i
		if flag:
			break
	if flag:
		print('NO')
	else:
		for i in a:
			if i != 0:
				print('NO')
				break
		else:
			print('YES')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	targ = list(map(int, input().split()))
	i = 0
	maxy = max(targ)
	while maxy >= k:
		maxy = maxy // k
		i += 1
	for s in range(i, -1, -1):
		val = k ** s
		for m in range(n):
			if targ[m] >= val:
				targ[m] -= val
				break
	minval = max(targ)
	if minval == 0:
		print('YES')
	else:
		print('NO')


import math
a = int(input())
ans = []
for i in range(a):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = 'YES'
	r = max(l)
	if r > 0:
		t = int(math.log(r, k)) + 1
	else:
		ans.append('YES')
		continue
	u = [z for z in range(t, -1, -1)]
	for j in l:
		if j == 0:
			continue
		s = []
		for c in u:
			if k ** c <= j:
				j -= k ** c
				s.append(c)
		for c in s:
			u.remove(c)
		if j != 0:
			d = 'NO'
	ans.append(d)
for i in ans:
	print(i)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	cnt = 0
	while k ** cnt <= 10 ** 16:
		cnt += 1
	for i in range(cnt, -1, -1):
		num = k ** i
		for j in range(n):
			if arr[j] >= num:
				arr[j] = arr[j] - num
				break
	if sum(arr) > 0:
		print('NO')
	else:
		print('YES')


def convert(n, base):
	a = '01'
	if n < base:
		if n % base >= 2:
			return False
		return a[n % base]
	else:
		if n % base >= 2:
			return False
		x = convert(n // base, base)
		if x:
			return x + a[n % base]
		return False
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = {}
	fl = True
	for i in a:
		x = convert(i, k)
		if x:
			for j in range(len(x)):
				if x[j] == '1':
					if len(x) - j in cnt:
						fl = False
						break
					cnt[len(x) - j] = 1
			if not fl:
				break
		else:
			fl = False
			break
	if fl:
		print('YES')
	else:
		print('NO')


from itertools import accumulate
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	kp = [k ** i for i in range(61)]
	kp = kp[::-1]
	for j in kp:
		a = sorted(a)[::-1]
		if a[0] >= j:
			a[0] -= j
	if a != [0] * n:
		print('NO')
	else:
		print('YES')


import bisect

def powSum(num, k, arr):
	if num == 0:
		return
	if num < 0:
		return
	i = 0
	while pow(k, i) <= num:
		i += 1
	i -= 1
	num -= pow(k, i)
	arr.append(i)
	powSum(num, k, arr)
arr = []
t = int(input())
for _ in range(t):
	superSet = set()
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	flag = True
	for num in a:
		arr = []
		powSum(num, k, arr)
		sa = set(arr)
		if len(sa) != len(arr):
			print('NO')
			flag = False
			break
		else:
			inter = superSet.intersection(sa)
			if len(inter) > 0:
				print('NO')
				flag = False
				break
			else:
				for e in sa:
					superSet.add(e)
	if flag:
		print('YES')


def getRep(base, num):
	result = []
	while num > 0:
		result.append(num % base)
		num //= base
	answer = [0] * 60
	index = len(answer) - 1
	for i in result:
		answer[index] = i
		index -= 1
	return answer

def solve(n, k, a):
	seen = set()
	for val in a:
		if val == 0:
			continue
		rep = getRep(k, val)
		for (i, power) in enumerate(rep):
			if power > 1:
				return False
			if power > 0:
				if i in seen:
					return False
				seen.add(i)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if solve(n, k, a):
		print('YES')
	else:
		print('NO')


from math import log
from collections import defaultdict as dd
t = int(input())
while t:
	lol = 0
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dd(int)
	for i in range(n):
		a = l[i]
		if a % k != 0:
			if d[0] == 0:
				a -= 1
				d[0] = 1
			if a % k != 0:
				lol = 1
				break
		while a:
			if a % k == 0:
				cou = 0
				aa = a
				while aa % k == 0:
					cou += 1
					aa = aa // k
				if d[cou] != 0:
					lol = 1
					break
				a = a - k ** cou
				d[cou] = 1
			else:
				a -= 1
				if a % k != 0:
					lol = 1
					break
		if lol:
			break
	if lol:
		print('NO')
	else:
		print('YES')
	t -= 1


from math import log

def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	(n, k) = I()
	a = I()
	if a == [0] * n:
		print('YES')
	else:
		used = [0] * int(log(max(a), k) + 2)
		f = 0
		currUsed = []
		for ai in a:
			d = 0
			c = 0
			while ai >= 1:
				d = ai % k
				ai = ai // k
				if d == 1:
					if used[c]:
						f = 1
						break
					else:
						used[c] = 1
						c += 1
					continue
				elif d == 0:
					c += 1
					continue
				else:
					break
			if f:
				print('NO')
				break
			if not (d == 1 or d == 0):
				print('NO')
				f = 1
				break
		if not f:
			print('YES')


num = int(input())
for _ in range(num):
	(n, k) = map(int, input().split())
	ex = list(map(int, input().split()))
	b = []
	for i in ex:
		if i != 0:
			b.append(i)
	b.sort()
	l = set()
	flag = True
	for i in b:
		x = i
		cnt = 0
		while x > 0:
			if x % k == 0:
				x //= k
				cnt += 1
			elif (x - 1) % k == 0:
				x = (x - 1) // k
				if cnt in l:
					flag = False
					break
				l.add(cnt)
				cnt += 1
			else:
				flag = False
				break
			if x == 1:
				if cnt in l:
					flag = False
					break
				l.add(cnt)
				break
		if flag is False:
			break
	print('YES' if flag else 'NO')


from collections import defaultdict
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	d = defaultdict(int)
	f = 0
	for i in range(n):
		p = list1[i]
		count = 0
		while p > 0:
			while p % k == 0 and p > 0:
				p = p // k
				count += 1
			d[count] += 1
			if d[count] > 1:
				f = 1
				break
			p -= 1
		if f == 1:
			break
	if f == 0:
		print('YES')
	else:
		print('NO')
	t -= 1


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	m = max(a)
	mk = 0
	while k ** mk <= m:
		mk += 1
	mk -= 1
	u = [False] * (mk + 1)
	f = True
	for i in range(n):
		if a[i] == 0:
			continue
		for j in range(mk, -1, -1):
			if u[j] or k ** j > a[i]:
				continue
			a[i] -= k ** j
			u[j] = True
		if a[i]:
			f = False
			break
	print('Yes' if f else 'No')


def solve(n):
	global total
	necessarios = set()
	cont = 0
	while n:
		temp = n // k
		if n % k == 1:
			necessarios.add(cont)
			total += 1
		elif n % k > 1:
			return False
		cont += 1
		n = temp
	return necessarios
for _ in range(int(input())):
	total = 0
	(n, k) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	ans = set()
	for i in l:
		a = solve(i)
		if a == False:
			print('NO')
			break
		ans = ans.union(a)
	else:
		if len(ans) != total:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if a[n - 1] == 0:
		print('YES')
		continue
	temp = 1
	flag = True
	while temp < a[n - 1]:
		temp *= k
	while temp >= 1:
		if a[n - 1] >= temp:
			a[n - 1] -= temp
			a.sort()
		temp //= k
	for i in a:
		if i != 0:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


test = int(input())
for t in range(test):
	inps = list(map(int, input().split()))
	(n, k) = (inps[0], inps[1])
	Li = list(map(int, input().split()))
	till = 0
	maxx = max(Li)
	if maxx == 0:
		print('YES')
		continue
	while maxx > k ** till:
		till += 1
	for x in range(till, -1, -1):
		idx = Li.index(max(Li))
		if Li[idx] >= k ** x:
			Li[idx] = Li[idx] - k ** x
	if sum(Li) == 0:
		print('YES')
	else:
		print('NO')


import math
from collections import defaultdict
x = int(input())
for _ in range(x):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	f = True
	d = defaultdict(int)
	for i in a:
		j = 0
		while i > 0:
			if i % m == 0:
				i //= m
			elif i % m == 1:
				if d[j] != 0:
					f = False
					break
				i //= m
				d[j] = 1
			else:
				f = False
				break
			j += 1
		if not f:
			break
	if f:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	used = []
	f = 1
	for i in range(n):
		p = a[i]
		c = 0
		while p != 0:
			if p % k == 0:
				p = p // k
				c += 1
			elif (p - 1) % k == 0:
				p = (p - 1) // k
				if c in used:
					f = 0
					break
				else:
					used.append(c)
					c += 1
			else:
				f = 0
				break
		if f == 0:
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


def examA():
	T = I()
	ans = []
	for _ in range(T):
		(N, M) = LI()
		if N % M != 0:
			ans.append('NO')
		else:
			ans.append('YES')
	for v in ans:
		print(v)
	return

def examB():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		A = LI()
		A.sort()
		ans.append(A[::-1])
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examC():
	T = I()
	ans = []
	for _ in range(T):
		(N, K) = LI()
		A = LI()
		sumA = sum(A)
		if sumA == 0:
			ans.append('YES')
			continue
		cur = 0
		L = []
		for i in range(100):
			now = K ** i
			L.append(now)
			cur += now
			if cur >= sumA:
				break
		for i in range(N):
			A[i] *= -1
		heapify(A)
		for l in L[::-1]:
			if not A:
				break
			a = -heappop(A)
			if a < l:
				heappush(A, -a)
			elif a > l:
				heappush(A, -(a - l))
		if not A or heappop(A) == 0:
			ans.append('YES')
		else:
			ans.append('NO')
	for v in ans:
		print(v)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
import sys, copy, bisect, itertools, heapq, math, random
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
examC()


def convert_to_k_system(num):
	pos = 0
	while num > 0:
		rem = num % k
		num = num // k
		if rem == 1 and visited[pos] == 0:
			visited[pos] = 1
		elif rem == 1 and visited[pos] == 1:
			return False
		elif rem > 1:
			return False
		pos += 1
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	visited = list(bytearray(100))
	arr = list(map(int, input().split()))
	flag = True
	for i in range(n):
		if not convert_to_k_system(arr[i]):
			print('NO')
			flag = False
			break
	if flag:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	used = set()
	possible = True
	for el in a:
		p = 0
		while el > 0:
			digit = el % k
			if digit > 0:
				if digit > 1 or p in used:
					possible = False
					break
				else:
					used.add(p)
			p += 1
			el //= k
		if not possible:
			print('NO')
			break
	if possible:
		print('YES')


from bisect import bisect_right
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())), reverse=True)
	ps = []
	for i in range(0, 100):
		u = k ** i
		if u <= a[0]:
			ps.append(u)
		else:
			break
	u = 0
	used = []
	for i in a:
		if i == 0:
			continue
		else:
			while i > 0:
				pos = bisect_right(ps, i)
				i -= ps[pos - 1]
				used.append(pos - 1)
				if i < 0:
					u = 1
					break
		if u == 1:
			break
	used = sorted(used)
	for i in range(0, len(used) - 1):
		if used[i] == used[i + 1]:
			u = 1
	if u == 1:
		print('NO')
	else:
		print('YES')


import bisect
tc = int(input())

def check(target, k):
	max_val = max(target)
	i = 1
	kth = 1
	powers = [kth]
	while kth < max_val:
		kth *= k
		i += 1
		powers.append(kth)
	stat = [0] * i
	for v in target:
		while v:
			kth = 1
			idx = bisect.bisect_right(powers, v) - 1
			if idx >= 0:
				stat[idx] += 1
			if stat[idx] > 1:
				return False
			v -= powers[idx]
	return True
for _ in range(tc):
	(n, k) = map(int, input().split())
	(*target,) = map(int, input().split())
	if check(target, k):
		print('YES')
	else:
		print('NO')


t = int(input())
a = []
for i in range(t):
	(N, K) = map(int, input().split())
	p = list(map(int, input().split()))
	a.append([p, [N, K]])
for i in a:
	f = 0
	j = i[0]
	k = i[1][1]
	n = i[1][0]
	j.sort()
	c = []
	for p in j:
		if p == 0:
			pass
		else:
			m = 0
			while p != 0:
				r = p % k
				p = p // k
				if r == 1 or r == 0:
					pass
				else:
					f = -1
					break
				if r == 1 and m in c:
					f = -1
					break
				if r == 1:
					c.append(m)
				m += 1
			if f == -1:
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def baseconv(num, k):
	if num == 0:
		return []
	return [num % k] + baseconv((num - num % k) // k, k)
t = int(input())
for _ in range(t):
	ans = True
	(n, k) = map(int, input().split())
	want = list(map(int, input().split()))
	pos = [0 for i in range(100)]
	for i in range(n):
		if ans:
			conv = baseconv(want[i], k)
			for b in range(len(conv)):
				if conv[b] == 1:
					pos[b] += 1
				if pos[b] > 1 or conv[b] > 1:
					ans = False
					break
	print('YES' if ans else 'NO')


def f():
	(n, k) = [int(s) for s in input().split()]
	A = [int(s) for s in input().split()]
	memo = [1] * 100
	for a in A:
		B = []
		while a:
			B.append(a % k)
			a //= k
		for (i, b) in enumerate(B):
			memo[i] -= b
			if memo[i] < 0:
				print('NO')
				return
	print('YES')
	return
t = int(input())
for i in range(t):
	f()


def calc(n, r):
	if n < r:
		return 0
	return 1 + calc(n // r, r)
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	flag = 0
	for i in a:
		temp = i
		while temp // k != 0:
			b = int(calc(temp, k))
			if b in d:
				flag = 1
				break
			else:
				d[b] = 1
			temp = temp - k ** b
		if flag == 1:
			break
		if temp > 1:
			flag = 1
			break
		elif temp == 1:
			if 0 in d:
				flag = 1
				break
			else:
				d[0] = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = []
	s = 0
	for i in range(len(a)):
		if s == 1:
			break
		while a[i] != 0:
			j = 0
			while k ** j <= a[i]:
				j += 1
			a[i] -= k ** (j - 1)
			x += [j - 1]
			if x.count(j - 1) > 1:
				s = 1
				break
	if s == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

def lint():
	return list(map(int, input().split()))

def fint():
	return list(map(int, stdin.readline().split()))

def main():
	(n, k) = map(int, input().split())
	cnt = [0] * 100
	for i in lint():
		for j in range(60):
			cnt[j] += i % k
			i //= k
	for i in cnt:
		if i > 1:
			print('NO')
			break
	else:
		print('YES')
t = int(input())
for i in range(t):
	main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(item) for item in input().split()]
	b = []
	ok = True
	for item in a:
		ret = 0
		shift = 0
		while item > 0:
			if item % k > 1:
				ok = False
			else:
				ret |= item % k << shift
			item //= k
			shift += 1
		b.append(ret)
	if not ok:
		print('NO')
		continue
	val = 0
	for item in b:
		if val & item:
			ok = False
			break
		val |= item
	if not ok:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()

def getStep(x, k):
	step = 0
	while k ** step <= x:
		step += 1
	return step - 1
t = getInt()
for _ in range(t):
	(n, k) = getVars()
	a = getList()
	steps = []
	a.sort(reverse=True)
	res = 'YES'
	while a[0] > 0:
		step = getStep(a[0], k)
		if step in steps:
			res = 'NO'
			break
		a[0] -= k ** step
		a.sort(reverse=True)
		steps.append(step)
	print(res)


def fun(n, k):
	s = ''
	while n > 0:
		s = s + str(n % k)
		if n % k > 1:
			return False
		n = n // k
	j = 0
	for i in s:
		if i == '1':
			if check[j] == 1:
				return False
			else:
				check[j] = 1
		j += 1
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check = [0 for i in range(55)]
	a = list(map(int, input().split()))
	ans = True
	for i in a:
		if not fun(i, k):
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


def max_p(x, k):
	product = 1
	while product <= x:
		product *= k
	return product // k
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	possible = True
	powers = {}
	for i in a:
		x = i
		while True:
			if x != 0:
				power = max_p(x, k)
				if power not in powers:
					powers[power] = 1
				else:
					powers[power] += 1
					possible = False
					break
				x = x - power
			else:
				break
		if possible == False:
			break
	if possible == True:
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for test in range(0, t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	p = 1
	ind = 0
	while p <= a[0]:
		p *= k
		ind += 1
	f = False
	for i in range(0, ind):
		p = int(p / k)
		if len(a) > 1 and a[0] >= p and (a[1] >= p):
			f = True
			break
		elif a[0] < p:
			continue
		else:
			a[0] -= p
			if len(a) > 1 and a[0] < a[1]:
				a.sort(reverse=True)
		if a[0] == 0:
			break
	if a[0] > 0:
		f = True
	if f:
		print('NO')
	else:
		print('YES')


def main():
	for i in range(int(input())):
		(array, number) = case1312c()
		print(ifPossibleToMake(array, number))

def case1312c():
	(nValues, number) = map(int, input().split())
	array = tuple(map(int, input().split()))
	return (array, number)

def ifPossibleToMake(array, number):
	usedPowers = set()
	for value in array:
		power = 0
		while value:
			remainder = value % number
			if remainder == 1:
				value -= 1
				if power in usedPowers:
					return 'NO'
				usedPowers.add(power)
			elif remainder:
				return 'NO'
			value /= number
			power += 1
	return 'YES'
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	bits = set()
	flag = True
	for i in a:
		j = 0
		while i:
			m = i % k
			i //= k
			if m >= 2:
				flag = False
				break
			elif m == 1:
				if j in bits:
					flag = False
					break
				else:
					bits.add(j)
			j += 1
		if not flag:
			break
	print('YES' if flag else 'NO')


from math import ceil, sqrt, log, floor, pi
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	List = [int(x) for x in input().split()]
	StartPower = int(ceil(log(10 ** 16, K)))
	Visited = [False] * (StartPower + 1)
	flag = 0
	for i in range(N):
		CopyPower = StartPower
		val = List[i]
		while val != 0:
			if val >= K ** CopyPower:
				val -= K ** CopyPower
				if Visited[CopyPower]:
					flag = 1
					print('NO')
					break
				else:
					Visited[CopyPower] = True
			CopyPower -= 1
		if flag:
			break
	if not flag:
		print('YES')


import math
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))

def base(b, k):
	s = []
	while b:
		s.append(b % k)
		b //= k
	return s
for _ in range(I()):
	(n, k) = M()
	a = LI()
	d = defaultdict(int)
	for i in range(n):
		s = base(a[i], k)
		for j in range(len(s)):
			d[j] += s[j]
	flag = 1
	for i in d.values():
		if i > 1:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict
from math import log10

def solve(num, k, seen):
	max_power = int(log10(num) / log10(k)) + 3
	for i in range(max_power, -1, -1):
		if k ** i <= num:
			if seen[i]:
				return False
			num -= k ** i
			seen[i] = True
	return num == 0

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().strip().split()))
		arr = list(map(int, input().strip().split()))
		a = []
		for num in arr:
			if num:
				a.append(num)
		a.sort()
		seen = [False for _ in range(64)]
		f = False
		for num in a:
			if not solve(num, k, seen):
				f = True
				break
		if f:
			print('NO')
		else:
			print('YES')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt = 0
	while k ** cnt <= 10 ** 16:
		cnt += 1
	while cnt >= 0:
		f = 0
		temp = 0
		for i in range(n):
			if l[i] >= k ** cnt:
				temp += 1
				l[i] -= k ** cnt
		if temp > 1:
			f = 1
			break
		cnt -= 1
	if f == 0 and l.count(0) == n:
		print('YES')
	else:
		print('NO')


import io
import os
from collections import defaultdict, deque, Counter

def solve(N, K, A):
	m = max(A)
	base = 1
	while base <= m:
		base *= K
	while base != 0:
		num = 0
		for i in range(N):
			if base <= A[i]:
				A[i] -= base
				num += 1
		if num > 1:
			return 'NO'
		base //= K
	if not all((x == 0 for x in A)):
		return 'NO'
	return 'YES'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	ans = solve(N, K, A)
	print(ans)


T = int(input())
for i in range(0, T * 2, 2):
	NK = input()
	[N, K] = NK.split()
	N = int(N)
	K = int(K)
	arr = list(map(int, input().split()))
	used = set()
	impossible = False
	for x in arr:
		temp = 0
		if x == 0:
			continue
		while x > 0:
			if x % K == 0:
				temp += 1
				x = x // K
			elif temp in used:
				impossible = True
				break
			else:
				x = x - 1
				used.add(temp)
		if impossible:
			break
	print('NO' if impossible else 'YES')


def answer(k, target):
	ithSteps = []
	maxStep = 1
	for i in range(len(target)):
		ithStep = []
		if target[i] < k:
			if target[i] != 0 and target[i] != 1:
				return 'NO'
			ithStep.append(target[i])
			ithSteps.append(ithStep)
		else:
			if target[i] % k != 0 and (target[i] - 1) % k != 0:
				return 'NO'
			while True:
				rest = target[i] % k
				if rest != 0 and rest != 1:
					return 'NO'
				target[i] = int((target[i] - rest) / k)
				ithStep.append(rest)
				if target[i] == 1:
					ithStep.append(1)
					ithSteps.append(ithStep)
					if maxStep < len(ithStep):
						maxStep = len(ithStep)
					break
	for i in range(maxStep):
		colSum = 0
		for j in range(len(ithSteps)):
			if len(ithSteps[j]) > i:
				colSum += ithSteps[j][i]
				if colSum > 1:
					return 'NO'
	return 'YES'
testCount = int(input())
for _ in range(testCount):
	(n, k) = map(int, input().split())
	target = list(map(int, input().split()))
	print(answer(k, target))


from math import log
t = int(input())

def convert(x, k):
	ans = ''
	s = [str(i) for i in range(2, k)]
	while x != 0:
		ans += str(x % k)
		if str(x % k) in s:
			return '-1'
		x = x // k
	return ans[::-1]
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	lt = [int(x) for x in input().split()]
	l = int(log(10 ** 16) // log(k)) + 1
	flag = True
	for i in range(n):
		p = convert(lt[i], k)
		if p == '-1':
			flag = False
			continue
		p = '0' * (l - len(p)) + p
		lt[i] = p
	if flag == False:
		print('NO')
	else:
		aux = ['' for _ in range(l)]
		for i in range(l):
			for j in range(n):
				aux[i] += lt[j][i]
		for i in range(l):
			if aux[i].count('1') > 1:
				flag = False
		if flag == False:
			print('NO')
		else:
			print('YES')


def test(a, n, k):
	while max(a) > 0:
		s = 0
		for i in range(n):
			s += a[i] % k
			if s > 1:
				return False
			a[i] = a[i] // k
	return True
cases = int(input())
for i in range(cases):
	(n, k) = (int(x) for x in input().split(' '))
	a = [int(x) for x in input().split(' ')]
	print('YES' if test(a, n, k) else 'NO')


def solve():
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	maks = 0
	l = []
	for x in p:
		pot = k
		cnt = 0
		while x:
			maks = max(maks, x % pot)
			if x % pot:
				l.append(cnt)
			x = x // k
			cnt += 1
	l = sorted(l)
	for i in range(len(l) - 1):
		if l[i] == l[i + 1] or maks > 1:
			print('NO')
			return
	if maks > 1:
		print('NO')
	else:
		print('YES')
t = int(input())
for i in range(t):
	solve()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def reVal(num):
	if num >= 0 and num <= 9:
		return chr(num + ord('0'))
	else:
		return chr(num - 10 + ord('A'))

def strev(str):
	len = len(str)
	for i in range(int(len / 2)):
		temp = str[i]
		str[i] = str[len - i - 1]
		str[len - i - 1] = temp

def fromDeci(res, base, inputNum):
	index = 0
	while inputNum > 0:
		res += reVal(inputNum % base)
		inputNum = int(inputNum / base)
	res = res[::-1]
	return res

def norm(s, l):
	tba = '0' * (l - len(s))
	return tba + s
for xyz in range(0, int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	le = []
	for i in l:
		if i != 0:
			le.append(i)
	l = le.copy()
	bm = []
	for i in l:
		bm.append(fromDeci('', k, i))
	if len(l) == 0:
		print('YES')
	else:
		f = True
		ma = max(l)
		n = len(l)
		for i in range(0, n):
			bm[i] = norm(bm[i], int(math.log(ma, k)) + 2)
		for i in bm:
			if f:
				for j in i:
					if j != '1' and j != '0':
						f = False
						break
		if f:
			cnt = [0] * len(bm[0])
			for i in bm:
				for j in range(0, len(i)):
					cnt[j] += int(i[j])
			if max(cnt) > 1:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = [int(i) for i in input().split()]
	B = [0] * 100
	for a in A:
		ct = 0
		while a:
			B[ct] += a % k
			a //= k
			ct += 1
	print('YES' if max(B) <= 1 else 'NO')


MAX = 500

def into_k_reversed(a, k):
	ret = [0 for _ in range(MAX)]
	i = 0
	while a > 0:
		ret[i] = a % k
		a //= k
		i += 1
	return ret

def test_into_k_reversed():
	print(into_k_reversed(15, 9))
t = int(input())
ans = [False for _ in range(t)]
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	cnt = [0 for _ in range(MAX)]
	ans_i = True
	for a_j in a:
		if not ans_i:
			break
		s = into_k_reversed(a_j, k)
		for l in range(MAX):
			if not ans_i:
				break
			if s[l] == 0:
				continue
			if s[l] == 1:
				if cnt[l] == 1:
					ans_i = False
				else:
					cnt[l] = 1
				continue
			ans_i = False
	if ans_i:
		ans[i] = True
for a in ans:
	if a:
		print('YES')
	else:
		print('NO')


import math, collections, sys
input = sys.stdin.readline

def getBits(a, k):
	z = []
	while a:
		z.append(a % k)
		a //= k
	return z

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = collections.defaultdict(int)
	for i in a:
		z = getBits(i, k)
		for j in range(len(z)):
			d[j] += z[j]
	for i in d.values():
		if i > 1:
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	solve()


def dig(x, k):
	st = [0] * 55
	for i in range(55, -1, -1):
		if x >= k ** i:
			st[i] = x // k ** i
			x %= k ** i
		if x == 0:
			break
	return st
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = [0] * 55
	for x in a:
		st = dig(x, k)
		for i in range(55):
			ans[i] += st[i]
	if max(ans) >= 2:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	d = dict()
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = False
	for i in range(n):
		if ans:
			break
		if a[i] == 0:
			continue
		if a[i] != 1 and a[i] < k:
			print('NO')
			ans = True
			break
		digits = []
		while a[i]:
			digits.append(int(a[i] % k))
			a[i] //= k
		for j in range(len(digits) - 1, -1, -1):
			if digits[j] == 0:
				continue
			if digits[j] == 1:
				if j in d.keys():
					print('NO')
					ans = True
					break
				d[j] = 1
			else:
				print('NO')
				ans = True
				break
	if ans:
		continue
	else:
		print('YES')


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def modpow(b, p, m):
	res = 1
	b = b % m
	while p:
		if p & 1:
			res = res * b % m
		b = b * b % m
		p >>= 1
	return res

def mod_inv(a, m):
	return modpow(a, m - 2, m)

def ncr(n, r, m):
	res = 1
	if r == 0:
		return 1
	if n - r < r:
		r = n - r
	(p, k) = (1, 1)
	while r:
		res = res % m * (n % m * mod_inv(r, m) % m) % m
		n -= 1
		r -= 1
	return res

def ncrlis(n, r, m, fact):
	return fact[n] * (mod_inv(fact[r], m) * mod_inv(fact[n - r], m)) % m % m

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(ii()):
	(n, k) = mi()
	a = li()
	f = 0
	powr = [k ** (54 - i) for i in range(55)]
	check = [0 for i in range(55)]
	for i in range(n):
		for j in range(55):
			if a[i] >= powr[j]:
				a[i] -= powr[j]
				check[j] += 1
		if a[i]:
			f = 1
			break
	for i in range(55):
		if check[i] > 1:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
import bisect
for xoxo in range(1):
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		p = sum(a)
		b = [1]
		i = 1
		while b[-1] < p:
			b.append(k ** i)
			i += 1
		ans = 0
		a.sort()
		c = [0] * len(b)
		for p in a:
			if len(b) == 0:
				ans = -1
				break
			while p != 0:
				i = bisect.bisect_right(b, p)
				p -= b[i - 1]
				if c[i - 1] == 0:
					c[i - 1] = 1
				else:
					ans = -1
					break
				if p < 0:
					ans = -1
					break
			k = 0
			for j in range(len(c)):
				if c[j] == 0:
					b[k] = b[j]
					k += 1
			b = b[:k]
			c = [0] * len(b)
			if ans == -1:
				break
		if ans == -1:
			print('NO')
		else:
			print('YES')


t = int(input(''))
while t > 0:
	(n, k) = input('').split()
	n = int(n)
	k = int(k)
	g = []
	l = list(map(int, input().split()))
	d = max(l)
	j = 0
	e = 0
	c = 0
	while k ** j <= d:
		e = j
		j += 1
	for i in range(0, len(l)):
		s = ''
		for j in range(e + 1, -1, -1):
			if k ** j <= l[i]:
				l[i] = l[i] - k ** j
				s = s + '1'
			else:
				s = s + '0'
			if l[i] == 0:
				for q in range(j - 1, -1, -1):
					s = s + '0'
				g.append(s)
				break
		if l[i] > 0:
			print('NO')
			c = 1
			break
	if c == 0:
		sum = 0
		u = 0
		for i in g:
			sum = sum + int(i)
			h = str(sum)
			for i in h:
				if int(i) > 1:
					print('NO')
					c = 1
					u = 1
					break
			if u == 1:
				break
		if c == 0:
			print('YES')
	t = t - 1


testCases = int(input())
for i1 in range(testCases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	count = {}
	all = []
	result = 'YES'
	for i2 in a:
		temp = []
		while i2 > k - 1:
			temp.append(i2 % k)
			i2 = i2 // k
		temp.append(i2)
		for i3 in range(0, len(temp), 1):
			if i3 in count.keys():
				count[i3] += temp[i3]
			else:
				count[i3] = temp[i3]
	for i2 in count.values():
		if i2 > 1:
			result = 'NO'
			break
	print(result)


def covert_bin(num, d):
	s1 = ''
	while num > 0:
		rem = num % d
		num = num // d
		if rem > 1:
			return '-1'
		else:
			s1 += str(rem)
	return s1
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	odds = 0
	even = 0
	occupied = [0] * 100
	lis = []
	flag = 0
	for i in arr:
		s = covert_bin(i, k)
		lis.append(s)
		lis.append(s)
		if s == '-1':
			flag = 1
			break
		else:
			for j in range(len(s)):
				if s[j] == '1':
					if occupied[j] == 1:
						flag = 1
						break
					else:
						occupied[j] = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	if max(l) == 0:
		print('YES')
	else:
		x = math.ceil(math.log(max(l), k))
		while x >= 0:
			for i in range(n):
				if l[i] >= k ** x:
					l[i] -= k ** x
					break
			x -= 1
		if max(l) == 0:
			print('YES')
		else:
			print('NO')


from math import log

def check(x, k):
	a = []
	tmp = x
	while tmp != 0:
		a.append(tmp % k)
		tmp //= k
	return a

def solve():
	(_, k) = map(int, input().split())
	a = list(map(int, input().split()))
	test = [0] * 54
	for x in a:
		if x == 0:
			continue
		tmp = check(x, k)
		for i in range(len(tmp)):
			test[i] += tmp[i]
			if test[i] > 1:
				print('NO')
				return
	print('YES')
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	numbers = list(map(int, input().split()))
	pows = [0] * 65
	for num in numbers:
		for i in range(64):
			if num % k:
				pows[i] += num % k
			num //= k
	print('YES' if max(pows) <= 1 else 'NO')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())

def conv(num, n):
	ret = []
	while num > 0:
		ret.append(num % n)
		num = num // n
	return ret
t = oint()
for _ in range(t):
	(n, k) = rint()
	a = list(rint())
	used_bits = [0] * 100
	flag = 0
	for i in range(n):
		aa = a[i]
		tmp = conv(aa, k)
		for j in range(len(tmp)):
			if tmp[j] == 1:
				if used_bits[j]:
					flag = 1
					break
				else:
					used_bits[j] = 1
			elif tmp[j] == 0:
				continue
			else:
				flag = 1
				break
		if flag:
			break
	if flag:
		print('NO')
	else:
		print('YES')


def conv(num, b):
	if num < b:
		return str(num)
	else:
		return conv(num // b, b) + ' ' + str(num % b)
t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split(' ')))
	num = list(map(int, input().split(' ')))
	sum = 0
	flag = 0
	prev_list = []
	for i in num:
		if i == 0:
			pass
		else:
			convert = list(map(int, conv(i, k).split(' ')))
			convert.reverse()
			for j in range(len(convert)):
				if convert[j] > 1:
					flag = 1
					break
				if j < len(prev_list):
					if prev_list[j] == 1 and convert[j] == 1:
						flag = 1
						break
					elif prev_list[j] == 0 and convert[j] == 1:
						prev_list[j] = 1
				else:
					prev_list.append(convert[j])
		if flag == 1:
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(n, base) = map(int, input().split())
	a = list(map(int, input().split()))
	frecv = [0] * 64
	for i in range(n):
		nr = 0
		while a[i] > 0:
			frecv[nr] += a[i] % base
			a[i] //= base
			nr += 1
	for i in range(63, 0, -1):
		if frecv[i] > 1:
			frecv[i - 1] += (frecv[i] - 1) * base
			frecv[i] = 1
	ok = True
	for i in range(0, 63):
		if frecv[i] > 1:
			ok = False
	if ok == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	works = True
	used = [0] * 100
	for i in range(n):
		cur = 0
		po1 = 1
		po2 = k
		j = 0
		while po1 <= a[i]:
			if a[i] % po2 != 0:
				if used[j] == 1:
					works = False
				else:
					used[j] = 1
					a[i] -= po1
				if a[i] % po2 != 0:
					works = False
			po1 *= k
			po2 *= k
			j += 1
	if works:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	arr = [0 for i in range(54)]
	key = 0
	for i in range(n):
		p = a[i]
		po = 54
		while p > 0 and po >= 0:
			if k ** po <= p and arr[po] == 0:
				p -= k ** po
				arr[po] = 1
			else:
				po -= 1
		if p > 0:
			key = 1
			break
		else:
			continue
	if key == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	count = [0 for i in range(60)]
	for num in l:
		j = 0
		while num:
			count[j] += num % k
			j += 1
			num = num // k
	for i in count:
		if i > 1:
			print('NO')
			break
	else:
		print('YES')


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(n, k) = num()
		tp = 1
		op = []
		a = li()
		while tp <= max(a):
			op.append(tp)
			tp *= k
		zp = []
		fl = True
		for i in range(n):
			if a[i] == 0:
				continue
			x = a[i]
			ff = len(op) - 1
			while ff >= 0 and x != 0:
				if op[ff] <= x:
					zp.append(ff)
					x -= op[ff]
				ff -= 1
			if x != 0:
				fl = False
		zp.sort()
		for i in range(1, len(zp)):
			if zp[i] == zp[i - 1]:
				fl = False
		if fl:
			print('Yes')
		else:
			print('No')
solve()


import math

def solve(n, exp, arr):
	if max(arr) == 0:
		return 'YES'
	start = math.ceil(math.log(max(arr), exp))
	if exp ** start > max(arr):
		start -= 1
	while True:
		if start < 0:
			break
		current = exp ** start
		found = 0
		for index in range(len(arr)):
			if arr[index] >= current:
				found += 1
				arr[index] -= current
		if found > 1:
			return 'NO'
		start -= 1
	for num in arr:
		if num > 0:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, exp) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(solve(n, exp, arr))


from math import ceil, log
from sys import stdin

def toKBase(n, k, d):
	for _ in range(d + 1):
		yield (n % k)
		n //= k

def solve(arr, k):
	if max(arr) == 0:
		return True
	digit = ceil(log(max(arr), k))
	return all(map(lambda ls: sum(ls) <= 1, zip(*map(lambda n: tuple(toKBase(n, k, digit)), arr))))
input()
for (fst, nxt) in zip(*[iter(stdin)] * 2):
	(_, k) = map(int, fst.split())
	arr = list(map(int, nxt.split()))
	print('YES' if solve(arr, k) else 'NO')


j = int(input())
for j0 in range(j):
	(n, k) = map(int, input().split())
	str1 = input()
	list1 = str1.split()
	c = []
	e = []
	temp = True
	for n0 in range(n):
		num = int(list1[n0])
		b = []
		while True:
			s = num // k
			y = num % k
			b.append(y)
			if s == 0:
				break
			num = s
		d = len(b)
		c.append(b)
		e.append(d)
	max1 = max(e)
	for n0 in range(n):
		while len(c[n0]) < max1:
			c[n0].append(0)
	h = []
	for f in range(max1):
		g = 0
		for n0 in range(n):
			g = g + c[n0][f]
		h.append(g)
	for h0 in h:
		if h0 > 1:
			temp = False
	if temp == True:
		print('Yes')
	else:
		print('No')


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	if s == 0:
		print('YES')
		continue
	d = 1
	ans = 0
	check = defaultdict(lambda : 0)
	for j in range(0, n):
		s = a[j]
		dub = a[j]
		d = 1
		for i in range(0, 55):
			if d > s and dub != 0:
				ans = 1
				break
			if s % d == 0 and (s // d - 1) % k == 0:
				dub = dub - d
				check[d] = check[d] + 1
				d = d * k
				s = dub
				if dub == 0:
					break
			else:
				d = d * k
	v = check.values()
	if len(v) >= 1 and max(v) > 1 or ans:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = 1
	power = set()
	for i in a:
		j = 0
		while i > 0 and flag:
			while i % k == 0:
				i = i // k
				j += 1
			if j in power:
				flag = 0
				break
			power.add(j)
			i -= 1
		if not flag:
			break
	print('YES' if flag else 'NO')


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(100, -1, -1):
		minu = k ** i
		for j in range(n):
			if a[j] >= minu:
				a[j] -= minu
				break
	ans = 'YES'
	for i in a:
		if i != 0:
			ans = 'NO'
			break
	print(ans)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split(' ')))
	li = list(map(int, input().split(' ')))
	li.sort(reverse=True)
	check = [0] * 100
	res = 1
	for x in li:
		if x == 0:
			continue
		if res == 0:
			break
		num = x
		req = int(log(num, k))
		req2 = int(log(num, k)) + 1
		if int(pow(k, req2)) <= num:
			req = req2
		if int(pow(k, req)) > num:
			req -= 1
		while True:
			if check[req] == 0:
				check[req] = 1
			else:
				res = 0
				break
			if int(pow(k, req)) == num:
				break
			else:
				num = num - int(pow(k, req))
				req = int(log(num, k))
				req2 = int(log(num, k)) + 1
				if int(pow(k, req2)) <= num:
					req = req2
				if int(pow(k, req)) > num:
					req -= 1
	if res == 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	ANS = [0] * 61
	POW = [pow(k, p) for p in range(61)]
	flag = 1
	for a in A:
		for p in range(60, -1, -1):
			while a >= POW[p]:
				ANS[p] += 1
				a -= POW[p]
				if ANS[p] > 1:
					break
	if max(ANS) > 1:
		print('NO')
	else:
		print('YES')


def get_arr(num):
	k_ = []
	while num != 0:
		(num, mod) = (num // k, num % k)
		k_ += [mod]
	return k_

def check(_list):
	wow = [0] * max([len(e) for e in _list])
	for sub_l in _list:
		for (i, el) in enumerate(sub_l):
			if el > 1:
				return False
			else:
				wow[i] += el
	for w in wow:
		if w > 1:
			return False
	return True

def ans(_list):
	if check(_list):
		print('YES')
	else:
		print('NO')
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if sum(arr) == 0:
		print('YES')
		continue
	l = [get_arr(num) for num in arr]
	ans(l)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = []
	i = 0
	while pow(k, i) <= pow(10, 16):
		d.append(pow(k, i))
		i = i + 1
	h = set()
	flag = True
	for x in a:
		if x == 0:
			continue
		while flag:
			j = 0
			for i in range(len(d)):
				if x >= d[i]:
					j = i
			if j in h:
				flag = False
				break
			h.add(j)
			x = x - d[j]
			if x == 0:
				break
	if flag:
		print('YES')
	else:
		print('NO')


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	a.sort()
	x = 1
	while x <= a[n - 1]:
		x *= k
	x //= k
	done = False
	while x > 0:
		count = 0
		for i in range(n):
			if a[i] >= x:
				count += 1
				a[i] -= x
		if count > 1:
			done = True
			break
		x //= k
	for i in range(n):
		if a[i] != 0:
			done = True
			break
	if done:
		print('NO')
	else:
		print('YES')


for ii in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	dic = {}
	flag = True
	for i in a:
		if i == 0:
			continue
		li = []
		p = i
		while p >= k:
			li.append(p % k)
			p = p // k
		li.append(p)
		for j in range(len(li)):
			if li[j] > 1:
				flag = False
				break
			if li[j] == 1 and j in dic:
				flag = False
				break
			if li[j] == 1:
				dic[j] = 1
		if not flag:
			break
	if not flag:
		print('NO')
	else:
		print('YES')


import sys
from math import *
z = 1
if z:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
mini = 9999999999

def f(n, k):
	s = ''
	for i in range(int(log(10 ** 16, k)) + 1, -1, -1):
		if n // k ** i > 1:
			return '-1'
		if n // k ** i == 1 and n != 0:
			s += '1'
			n %= k ** i
		else:
			s += '0'
	return s
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	p = [0 for i in range(101)]
	flag = 0
	for i in a:
		s = f(i, k)
		if s == '-1' or s == '':
			flag = 1
			break
		else:
			s = '0' * (100 - len(s)) + s
			for j in range(len(s)):
				if s[j] == '1':
					p[j] += 1
	print('YES' if flag == 0 and p.count(0) + p.count(1) == len(p) else 'NO')


for i in range(int(input())):
	(_, k) = list(map(int, input().split()))
	_list = []
	arr = list(map(int, input().split()))
	if sum(arr) == 0:
		print('YES')
		continue
	for num in arr:
		k_ = []
		if num == 0:
			continue
		while num != 0:
			mod = num % k
			num = num // k
			k_.append(mod)
		_list.append(k_)
	check = [0] * 105
	for ss in _list:
		for i in range(len(ss)):
			check[i] += int(ss[i])
	flag = True
	for i in check:
		if i > 1:
			flag = False
			break
	if flag == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mask = 1
	mx = max(a)
	while mask <= mx:
		mask *= k
	mask //= k
	flag = True
	while mask > 0:
		used = False
		for i in range(len(a)):
			if a[i] >= mask:
				if used or a[i] // mask > 1:
					flag = False
				else:
					a[i] %= mask
				used = True
		mask //= k
	if flag:
		print('YES')
	else:
		print('NO')


import math
for t in range(int(input())):
	(n, k) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	a.sort()
	i = 0
	d = False
	if max(a) == 0:
		print('YES')
		continue
	top = math.log(max(a)) / math.log(k)
	while i < top + 2:
		for j in range(n):
			if a[j] % k ** i != 0:
				print('NO')
				d = True
				break
			elif a[j] % k ** (i + 1) != 0:
				a[j] -= k ** i
				break
		i += 1
		if d:
			break
	if not d:
		print('YES')


def check(num, b):
	while num // b >= 1:
		rem = num % b
		num = num // b
		if rem not in [0, 1]:
			return False
		if num < b:
			if num not in [0, 1]:
				return False
	return True
import sys
for _ in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().split())
	rr = list(map(int, sys.stdin.readline().split()))
	K = True
	while True:
		for i in rr:
			if i != 0:
				break
		else:
			break
		s = sum(map(lambda x: x % k, rr))
		if s > 1:
			K = False
			break
		for i in range(len(rr)):
			rr[i] = rr[i] // k
	if K:
		sys.stdout.write('YES\n')
	else:
		sys.stdout.write('NO\n')


def get(x, k):
	a = []
	now = k
	while x:
		a.append(x % now)
		x //= k
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	b = []
	for i in a:
		if i:
			b.append(i)
	a = b
	mark = [0] * 70
	for i in a:
		tmp = get(i, k)
		for i in range(len(tmp)):
			mark[i] += tmp[i]
	if max(mark) > 1:
		print('NO')
	else:
		print('YES')


for q in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	res = 'YES'
	for i in range(n):
		ind = 0
		while a[i] > 0:
			r = a[i] % k
			if r == 0:
				pass
			elif r != 1 or d.get(ind, 0) == 1:
				res = 'NO'
				break
			else:
				d[ind] = 1
			a[i] //= k
			ind += 1
	print(res)


from sys import stdin, stdout
from collections import deque
input = stdin.readline

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		ai = list(map(int, input().split()))
		ar = [0] * 60
		for num in ai:
			j = 0
			while num != 0:
				ar[j] += num % k
				num //= k
				j += 1
		print(['YES', 'NO'][max([i > 1 for i in ar])])
main()


import math
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	key = dict()
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	copy = a[0]
	zero = 0
	one = 0
	for i in range(len(a)):
		if a[i] == 0:
			zero += 1
			continue
		else:
			l = []
			while a[i] > 0:
				pow_ = math.log10(a[i]) / math.log10(k) // 1
				if pow_ == 0:
					one += 1
				if pow_ in key or one == 2:
					break
				l.append(pow_)
				a[i] = a[i] - int(k ** pow_)
				if a[i] == 0:
					res = max(set(l), key=l.count)
					if l.count(res) > 1:
						break
					zero += 1
					for i in l:
						key[int(i)] = 1
					break
	if zero == n or (copy == 9007199254740991 and k == 2 and (n == 1)):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		X = []
		for i in range(60):
			X.append(K ** i)
		X.sort(reverse=True)
		v = set()
		f = True
		for a in A:
			tmp = a
			for x in X:
				if tmp >= x:
					tmp -= x
					if x in v:
						f = False
						break
					v.add(x)
			if tmp != 0:
				f = False
				break
		if f:
			print('YES')
		else:
			print('NO')
main()


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def solve(s, n, l, r, prefix, k):
	ans = 0
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			ones = prefix[j] - prefix[i - 1]
			zeros = j - i - ones + 1
			if prefix[j] - prefix[i - 1] <= k and zeros <= k:
				ans += 1
	return ans

def highestPowerof(n, k):
	res = 0
	while n >= k:
		n = n // k
		res += 1
	return res
for _ in range(iinput()):
	(n, k) = rinput()
	a = rlinput()
	d = defaultdict(int)
	flag = True
	for i in a:
		while i > 0:
			temp = highestPowerof(i, k)
			i -= int(pow(k, temp))
			if i >= 0:
				if d[temp] == 1:
					flag = False
					break
				d[temp] += 1
		if flag == False:
			break
	print('YES' if flag else 'NO')


from math import log

def f(a, res, n, k):
	if res == a:
		return True
	s = int(log(10 ** 16, k)) + 1
	for i in range(s, -1, -1):
		for j in range(n):
			if a[j] >= k ** i:
				a[j] -= k ** i
				if res == a:
					return True
				s -= 1
				break
	return False
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if f(a, [0 for j in range(n)], n, k):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == 1:
		if k == 2 and l[0] == 9007199254740991:
			print('YES')
		elif l[0] == 0:
			print('YES')
		elif l[0] - k ** int(math.log10(l[0]) / math.log10(k)) < 0:
			print('NO')
		elif l[0] - k ** int(math.log10(l[0]) / math.log10(k)) == 0:
			print('YES')
		else:
			d = []
			z = set()
			t = l[0]
			while t > 0:
				x = int(math.log10(t) / math.log10(k))
				t = t - k ** x
				if t >= 0:
					d.append(x)
					z.add(x)
				else:
					d.append(x - 1)
					z.add(x - 1)
			if len(d) == len(z):
				print('YES')
			else:
				print('NO')
	else:
		p = []
		s = set()
		ans = 'YES'
		for i in range(n):
			if l[i] > 0:
				t = l[i]
				while t > 0:
					x = int(math.log10(t) / math.log10(k))
					j = k ** x
					t = t - j
					if t < 0:
						p.append(x - 1)
						s.add(x - 1)
					else:
						p.append(x)
						s.add(x)
					if len(p) != len(s):
						ans = 'NO'
						break
			if ans == 'NO':
				break
		print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort()
		f = True
		s = set()
		for j in range(len(a)):
			if a[j] == 0:
				continue
			temp = a[j]
			p = 0
			while temp != 0:
				if temp % k != 0 and (temp - 1) % k != 0:
					f = False
					break
				if temp % k == 0:
					p += 1
					temp = temp // k
					continue
				if (temp - 1) % k == 0:
					if p in s:
						f = False
						break
					s.add(p)
					p += 1
					temp = (temp - 1) // k
					continue
			if not f:
				break
		if f:
			print('YES')
		else:
			print('NO')
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	has_ans = True
	picked = set()
	arr = map(int, input().split())
	for num in arr:
		i = 0
		while num > 0 and has_ans:
			while num % k == 0:
				num //= k
				i += 1
			if i in picked:
				has_ans = False
				break
			else:
				picked.add(i)
				num -= 1
		if not has_ans:
			break
	print('YES' if has_ans else 'NO')


import sys
import math
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def getit(num, base):
	res = []
	while True:
		if num == 0:
			return res
		else:
			lognum = int(math.log(num, base))
			revnorm = base ** lognum
			revnormp1 = base ** (lognum + 1)
			revnormm1 = base ** (lognum - 1)
			if lognum == 0 and revnorm != num or revnormp1 != revnormp1:
				return False
			elif revnorm == num:
				num = 0
				res.append(lognum)
			elif revnormp1 == num:
				num = 0
				res.append(lognum + 1)
			elif num < revnorm:
				num -= revnormm1
				if lognum - 1 in res:
					return False
				res.append(lognum - 1)
			elif num < revnormp1:
				num -= revnorm
				if lognum in res:
					return False
				res.append(lognum)
			else:
				num -= revnormp1
				if lognum + 1 in res:
					return False
				res.append(lognum + 1)

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		array = list(map(int, input().split()))
		gotarr = []
		found = True
		for ele in array:
			logitnum = getit(ele, k)
			if not found:
				break
			elif ele:
				if logitnum:
					for nums in logitnum:
						if nums not in gotarr:
							gotarr.append(nums)
						else:
							found = False
							break
				else:
					found = False
		if found:
			yield 'YES'
		else:
			yield 'NO'
t = int(input())
ans = gift()
print(*ans, sep='\n')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 1
	m = 0
	p = []
	e = 0
	ma = max(a)
	while c <= ma:
		p.append(c)
		m += 1
		c *= k
	if m == 0:
		print('YES')
	else:
		b = [0 for i in range(m)]
		for i in range(n):
			d = m - 1
			for j in range(m):
				if a[i] >= p[d - j]:
					b[d - j] += 1
					a[i] -= p[d - j]
					if a[i] >= p[d - j] or b[d - j] > 1:
						e = 1
						break
			if e == 1:
				print('NO')
				break
		else:
			print('YES')


t = int(input())
for _ in range(t):
	(n, k) = [int(p) for p in input().split()]
	arr = [int(p) for p in input().split()]
	s = set()
	mul = [k ** i for i in range(80)]
	ok = [0] * n
	for i in range(len(arr)):
		e = arr[i]
		for j in range(len(mul) - 1, -1, -1):
			if e >= mul[j] and j not in s:
				e -= mul[j]
				s.add(j)
			if e == 0:
				ok[i] = True
				break
	if all(ok):
		print('YES')
	else:
		print('NO')


from collections import defaultdict

def power_cal(a, b):
	count = 0
	while a >= b:
		a = a // b
		count += 1
	return count
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	used = defaultdict(int)
	flag = 0
	for i in arr:
		j = i
		while j > 0:
			temp = power_cal(j, k)
			j = j - int(pow(k, temp))
			if j >= 0:
				if used[temp] == 1:
					flag = 1
					break
			used[temp] += 1
		if flag == 1:
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
ans = []

def to_arr(n, k):
	if n < k:
		return [n]
	return to_arr(n // k, k) + [n % k]

def make_n_long(arr, n):
	if len(arr) >= n:
		return arr
	return [0 for i in range(n - len(arr))] + arr

def normolize(arr):
	m = 0
	for i in arr:
		if len(i) > m:
			m = len(i)
	for i in range(len(arr)):
		arr[i] = make_n_long(arr[i], m)
	return arr
for _ in range(n):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = list(map(lambda n: to_arr(n, k), arr))
	arr = normolize(arr)
	used = []
	ok = True
	for mask in arr:
		for j in range(len(mask)):
			if mask[j] > 1 or (mask[j] == 1 and j in used):
				ok = False
				ans.append('NO')
				break
			if mask[j] == 1:
				used.append(j)
		if not ok:
			break
	if ok:
		ans.append('YES')
print(*ans, sep='\n')


from sys import stdin

def to_base(num, b):
	ret = []
	while num > 0:
		ret.append(num % b)
		num = num // b
	return ret
for tc in range(int(stdin.readline())):
	(n, k) = [int(xx) for xx in stdin.readline().split()]
	a = [int(xx) for xx in stdin.readline().split()]
	bits = set()
	ok = True
	for num in a:
		conv = to_base(num, k)
		for i in range(len(conv)):
			cur = conv[i]
			if cur == 1:
				if i in bits:
					ok = False
				else:
					bits.add(i)
			elif cur != 0:
				ok = False
	print('YES' if ok else 'NO')


Case = int(input())
for i in range(0, Case):
	(n, k) = map(int, input().split())
	a = input().split()
	bit = []
	ans = True
	for x in range(0, 63):
		bit.append(0)
	for v in a:
		va = int(v)
		t = 0
		while va > 0:
			tep = va % k
			if tep > 0 and bit[t] > 0:
				ans = False
			elif tep > 1:
				ans = False
			elif bit[t] == 0:
				bit[t] = tep
			t += 1
			va = va // k
	if ans:
		print('YES', end='\n')
	else:
		print('NO', end='\n')


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
	return f(x) // (f(y) * f(x - y))
from collections import defaultdict
from heapq import heappop, heappush, heapify
t = int(input())

def bin(n, k):
	global s
	if n > 1:
		bin(n // k, k)
	s.append(str(n % k))
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	la = []
	flag = 0
	hash = defaultdict(int)
	for i in range(n):
		s = []
		bin(l[i], k)
		for i in s:
			if i != '0' and i != '1':
				flag = 1
				break
		if not flag:
			s = s[::-1]
			for i in range(len(s)):
				if s[i] == '1':
					hash[i] += 1
		else:
			break
	if not flag:
		for i in hash:
			if hash[i] > 1:
				flag = 1
				break
		if not flag:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	cl = [0] * 61
	for i in range(n):
		b = 0
		while l[i]:
			cl[b] += l[i] % k
			l[i] //= k
			b += 1
	f = 1
	for i in cl:
		if i > 1:
			f = 0
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	vis = dict()
	for x in a:
		if x == 0:
			continue
		for i in range(0, 100):
			if x == 0:
				break
			if x % k == 0:
				x = x / k
			elif x % k == 1:
				if i in vis.keys():
					flag = False
					break
				vis[i] = 1
				x = (x - 1) / k
			else:
				flag = False
				break
	if flag:
		print('YES')
	else:
		print('NO')
	t -= 1


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	seen = set()
	maxa = max(a)
	if maxa == 0:
		print('YES')
		continue
	maxi = int(math.ceil(math.log(max(a), k))) + 1
	for w in a:
		flag = 0
		for i in range(maxi, -1, -1):
			if k ** i <= w:
				if i in seen:
					print('NO')
					flag = 1
					break
				seen.add(i)
				w -= k ** i
		if flag:
			break
		if w != 0:
			print('NO')
			break
	else:
		print('YES')


def block(x, k):
	v = []
	if x == 1:
		return [0]
	while x > 0:
		v.append(int(x % k))
		x = int(x / k)
	ans = []
	for i in range(len(v)):
		if v[i] == 1:
			ans.append(i)
	return ans
t = int(input())
while t:
	s = input().split()
	(n, k) = (int(s[0]), int(s[1]))
	i = 0
	s2 = input().split()
	a = []
	for i in range(len(s2)):
		a.append(int(s2[i]))
	finalList = []
	f = 0
	for i in a:
		v = block(i, k)
		s = 0
		for j in v:
			s += k ** j
			finalList.append(j)
		if s != i:
			print('NO')
			f = 1
			break
	if f == 0:
		if len(finalList) == len(set(finalList)):
			print('YES')
		else:
			print('NO')
	t -= 1


from sys import stdin
input = stdin.readline
t = int(input())

def bc(x, k):
	l = []
	m = 1
	while m * k <= x:
		m *= k
	while m > 0:
		l.append(x // m)
		x %= m
		m //= k
	return l
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())), reverse=True)
	z = [0 for i in range(n)]
	z[0] = bc(a[0], k)
	l = len(z[0])
	for i in range(n):
		z[i] = bc(a[i], k)
		z[i] = [0] * (l - len(z[i])) + z[i]
	b = [0] * l
	for i in range(n):
		for j in range(l):
			b[j] += z[i][j]
	if max(b) > 1:
		print('NO')
	else:
		print('YES')


T = int(input())
for case in range(T):
	(N, base) = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	arr_K = set()
	flag = False
	for a in arr:
		bit = 0
		if a == 0:
			continue
		while a != 0:
			rem = a % base
			if rem != 1 and rem != 0:
				flag = True
				print('NO')
				break
			elif rem == 1:
				if bit in arr_K:
					flag = True
					print('NO')
					break
				arr_K.add(bit)
			bit += 1
			a = a // base
		arr_K
		if flag:
			break
	if not flag:
		print('YES')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	can = True
	res = []
	for i in map(int, input().split()):
		x = i
		bf = []
		while x:
			ost = x % k
			x //= k
			if ost > 1:
				can = False
			bf.append(ost)
		res.append(bf[:])
	for i in range(max([len(g) for g in res])):
		if len([g for g in res if len(g) > i and g[i]]) >= 2:
			can = False
	if can:
		print('YES')
	else:
		print('NO')


from bisect import *
from math import *
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	arr = list(map(int, input().split()))
	list1 = [0 for j in range(65)]
	power_list = [1]
	for j in range(64):
		power_list.append(power_list[-1] * k)
	flag = True

	def rep(num, b):
		if num >= 1:
			temp = bisect_left(power_list, num)
			if num != power_list[temp]:
				temp -= 1
			val = num // power_list[temp]
			list1[temp] += val
			num = num - val * power_list[temp]
			rep(num, k)
	for j in arr:
		rep(j, k)
	for j in list1:
		if j > 1:
			flag = False
			break
	if flag == False:
		print('NO')
	else:
		print('YES')


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(n, k) = read()
	a = read()
	flag = True
	s = set()
	for i in range(len(a)):
		if a[i] == 0:
			continue
		else:
			temp = a[i]
			ind = 0
			while temp > 0:
				if temp % k == 1:
					if ind in s:
						flag = False
						break
					else:
						temp -= 1
						s.add(ind)
				elif temp % k == 0:
					ind += 1
					temp = temp // k
				else:
					flag = False
					break
			if flag is False:
				break
	if flag:
		print('YES')
	else:
		print('NO')


def ksys(n, k):
	ans = []
	while n:
		ans.append(n % k)
		n = n // k
	return ans
for _ in range(int(input())):
	(n, k) = (int(x) for x in input().split())
	v = [ksys(int(x), k) for x in input().split()]
	ans = 'YES'
	j = 0
	max_l = max((len(x) for x in v))
	while j < max_l:
		cnt = 0
		for i in range(n):
			if j >= len(v[i]) or v[i][j] == 0:
				continue
			elif j < len(v[i]) and v[i][j] == 1:
				cnt += 1
				if cnt == 2:
					ans = 'NO'
					break
			else:
				ans = 'NO'
				break
		j += 1
		if ans == 'NO':
			break
	print(ans)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def ai():
	return list(map(int, input().split()))
for _ in range(ii()):
	(n, k) = mi()
	lst = ai()
	b = [0] * 100
	flag = False
	for val in lst:
		i = 0
		while val:
			b[i] += val % k
			val //= k
			if b[i] > 1:
				flag = True
				break
			i += 1
	if flag:
		print('NO')
	else:
		print('YES')


import sys
from sys import stdout, stdin
import math

def inputt():
	return stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return input().split()

def rlinput():
	return [int(i) for i in input().split()]

def main():
	(n, k) = map(int, rinput())
	q = rlinput()
	w = dict()
	for i in range(n):
		e = 0
		while q[i] > 0:
			if e in w:
				w[e] += q[i] % k
			else:
				w[e] = q[i] % k
			q[i] //= k
			e += 1
	fl = True
	for i in w:
		if w[i] > 1:
			fl = False
	if fl:
		print('YES')
	else:
		print('NO')
for i in range(int(input())):
	main()


from sys import stdin
from collections import defaultdict

def read_tuple():
	return map(int, input().split())

def read_int():
	return int(input())

def read_list():
	return list(map(int, input().split()))

def read_str_list():
	return list(input().split())

def log(a, k):
	curr = 0
	while a % k == 0:
		a //= k
		curr += 1
	return curr
for _ in range(read_int()):
	(n, k) = read_tuple()
	arr = read_list()
	done = defaultdict(int)
	poss = True
	for a in arr:
		while a != 0:
			p = log(a, k)
			if p > 0:
				done[p] += 1
				a -= pow(k, p)
				if done[p] > 1:
					poss = False
			else:
				done[0] += a % k
				a -= a % k
				if done[0] > 1:
					poss = False
		if not poss:
			break
	if poss:
		print('YES')
	else:
		print('NO')


import collections
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = collections.defaultdict(int)
	for ele in arr:
		c = 0
		while ele:
			d[c] += ele % k
			c += 1
			ele = ele // k
	flag = 1
	for i in d:
		if d[i] > 1:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ok = True
	b = list(map(int, input().split()))
	a = []
	for x in b:
		if not ok:
			break
		l = 0
		while x > 0:
			if x % k > 1:
				ok = False
				break
			if x % k == 1:
				a.append(l)
			l += 1
			x //= k
	if not ok:
		print('NO')
		continue
	print('YES' if len(set(a)) == len(a) else 'NO')