Alice gave Bob 3 integers N, K, and S. Help Bob find an S-good sequence.

A sequence B of length N is called S-good if the following conditions are met:
B_{i} \in \{-1, 0, 1\} for each 1 ≤ i ≤ N
\sum_{i=1}^N B_{i}\cdot K^{i-1} = S

If there are multiple S-good sequences, print any of them.  
If no S-good sequence exists, print -2.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing three space-separated integers — N, K,  and S.

------ Output Format ------ 

For each test case:
- If no S-good sequence exists, print -2.
- Otherwise, output N space-separated integers denoting the S-good sequence.

If multiple S-good sequences exist, you may print any of them.

------ Constraints ------ 

$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 100$
$2 ≤ K ≤ 100$
$1 ≤ S ≤ 10^{18}$

----- Sample Input 1 ------ 
3
4 2 15
3 6 36
5 5 7
----- Sample Output 1 ------ 
1 1 1 1
0 0 1
-2
----- explanation 1 ------ 
Test case $1$: We have $B = [1,1,1,1]$ and $S = 15$    
$\sum_{i=1}^N B_{i}\cdot K^{i-1} = 1\cdot 1 + 2\cdot 1 + 4\cdot 1 + 8\cdot 1 = 15$, hence $B$ is an $S$-good sequence.

Test case $2$: We have $B = [0, 0, 1]$ and $S = 36$. $6^{2} = 36$ so clearly $B$ is $S$-good.

Test case $3$: No $S$-good sequence of length $5$ exists.

Difficulty: HARD
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	nums = input().split(' ')
	(n, k, s, l) = (int(nums[0]), int(nums[1]), int(nums[2]), [])
	for j in range(n):
		l.append(k ** j)
	(total, l_good, a) = (s, [], 0)
	for x in range(1, len(l) + 1):
		if total - l[-x] >= 0:
			l_good.append((-1) ** a)
			total -= l[-x]
		elif x != len(l) and total - l[-x] < 0 and (abs(total - l[-x]) <= sum(l[-len(l):-x])):
			l_good.append((-1) ** a)
			a += 1
			total = l[-x] - total
		else:
			l_good.append(0)
	if total == 0:
		for y in range(n):
			print(l_good[::-1][y], end=' ')
		print()
	else:
		print(-2)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	ans = []
	for i in range(n):
		if s % k == 0:
			ans.append(0)
			s //= k
		elif s % k == 1:
			ans.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			ans.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(-2)
	else:
		print(*ans)


t = int(input())
for i in range(t):
	(n, k, s) = map(int, input().split())
	seq = -2
	l = []
	for i in range(n):
		if s % k == 0:
			l.append(0)
			s = s // k
		elif s % k == 1:
			l.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			l.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(seq)
	else:
		print(*l)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	arr = []
	for j in range(a):
		if c % b == 0:
			arr.append(0)
			c = c // b
		elif c % b == 1:
			arr.append(1)
			c = (c - 1) // b
		elif c % b == b - 1:
			arr.append(-1)
			c = (c + 1) // b
	if c > 0:
		print(-2)
	else:
		print(*arr)


t = int(input())
while t > 0:
	(n, k, s) = map(int, input().split())
	a = []
	for i in range(n):
		if s % k == 0:
			a.append(0)
			s //= k
		elif s % k == 1:
			a.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			a.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(-2)
	else:
		print(*a)
	t -= 1


import sys
input = sys.stdin.readline

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

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

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

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

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

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))

def outpltlt(lst):
	sys.stdout.write('\n'.join(map(str, (' '.join(map(str, a)) for a in lst))))
ans = []
for _ in range(inp()):
	(N, K, S) = inlt()
	an = []
	for i in range(N):
		if not S % K:
			an.append(0)
			S //= K
		elif S % K == 1:
			an.append(1)
			S = (S - 1) // K
		elif S % K == K - 1:
			an.append(-1)
			S = (S + 1) // K
		else:
			an = [-2]
			break
	ans.append(an if not S else [-2])
