Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that any two consecutive stones' numbers differ by one of two values.  Legend has it that there is a treasure trove at the end of the trail.  If Manasa can guess the value of the last stone, the treasure will be hers.

Example 

$n=2$ 

$a=2$ 

$b=3$  

She finds $2$ stones and their differences are $a=2$ or $b=3$.  We know she starts with a $0$ stone not included in her count.  The permutations of differences for the two stones are $[2,2],[2,3],[3,2].$ or $[3,3]$.  Looking at each scenario, stones might have $[2,4],[2,5],[3,5]$ or $[3,6]$ on them.  The last stone might have any of  $4,5$, or $6$ on its face. 

Compute all possible numbers that might occur on the last stone given a starting stone with a $0$ on it, a number of additional stones found, and the possible differences between consecutive stones.  Order the list ascending.

Function Description

Complete the stones function in the editor below.   

stones has the following parameter(s):  

int n: the number of non-zero stones  
int a: one possible integer difference  
int b: another possible integer difference  

Returns  

int[]: all possible values of the last stone, sorted ascending  

Input Format

The first line contains an integer $T$, the number of test cases.  

Each test case contains $3$ lines: 

- The first line contains $n$, the number of non-zero stones found. 

- The second line contains $a$, one possible difference 

- The third line contains $b$, the other possible difference.  

Constraints

$1\leq T\leq10 $  
$1\leq n,a,b\leq10^{3}$  

Sample Input
STDIN   Function
-----   --------
2       T = 2 (test cases)
3       n = 3 (test case 1)
1       a = 1
2       b = 2
4       n = 4 (test case 2)
10      a = 10
100     b = 100

Sample Output
2 3 4 
30 120 210 300 

Explanation

With differences 1 and 2, all possible series for the first test case are given below:

0,1,2
0,1,3
0,2,3
0,2,4

Hence the answer 2 3 4. 

With differences 10 and 100, all possible series for the second test case are the following: 

0, 10, 20, 30
0, 10, 20, 120
0, 10, 110, 120
0, 10, 110, 210
0, 100, 110, 120
0, 100, 110, 210
0, 100, 200, 210
0, 100, 200, 300

Hence the answer 30 120 210 300.

Difficulty: EASY

Solutions:
import sys
t = int(input())
for i in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	arr = []
	val = min(a, b) * (n - 1)
	arr += [val]
	while val < max(a, b) * (n - 1):
		val += max(a, b) - min(a, b)
		arr += [val]
	s = ''
	for i in arr:
		s += str(i) + ' '
	print(s)


T = int(input())
for t in range(T):
	N = int(input())
	a = int(input())
	b = int(input())
	m = min(a, b)
	dif = abs(b - a)
	current = m * max(1, N - 1)
	last = -1
	for n in range(N):
		if last != current:
			print(current, end=' ')
		last = current
		current = current + dif
	print('')


def solve(steps, a, b):
	computed = {}
	neXt = set([a, b])
	for i in range(steps - 2):
		current = neXt
		neXt = set()
		for val in current:
			if val in computed:
				addNext(neXt, computed[val])
			else:
				pos = set([val + a, val + b])
				addNext(neXt, pos)
				computed[val] = pos
	return neXt

def addNext(x, a):
	for v in a:
		x.add(v)
cases = int(input().strip())
for n in range(cases):
	steps = int(input().strip())
	a = int(input().strip())
	b = int(input().strip())
	x = sorted(solve(steps, a, b))
	for num in x:
		print(num, end='')
		print(' ', end='')
	print('')


def pos(sum, n, a, b):
	if n == 1:
		return sum + a
from sys import stdin as cin
for i in range(int(cin.readline())):
	n = int(cin.readline())
	a = int(cin.readline())
	b = int(cin.readline())
	arr = [0]
	for t in range(n - 1):
		k = []
		for x in arr:
			k.append(x + a)
			k.append(x + b)
		arr = list(set(k))
	arr.sort()
	for x in arr:
		print(x, end=' ')
	print()


T = int(input())
for Ti in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	(a, b) = sorted([a, b])
	d = b - a
	cur = a * (n - 1)
	print(cur, end=' ')
	for i in range(n - 1):
		cur += d
		print(cur, end=' ')
	print('')


def stones(n, a, b):
	if a <= b:
		for i in range(n):
			steps = (n - 1 - i) * a + b * i
			print(steps, end=' ')
	else:
		for i in range(n):
			steps = (n - 1 - i) * b + a * i
			print(steps, end=' ')
	print()
for i in range(int(input())):
	stones(int(input()), int(input()), int(input()))


import math

def uniq(input):
	output = []
	for x in input:
		if x not in output:
			output.append(x)
	return output
t = int(input())
for i in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	if a <= b:
		l = [[0]]
		for j in range(1, n):
			n1 = len(l[j - 1])
			sum1 = []
			for k in range(n1):
				x = l[j - 1][k] + a
				y = l[j - 1][k] + b
				sum1.append(x)
				sum1.append(y)
			s = uniq(sum1)
			l.append(s)
		l1 = uniq(l[n - 1])
		for m in range(len(l1)):
			print('%d ' % l1[m], end='')
		print('\r')
	else:
		l = [[0]]
		temp = aa = b
		b = temp
		for j in range(1, n):
			n1 = len(l[j - 1])
			sum1 = []
			for k in range(n1):
				x = l[j - 1][k] + a
				y = l[j - 1][k] + b
				sum1.append(x)
				sum1.append(y)
			s = uniq(sum1)
			l.append(s)
		l1 = uniq(l[n - 1])
		l1.reverse()
		for m in range(len(l1)):
			print('%d ' % l1[m], end='')
		print('\r')