outpltlt(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	ans = []
	bol = True
	for i in range(n):
		if s % k == 1:
			ans.append(1)
		elif s % k == k - 1:
			ans.append(-1)
			s = (s + 1) // k
			continue
		elif s % k == 0:
			ans.append(0)
		else:
			bol = False
		s = s // k
	if bol:
		if s == 0:
			print(*ans, sep=' ')
		else:
			print(-2)
	else:
		print(-2)


for i in range(int(input())):
	(N, K, S) = map(int, input().split())
	b = True
	ans = ''
	for j in range(N):
		if S % K == 1:
			ans = ans + ' 1'
		elif S % K == K - 1:
			ans = ans + ' -1'
			S = (S + 1) // K
			continue
		elif S % K == 0:
			ans = ans + ' 0'
		else:
			b = False
			break
		S = S // K
	if b:
		if S != 0:
			print(-2)
		else:
			print(ans)
	else:
		print(-2)


T = int(input())
for _ in range(T):
	(N, K, S) = map(int, input().split())
	ans = []
	while S > 0:
		if S % K == 0 or S % K == 1:
			ans.append(S % K)
		elif S % K == K - 1:
			ans.append(-1)
			S += 1
		else:
			print(-2)
			break
		S = S // K
	else:
		if len(ans) > N:
			print(-2)
		else:
			for _ in range(N - len(ans)):
				ans.append(0)
			print(*ans)


for _ in range(int(input())):
	(N, base, sm) = list(map(int, input().split()))
	z = []
	x = 0
	for i in range(N):
		z.append(-1)
		x += -1 * base ** i
	for i in range(N - 1, -1, -1):
		m = base ** i
		if x + 2 * m <= sm:
			x = x + 2 * m
			z[i] = 1
		elif x + m <= sm:
			x = x + m
			z[i] = 0
	if x == sm:
		print(*z)
	else:
		print(-2)


for _ in range(int(input())):
	(N, K, S) = map(int, input().split(' '))
	l = []
	for i in range(N):
		if S % K == 0:
			l.append(0)
			S //= K
		elif S % K == 1:
			l.append(1)
			S = (S - 1) // K
		elif S % K == K - 1:
			l.append(-1)
			S = (S + 1) // K
	if S == 0:
		print(*l)
	else:
		print(-2)


t = int(input())
for _ in range(t):
	(n, k, s) = map(int, input().split())
	v = 0
	m = s
	l = []
	for i in range(n):
		b = s % k
		if b == 1 or b == 0:
			l.append(b)
		else:
			b = -1
			l.append(-1)
		s -= b
		s = s // k
	for i in range(n):
		v += l[i] * k ** i
	if v == m:
		for i in l:
			print(i, end=' ')
		print()
	else:
		print(-2)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split(' '))
	lst = []
	flag = 0
	for i in range(n):
		mod = s % k
		if mod == 0 or mod == 1 or mod == k - 1:
			if mod == 0:
				lst.append(0)
			elif mod == 1:
				lst.append(1)
				s -= 1
			else:
				lst.append(-1)
				s += 1
			s = s // k
		else:
			flag = 1
			break
	if flag == 0 and s == 0:
		print(*lst)
	else:
		print(-2)


def helper(n, s, k):
	n = int(n)
	s = int(s)
	k = int(k)
	ans = []
	Sum = s
	i = 0
	while i < n:
		if s % k == 0:
			ans.append(0)
		elif s % k == 1:
			s -= 1
			ans.append(1)
		else:
			s += 1
			ans.append(-1)
		s = s // k
		i += 1
	ansSum = 0
	t = 1
	for i in ans:
		ansSum += i * t
		t = k * t
	if ansSum == Sum:
		return ans
	else:
		return -2
T = int(input())
for i in range(T):
	(n, k, s) = input().split()
	ans = helper(n, s, k)
	if ans != -2:
		for i in ans:
			print(i, end=' ')
	else:
		print('-2')
	print()


t = int(input())
while t:
	(n, k, s) = [int(i) for i in input().split()]
	ans = []
	flag = 1
	while s != 0:
		bi = s % k
		if bi == 0 or bi == 1:
			ans.append(bi)
		elif bi == k - 1:
			ans.append(-1)
			bi = -1
		else:
			flag = 0
			break
		s = (s - bi) // k
	if flag:
		if len(ans) > n:
			print(-2)
		else:
			if len(ans) < n:
				ans.extend([0 for i in range(n - len(ans))])
			for num in ans:
				print(num, end=' ')
			print()
	else:
		print(-2)
	t -= 1


def omega(a, b):
	if b == 0:
		return 1
	R = omega(a, b // 2)
	if b % 2:
		return R * R * a
	else:
		return R * R
for i in range(int(input())):
	(N, K, S) = map(int, input().split())
	t = S
	alpha = []
	for i in range(N):
		r = S % K
		if r != 0 and r != 1 and (r != K - 1):
			print(-2)
			break
		if r == K - 1 and K != 2:
			r = -1
		alpha.append(r)
		S = (S - r) // K
	else:
		sum = 0
		for i in range(N):
			sum += alpha[i] * omega(K, i)
		if sum != t:
			print(-2)
			continue
		print(' '.join(map(str, alpha)))


import math
T = int(input())
for tc in range(T):
	(n, k, s) = map(int, input().split(' '))
	sumk = s
	l = []
	iterm = 0
	for i in range(n):
		temp = sumk % k
		if temp == 0:
			l.append(0)
		elif temp == 1:
			l.append(1)
		else:
			temp = -1
			l.append(-1)
		iterm = temp
		sumk -= iterm
		sumk /= k
	finalsum = 0
	for i in range(0, n):
		finalsum += k ** i * l[i]
	if finalsum == s:
		print(*l)
	else:
		print(-2)


t = int(input())
for _ in range(t):
	(n, k, s) = (int(x) for x in input().split())
	if k == 2:
		if s >= 2 ** n:
			print(-2)
		else:
			s_bin = bin(s)[2:]
			for c in reversed(s_bin):
				print(c, end=' ')
			print('0 ' * (n - len(s_bin)))
	else:
		seq = []
		bad = False
		for i in range(n):
			dig = s % k
			if dig in (0, 1):
				seq.append(dig)
				s //= k
			elif dig == k - 1:
				seq.append(-1)
				s = (s + 1) // k
			else:
				bad = True
				break
		if bad or s != 0:
			print(-2)
		else:
			for e in seq:
				print(e, end=' ')
			print()


t = int(input())
for _ in range(t):
	(n, k, s) = list(map(int, input().split(' ')))
	res = []
	for _ in range(n):
		if s % k == 0:
			res.append(0)
			s //= k
		elif s % k == 1:
			res.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			res.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(-2)
	else:
		print(*res)


t = int(input())
for testcases in range(t):
	(n, k, s) = map(int, input().split())
	list = []
	for i in range(n):
		if s % k == 0:
			list.append(0)
			s //= k
		elif s % k == 1:
			list.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			list.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(-2)
	else:
		print(*list)


def solution():
	(n, k, s) = map(int, input().split())
	list = []
	for i in range(n):
		if s % k == 0:
			list.append(0)
			s //= k
		elif s % k == 1:
			list.append(1)
			s = (s - 1) // k
		elif s % k == k - 1:
			list.append(-1)
			s = (s + 1) // k
	if s > 0:
		print(-2)
	else:
		print(*list)
t = int(input())
while t > 0:
	t = t - 1
	solution()


def solve(n, k, s):
	ans = [0] * n
	(prev, cur) = (1, k)
	for i in range(n):
		val = s % cur
		if val:
			if val == prev:
				ans[i] = 1
				s -= prev
			elif val == cur - prev:
				ans[i] = -1
				s += prev
			else:
				return [-2]
		if not s:
			return ans
		(prev, cur) = (cur, cur * k)
	return [-2]
for _ in range(int(input())):
	(n, k, s) = map(int, input().split(' '))
	print(*solve(n, k, s))


t = int(input())
for _ in range(t):
	(n, k, s) = map(int, input().split())
	ans = [0] * n
	i = 0
	ss = s
	while i < n:
		l = s % k
		if l == 0:
			pass
		elif l == 1:
			ans[i] = 1
			s -= 1
		elif l == k - 1:
			ans[i] = -1
			s += 1
		else:
			break
		s = s / k
		i += 1
	p = 1
	sumt = 0
	for i in ans:
		sumt += i * p
		p = p * k
	if ss == sumt:
		print(*ans)
	else:
		print(-2)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	l = []
	for i in range(min(n, 6111)):
		if s % k == 0:
			s = s // k
			l.append('0')
		elif s % k == 1:
			s = (s - 1) // k
			l.append('1')
		elif s % k == k - 1:
			s = (s + 1) // k
			l.append('-1')
	if s != 0:
		print('-2')
	else:
		print(*l)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	l = [0] * n
	a = s
	sumi = 0
	for i in range(min(n, 6111)):
		if s == 0:
			break
		elif s % k == 0:
			l[i] = 0
			s //= k
		elif s % k == 1:
			s -= 1
			l[i] = 1
			s //= k
		elif s % k == k - 1:
			s += 1
			l[i] = -1
			s //= k
	if s != 0:
		print(-2)
	else:
		print(*l)


t = int(input())
for i in range(0, t):
	(n, k, s) = map(int, input().split(' '))
	b = []
	flag = -1
	for i in range(0, n):
		if s == 0:
			flag = i
			break
		elif s < 0:
			flag = -2
			break
		elif s % k == 0 or s % k == 1:
			b.append(int(s % k))
			s = (s - b[i]) / k
			if s < 0:
				flag = -2
				break
		else:
			b.append(-1)
			s = (s + 1) / k
			if s < 0:
				flag = -2
				break
	if s == 0 and flag == -1:
		print(*b)
	elif flag == -2 or s > 0:
		print(-2)
	else:
		lenb = len(b)
		lb = [0] * (n - lenb)
		print(*b, end=' ')
		print(*lb)


from collections import defaultdict
import math
from heapq import heappop, heappush, heapify

def solve(n, k, s):
	l = []
	j = 0
	while j < n:
		x = s % k
		if x == 0:
			l.append(0)
			s = s // k
		elif x == 1:
			l.append(1)
			s = (s - 1) // k
		elif k - x == 1:
			l.append(-1)
			s = (s + 1) // k
		else:
			return [-2]
		j += 1
	if s > 0:
		return [-2]
	else:
		return l
for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	l = solve(n, k, s)
	print(*l)


def main():
	t = int(input())
	for _ in range(t):
		(n, k, s) = map(int, input().split())
		powers = [0] * n
		curr = 0
		ans = [0] * n
		powers[0] = 1
		for i in range(1, n):
			powers[i] = powers[i - 1] * k
			if powers[i] > s:
				break
		for i in range(n - 1, -1, -1):
			if abs(s - (curr + powers[i])) < abs(s - curr):
				curr += powers[i]
				ans[i] = 1
			elif abs(s - (curr - powers[i])) < abs(s - curr):
				curr -= powers[i]
				ans[i] = -1
		if curr == s:
			for i in ans:
				print(i, end=' ')
			print()
		else:
			print(-2)
main()


for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	l = []
	while a > 0:
		if n % b == 0:
			l.append(0)
			n = n // b
		elif n % b == 1:
			l.append(1)
			n = (n - 1) // b
		elif n % b == b - 1:
			l.append(-1)
			n = (n + 1) // b
		a -= 1
	if n > 0:
		print(-2)
	else:
		print(*l)


for t in range(int(input())):
	(n, k, s) = list(map(int, input().strip().split()))[:3]
	li = []
	flag = 1
	for i in range(n):
		rem = -1 if s % k == k - 1 and (not k == 2) else s % k
		if abs(rem) > 1:
			flag = 0
			break
		li.append(rem)
		s = s - rem
		s = s // k
	if flag == 0 or s != 0:
		print(-2)
	else:
		print(*li)


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	b = []
	for i in range(n):
		m = s % k
		if m == 0:
			b.append(0)
		elif m == 1:
			b.append(1)
		elif m == k - 1:
			b.append(-1)
		else:
			break
		s = (s - b[-1]) // k
	if s > 0:
		print('-2')
	else:
		for val in b:
			print(val, end=' ')
		print()


for _ in range(int(input())):
	(n, k, s) = map(int, input().split())
	b = []
	flg = False
	for _ in range(n):
		rem = -1 if s % k == k - 1 and (not k == 2) else s % k
		if abs(rem) > 1:
			flg = True
			break
		b.append(rem)
		s -= rem
		s //= k
	if s > 0 or flg:
		print(-2)
	else:
		print(*b)


T = int(input())
for tc in range(T):
	(n, k, s) = map(int, input().split())
	b = []
	st = s
	flag = 0
	while st > 0:
		rem = st % k
		if rem == 1 or rem == 0:
			b.append(rem)
		elif k - rem == 1:
			b.append(-1)
			st = st // k + 1
			continue
		elif k - rem > 1:
			flag = 1
			break
		st = (st - rem) // k
	if len(b) > n:
		flag = 1
	if flag == 1:
		print(-2)
		continue
	while len(b) < n:
		b.append(0)
	for i in b:
		print(i, end=' ')
	print()


for t in range(int(input())):
	(n, k, s) = map(int, input().split())
	a = []
	sm = s
	for i in range(n):
		x = s % k
		if x == 0:
			a.append(0)
		elif x == 1:
			a.append(1)
		elif x == k - 1:
			a.append(-1)
		else:
			break
		s = (s - a[-1]) // k
	if s > 0:
		print(-2)
	else:
		print(*a)


for t in range(int(input())):
	(n, k, s) = [int(i) for i in input().split()]
	l1 = [0] * n
	for i in range(n):
		if s % k == 0:
			l1[i] = 0
			s = s // k
		elif s % k == 1:
			s = (s - 1) // k
			l1[i] = 1
		elif s % k == k - 1:
			s = (s + 1) // k
			l1[i] = -1
	if s > 0:
		print(-2)
	else:
		print(*l1)


import sys
next((f := sys.stdin))
for s in f:
	(n, k, s) = map(int, s.split())
	if k == 2:
		ans = f'{s:b}'.zfill(n)[::-1]
		if len(ans) == n:
			s = 0
	else:
		ans = []
		for _ in range(n):
			r = (s + 1) % k - 1
			if abs(r) > 1:
				break
			ans.append(r)
			s = (s - r) // k
	print(*([-2] if s else ans))


import sys
next((f := sys.stdin))
for s in f:
	(n, k, s) = map(int, s.split())
	ans = []
	for _ in range(n):
		if abs((r := min((s % k, s % -k), key=abs))) > 1:
			break
		ans.append(r)
		s = (s - r) // k
	print(*([-2] if s else ans))


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 solve():
	(n, k, s) = mi()
	sc = s
	ans = [0] * n
	i = 0
	while i < n:
		if s % k == 0:
			ans[i] = 0
		elif s % k == 1:
			s -= 1
			ans[i] = 1
		else:
			s += 1
			ans[i] = -1
		s //= k
		i += 1
	(p, power) = (0, 1)
	for i in range(0, n):
		p += ans[i] * power
		power *= k
	if p != sc:
		print(-2)
		return
	for i in ans:
		print(i, end=' ')
	print()

def main():
	t = int(input())
	for i in range(t):
		solve()
main()


t = int(input())
for _ in range(t):
	(n, k, s) = map(int, input().split())
	b = []
	w = s
	fail = False
	while w > 0 or len(b) < n:
		digit = w % k
		if digit > 1 and digit < k - 1:
			fail = True
			break
		if digit == k - 1 and digit != 1:
			b.append(-1)
			w += k
		else:
			b.append(digit)
		w = w // k
	while len(b) > n and b[-1] == 0:
		b = b[0:len(b) - 1]
	if len(b) > n:
		fail = True
	if fail:
		print(-2)
	else:
		print(' '.join([str(e) for e in b]))


for i in range(int(input())):
	(N, K, S) = map(int, input().split())
	t = S
	alpha = []
	for i in range(N):
		r = S % K
		if r != 0 and r != 1 and (r != K - 1):
			print(-2)
			break
		if r == K - 1 and K != 2:
			r = -1
		alpha.append(r)
		S = (S - r) // K
	else:
		sum = 0
		for i in range(N):
			sum += alpha[i] * K ** i
		if sum != t:
			print(-2)
			continue
		print(' '.join(map(str, alpha)))


def solve():
	(n, k, s) = map(int, input().split())
	a = [k ** i for i in range(n)]
	su = []
	su.append(0)
	for i in range(1, n):
		su.append(su[i - 1] + a[i - 1])
	a = a[::-1]
	su = su[::-1]
	ans = []
	i = 0
	while i < n:
		if i < n - 1:
			if s == 0:
				ans.append(str(0))
			elif s - a[i] + su[i] >= 0:
				if s - a[i + 1] - su[i + 1] <= 0:
					ans.append(str(0))
				else:
					s -= a[i]
					ans.append(str(1))
			elif s <= 0:
				if s + a[i + 1] + su[i + 1] >= 0:
					ans.append(str(0))
				elif s - a[i] + su[i] <= 0:
					s += a[i]
					ans.append(str(-1))
			else:
				ans.append(str(0))
		elif s == 0:
			ans.append(str(0))
		elif s - a[i] + su[i] >= 0:
			s -= a[i]
			ans.append(str(1))
		elif s <= 0:
			if s - a[i] + su[i] <= 0:
				s += a[i]
				ans.append(str(-1))
		else:
			ans.append(str(0))
		i += 1
	ans = ans[::-1]
	a = a[::-1]
	su = su[::-1]
	if s != 0:
		print(-2)
		return
	print(' '.join(ans))
	return
for _ in range(int(input())):
	solve()


def log(n, s):
	ans = 0
	while s > 0:
		s = s // n
		if s > 0:
			ans += 1
	return ans
t = int(input())
while t > 0:
	n = input()
	n = n.split()
	k = int(n[1])
	s = int(n[2])
	n = int(n[0])
	a = [i for i in range(1, n + 1)]
	for i in range(0, n):
		a[i] = 0
	ans = 0
	for i in range(n):
		ans += int(pow(k, i))
		a[i] = 1
		if ans >= s:
			break
	if ans < s:
		print(-2)
	else:
		rem = int(ans - s)
		while rem != 0:
			temp = log(k, rem)
			if a[temp] == -1:
				print(-2)
				break
			a[temp] -= 1
			rem -= int(pow(k, temp))
		if rem == 0:
			for i in range(n):
				print(a[i], end=' ')
			print()
	t -= 1


from sys import stdin
input = stdin.readline

def summation(K, N):
	return (K ** (N + 1) - 1) // (K - 1)

def solve(N, K, S):
	B = [0] * N
	for i in range(N):
		x = S % K
		if x == K - 1:
			if summation(K, N - i - 1) == S:
				for j in range(i, N):
					B[j] = 1
				S = 0
				break
			else:
				x = -1
		if x in [-1, 0, 1]:
			B[i] = x
			S = (S - x) // K
		else:
			return [-2]
	if S == 0:
		return B
	return [-2]
T = int(input().strip())
for problem in range(1, T + 1):
	(N, K, S) = [int(x) for x in input().strip().split()]
	print(*solve(N, K, S))


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

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

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

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

def solve(n, k, s):
	b = [0] * n
	i = n
	sign = 1
	while i > 0:
		num = k ** (i - 1) - (k ** (i - 1) - 1) // (k - 1)
		if num > s:
			b[i - 1] = 0
		else:
			s -= k ** (i - 1)
			b[i - 1] = sign
		if s < 0:
			sign *= -1
			s *= -1
		i -= 1
	flag = True
	if s != 0:
		flag = False
	return (b, flag)

def main():
	for i in range(inp()):
		(n, k, s) = lis()
		(solution, flag) = solve(n, k, s)
		if flag:
			for j in solution:
				print(j, end=' ')
			print()
		else:
			print(-2)
main()


def binpow(a1, b1):
	if b1 == 0:
		return 1
	res = binpow(a1, b1 // 2)
	if b1 % 2:
		return res * res * a1
	else:
		return res * res
e = int(input())
while e > 0:
	e -= 1
	(n, k, s) = map(int, input().split())
	tmp = s
	b = []
	for i in range(n):
		rem = s % k
		if rem != 0 and rem != 1 and (rem != k - 1):
			print(-2)
			break
		if rem == k - 1 and k != 2:
			rem = -1
		b.append(rem)
		s = (s - rem) // k
	else:
		sum = 0
		for i in range(n):
			sum += b[i] * binpow(k, i)
		if sum != tmp:
			print(-2)
			continue
		print(' '.join(map(str, b)))


def binpow(p, q):
	if q == 0:
		return 1
	r = binpow(p, q // 2)
	if q % 2:
		return r * r * p
	else:
		return r * r
T = int(input())
for i in range(0, T):
	(N, a, b) = map(int, input().split())
	ans = []
	sum = b
	f = 1
	for i in range(N):
		rem = b % a
		if rem != 0 and rem != 1 and (rem != a - 1):
			print(-2)
			f = 0
			break
		if a != 2 and b % a == a - 1:
			rem = -1
		ans.append(rem)
		b = (b - rem) // a
	b = 0
	if not f:
		continue
	for (i, digit) in enumerate(ans):
		b += digit * binpow(a, i)
	if sum != b:
		print(-2)
	else:
		print(*ans)


num = [3, 5, 7, 11, 13]
mul = []
for n in num:
	mul.append(n ** 2)

def swingshotscatter(xarfadedsasaass, xanderfadedsa):
	if xanderfadedsa == 0:
		return 1
	xarfadedsasaass078 = swingshotscatter(xarfadedsasaass, xanderfadedsa // 2)
	if xanderfadedsa % 2:
		return xarfadedsasaass078 * xarfadedsasaass078 * xarfadedsasaass
	else:
		return xarfadedsasaass078 * xarfadedsasaass078
solve = int(input())
while solve > 0:
	solve -= 1
	(n, k, s) = map(int, input().split())
	curl = s
	xanderfade = []
	for i in range(n):
		swingshot = s % k
		if swingshot != 0 and swingshot != 1 and (swingshot != k - 1):
			print(-2)
			break
		if swingshot == k - 1 and k != 2:
			swingshot = -1
		xanderfade.append(swingshot)
		s = (s - swingshot) // k
	else:
		xanderfadedsasaass = 0
		for i in range(n):
			xanderfadedsasaass += xanderfade[i] * swingshotscatter(k, i)
		if xanderfadedsasaass != curl:
			print(-2)
			continue
		print(' '.join(map(str, xanderfade)))


def fun(a, b):
	if b == 0:
		return 1
	k = fun(a, b // 2)
	if b % 2:
		return k * k * a
	else:
		return k * k
tes = int(input())
while tes > 0:
	tes -= 1
	(n, k, s) = map(int, input().split())
	tmp = s
	l = []
	for i in range(n):
		rem = s % k
		if rem != 0 and rem != 1 and (rem != k - 1):
			print(-2)
			break
		if rem == k - 1 and k != 2:
			rem = -1
		l.append(rem)
		s = (s - rem) // k
	else:
		sum = 0
		for i in range(n):
			sum += l[i] * fun(k, i)
		if sum != tmp:
			print(-2)
			continue
		print(*l)


def bin(a, b):
	if b == 0:
		return 1
	r = bin(a, b // 2)
	if b % 2:
		return r * r * a
	else:
		return r * r
for i in range(int(input())):
	(n, k, s) = map(int, input().split())
	t = s
	alpha = []
	for i in range(n):
		r = s % k
		if r != 0 and r != 1 and (r != k - 1):
			print(-2)
			break
		if r == k - 1 and k != 2:
			r = -1
		alpha.append(r)
		s = (s - r) // k
	else:
		sum = 0
		for i in range(n):
			sum += alpha[i] * bin(k, i)
		if sum != t:
			print(-2)
			continue
		print(' '.join(map(str, alpha)))


T = int(input())
while T:
	[n, k, s] = [int(i) for i in input().split()]
	a = []
	flag = False
	while s > 0:
		ins = False
		f = s % k
		if f == 0 or f == 1:
			a.append(str(f))
		elif (f + 1) % k == 0:
			ins = True
			a.append(str(-1))
		else:
			print(-2)
			flag = True
			break
		if ins:
			s += 1
		s = int(s / k)
	if not flag:
		p = len(a)
		if p < n:
			for i in range(n - p):
				a.append(str(0))
			ans = ' '.join(a)
			print(ans)
		elif p == n:
			ans = ' '.join(a)
			print(ans)
		else:
			print(-2)
	T -= 1


def binpow(a, b):
	if b == 0:
		return 1
	res = binpow(a, b // 2)
	if b % 2:
		return res * res * a
	else:
		return res * res
T_C = int(input())
for _ in range(T_C):
	(n, k, s) = map(int, input().split())
	ans = []
	sum = s
	flag = True
	for i in range(n):
		rem = s % k
		if rem != 0 and rem != 1 and (rem != k - 1):
			print(-2)
			flag = False
			break
		if k != 2 and s % k == k - 1:
			rem = -1
		ans.append(rem)
		s = (s - rem) // k
	s = 0
	if not flag:
		continue
	for (i, digit) in enumerate(ans):
		s += digit * binpow(k, i)
	if sum != s:
		print(-2)
	else:
		print(*ans)