def poss_ends(step_count, diff1, diff2):
	poss_set = {diff1, diff2}
	for i in range(step_count - 2):
		new_set = set()
		for poss in poss_set:
			new_set.add(poss + diff1)
			new_set.add(poss + diff2)
		poss_set = new_set
	poss_list = list(poss_set)
	poss_list.sort()
	return poss_list
test_count = int(input())
for i in range(test_count):
	step_count = int(input())
	diff1 = int(input())
	diff2 = int(input())
	poss_list = poss_ends(step_count, diff1, diff2)
	for poss in poss_list:
		print(poss, end=' ')
	print()


t = int(input())
for i in range(t):
	w = []
	s = int(input())
	a = int(input())
	b = int(input())
	for j in range(s):
		w.append((s - j - 1) * a + b * j)
	u = ''
	for e in sorted(list(set(w))):
		u += str(e) + ' '
	print(u)


t = int(input())
for caseNr in range(t):
	S = set()
	n = int(input())
	a = int(input())
	b = int(input())
	for i in range(n):
		S.add(a * i + b * (n - i - 1))
	for s in sorted(S):
		print(s, end=' ')
	print()


t = int(input().strip())
while t > 0:
	n = int(input().strip())
	a = int(input().strip())
	b = int(input().strip())
	stonesum = min(a, b) * (n - 1)
	largest = max(a, b) * (n - 1)
	step = abs(a - b)
	print(stonesum, end=' ')
	while stonesum < largest:
		stonesum = stonesum + step
		print(stonesum, end=' ')
	print()
	t = t - 1


def main():
	T = int(input())
	for x in range(T):
		n = int(input())
		a = int(input())
		b = int(input())
		val = 0
		if a == b:
			print(a * (n - 1))
			continue
		if a < b:
			for x in range(n):
				val = (n - x - 1) * a + x * b
				print(str(val) + ' ', end='')
			print('')
		else:
			for x in range(n):
				val = (n - x - 1) * b + x * a
				print(str(val) + ' ', end='')
			print('')
main()


T = int(input())

def contains(element, array):
	for e in array:
		if e == element:
			return True
	return False

def filterDublicates(array):
	counted = []
	for e in array:
		if not contains(e, counted):
			counted.append(e)
	return counted

def calcEndStones(n, a, b, currentStone, endStones):
	if n > 1:
		calcEndStones(n - 1, a, b, currentStone + a, endStones)
		calcEndStones(n - 1, a, b, currentStone + b, endStones)
	else:
		endStones.append(currentStone)
		endStones.append(currentStone)

def calcEndStones2(n, a, b, currentStone, endStones):
	delta = b - a if b >= a else a - b
	endStones.append((a if b >= a else b) * (n - 1))
	for i in range(1, n):
		endStones.append(endStones[-1] + delta)
for i in range(T):
	N = int(input())
	A = int(input())
	B = int(input())
	endStones = []
	calcEndStones2(N, A, B, 0, endStones)
	endStones = filterDublicates(endStones)
	endStones.sort()
	answer = ''
	for e in endStones:
		answer += str(e) + ' '
	print(answer)


T = int(input())
for i in range(0, T):
	numberOfStones = int(input())
	a = int(input())
	b = int(input())
	possibleLastStones = []
	for i in range(0, numberOfStones):
		possibleStone = a * i + b * (numberOfStones - i - 1)
		if possibleStone not in possibleLastStones:
			possibleLastStones.append(possibleStone)
	for number in sorted(possibleLastStones):
		print(number, end=' ')
	print()


def last_stone(num, a, b):
	return sorted(list(set([x * a + (num - x - 1) * b for x in range(num)])))
for case in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	for answer in last_stone(n, a, b):
		print(answer, end=' ')
	print()


T = int(input())
for case in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	result = []
	for i in range(n):
		curres = a * i + b * (n - 1 - i)
		if curres not in result:
			result.append(curres)
	result.sort()
	for i in result:
		print(i, end=' ')
	print()


test = int(input())
while test:
	test = test - 1
	n = int(input())
	a = int(input())
	b = int(input())
	st = set()
	for i in range(n):
		st.add(a * i + b * (n - i - 1))
	for t in sorted(st):
		print(t, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(a * (n - 1))
	else:
		arr = [a] * (n - 1)
		for j in range(n):
			print(sum(arr), end=' ', flush=False)
			arr[j - 1] = b
		print()


test_cases = int(input())
for case in range(test_cases):
	n = int(input())
	a = int(input())
	b = int(input())
	final_str = ''
	for i in range(n):
		if a < b:
			final_str += str(a * (n - 1 - i) + b * i) + ' '
		elif b < a:
			final_str += str(b * (n - 1 - i) + a * i) + ' '
		else:
			final_str = str(a * (n - 1))
	print(final_str)


N = int(input())
solutions = []
remove = []
for times in range(N):
	output = ''
	t = int(input())
	a = int(input())
	b = int(input())
	for i in range(t):
		if a > b:
			solutions.append(a * i + b * (t - 1 - i))
		elif b > a:
			solutions.append(a * (t - 1 - i) + b * i)
		else:
			solutions.append(a * (t - 1))
			break
	for i in range(0, len(solutions)):
		output += str(solutions[i]) + ' '
	print(output)
	solutions.clear()
	remove.clear()