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.

Source: hackerrank | Difficulty: EASY
Tags: Implementation


Solutions:
T = int(input())
for test_case in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	s = set()
	for i in range(n):
		s.add(b * i + (n - i - 1) * a)
	print(' '.join(map(str, sorted(s))))


T = int(input())
for t in range(T):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	if a == b:
		print(n * a)
	else:
		if a > b:
			(a, b) = (b, a)
		l = []
		for i in range(0, n + 1):
			l.append(str(i * b + (n - i) * a))
		print(' '.join(l))


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 i in range(t):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	ans = set()
	for j in range(n + 1):
		ans.add(a * (n - j) + b * j)
	print(' '.join((str(i) for i in sorted(ans))))


t = int(input())
for i in range(t):
	(n, a, b) = (int(input()), int(input()), int(input()))
	l = list(set([x * a + (n - 1 - x) * b for x in range(n)]))
	l.sort()
	print('%s' % ' '.join(map(str, l)))


def process(n, a, b):
	result = set()
	for i in range(n + 1):
		result.add(i * a + (n - i) * b)
	print(*sorted(result))
T = int(input())
for cs in range(T):
	(n, a, b) = [int(input()) for _ in range(3)]
	process(n - 1, a, b)


T = int(input())
for i in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	result = []
	for j in range(n):
		result.append(j * a + (n - 1 - j) * b)
	result = list(set(result))
	result = sorted(result)
	print(' '.join((str(x) for x in result)))


call = lambda f: f()

def one_test(n, a, b):
	(a, b) = sorted([a, b])
	n -= 1
	if a == b:
		res = [a * n]
	else:
		res = (b * i + a * (n - i) for i in range(n + 1))
	return ' '.join(map(str, res))
t = int(input())
for i in range(t):
	(n, a, b) = map(int, map(call, (input,) * 3))
	print(one_test(n, a, b))


test_cases = int(input())
outputs = [[] for t in range(test_cases)]
for case in range(test_cases):
	n = int(input())
	a = int(input())
	b = int(input())
	last = 0
	for i in range(n):
		last = b * i + a * (n - 1 - i)
		outputs[case].append(last)
for (i, case) in enumerate(outputs):
	outputs[i] = sorted(list(set(case)))
for l in outputs:
	print(' '.join(map(str, l)))


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 get_combinations(j, a, b):
	combs = [j - 1, 0]
	sums = []
	while combs[0] >= 0:
		suma = a * combs[0] + b * combs[1]
		if suma not in sums:
			sums.append(suma)
		combs[0] -= 1
		combs[1] += 1
	return sorted(sums)

def main():
	t = int(input())
	for i in range(t):
		jumps = int(input())
		a = int(input())
		b = int(input())
		sums = get_combinations(jumps, a, b)
		string = '{}'
		for i in sums[:-1]:
			string = string.format('%s {}' % i)
		print(string.format(sums[-1]))
main()


import sys
inp = iter(sys.stdin)

def read_line():
	return int(next(inp))

def resolve(steps, a, b):
	ret = []
	temp = 0
	for x in range(steps):
		a_times = (steps - x - 1) * a
		b_times = x * b
		temp = a_times + b_times
		ret.append(temp)
	unique = []
	for x in ret:
		if x not in unique:
			unique.append(x)
	unique.sort()
	return ' '.join((str(x) for x in unique))
T = read_line()
for _ in range(T):
	steps = read_line()
	a = read_line()
	b = read_line()
	print(resolve(steps, a, b))


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('')


import sys
numberOfTestCases = -1
listOfRockValues = []
tempRockAmountValue = -1
tempAValue = -1
for (index, line) in enumerate(sys.stdin):
	if numberOfTestCases == -1:
		numberOfTestCases = line
	else:
		testCaseIndex = (index - 1) % 3
		if testCaseIndex == 0:
			tempRockAmountValue = int(line.rstrip())
		elif testCaseIndex == 1:
			tempAValue = int(line.rstrip())
		else:
			listOfRockValues.append([tempRockAmountValue, tempAValue, int(line.rstrip())])

def createBitCombinations(totalAmount):
	allPossibleBitStrings = []
	nAmount = totalAmount
	bitstring = '1' * nAmount
	while nAmount >= 0:
		bitListForValue = [int(i) for i in bitstring]
		while len(bitListForValue) < totalAmount:
			bitListForValue = [0] + bitListForValue
		allPossibleBitStrings.append(bitListForValue)
		nAmount -= 1
		bitstring = '1' * nAmount
	return allPossibleBitStrings

def createPossibleValues(nAmount, aValue, bValue):
	possibleValues = []
	allPossibleBitStrings = createBitCombinations(nAmount - 1)
	for bitstring in allPossibleBitStrings:
		runningValue = 0
		for bitvalue in bitstring:
			if bitvalue:
				runningValue += aValue
			else:
				runningValue += bValue
		possibleValues.append(runningValue)
	return possibleValues

def cleanDuplicatesAndSort(uncleanList):
	cleanList = []
	for x in uncleanList:
		if x not in cleanList:
			cleanList.append(x)
	cleanList = sorted(cleanList, key=int)
	return cleanList
for rockValues in listOfRockValues:
	possibleEndValues = createPossibleValues(rockValues[0], rockValues[1], rockValues[2])
	possibleEndValues = cleanDuplicatesAndSort(possibleEndValues)
	print(' '.join(map(str, possibleEndValues)))


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('')


T = int(input())
for i in range(0, T):
	end = int(input())
	a = int(input())
	b = int(input())
	d = {}
	for j in range(0, end):
		k = end - 1 - j
		sumv = j * a + k * b
		if not sumv in d:
			d[sumv] = 1
	ls = sorted(d.keys())
	print(' '.join([str(x) for x in ls]))


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 sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	a = int(sys.stdin.readline())
	b = int(sys.stdin.readline())
	print(*sorted(set((x * a + (n - 1 - x) * b for x in range(n)))))


T = int(input())
for i in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	first_term = (n - 1) * min(a, b)
	difference = max(a, b) - min(a, b)
	printstr = str(first_term)
	if difference > 0:
		for j in range(n - 1):
			first_term += difference
			printstr += ' ' + str(first_term)
	print(printstr)


import sys
numberOfTestCases = -1
listOfRockValues = []
tempRockAmountValue = -1
tempAValue = -1
for (index, line) in enumerate(sys.stdin):
	if numberOfTestCases == -1:
		numberOfTestCases = line
	else:
		testCaseIndex = (index - 1) % 3
		if testCaseIndex == 0:
			tempRockAmountValue = int(line.rstrip())
		elif testCaseIndex == 1:
			tempAValue = int(line.rstrip())
		else:
			listOfRockValues.append([tempRockAmountValue, tempAValue, int(line.rstrip())])

def createBitCombinations(totalAmount):
	allPossibleBitStrings = []
	nAmount = totalAmount
	bitstring = '1' * nAmount
	while nAmount >= 0:
		bitListForValue = [int(i) for i in bitstring]
		while len(bitListForValue) < totalAmount:
			bitListForValue = [0] + bitListForValue
		allPossibleBitStrings.append(bitListForValue)
		nAmount -= 1
		bitstring = '1' * nAmount
	return allPossibleBitStrings

def createPossibleValues(nAmount, aValue, bValue):
	possibleValues = []
	allPossibleBitStrings = createBitCombinations(nAmount - 1)
	for bitstring in allPossibleBitStrings:
		runningValue = 0
		for bitvalue in bitstring:
			if bitvalue:
				runningValue += aValue
			else:
				runningValue += bValue
		possibleValues.append(runningValue)
	return possibleValues

def cleanDuplicatesAndSort(uncleanList):
	cleanList = []
	for x in uncleanList:
		if x not in cleanList:
			cleanList.append(x)
	cleanList = sorted(cleanList, key=int)
	return cleanList
for rockValues in listOfRockValues:
	possibleEndValues = createPossibleValues(rockValues[0], rockValues[1], rockValues[2])
	possibleEndValues = cleanDuplicatesAndSort(possibleEndValues)
	print(' '.join(map(str, possibleEndValues)))


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')


from itertools import combinations_with_replacement as cwp
ncases = int(input())
cases = []
for i in range(ncases):
	cases.append([int(input()) for _ in range(3)])
for (n, a, b) in cases:
	series = set()
	for serie in cwp([a, b], n - 1):
		series.add(sum(serie))
	print(' '.join(map(str, sorted(series))))


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 t in range(T):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	if a == b:
		print(n * a)
	else:
		if a > b:
			(a, b) = (b, a)
		l = []
		for i in range(0, n + 1):
			l.append(str(i * b + (n - i) * a))
		print(' '.join(l))


T = int(input())
for _ in range(T):
	n = int(input())
	a_in = int(input())
	b_in = int(input())
	a = min([a_in, b_in])
	b = max([a_in, b_in])
	solutions = list('')
	for i in range(n):
		test = (n - 1 - i) * a + i * b
		if test not in solutions:
			solutions.append(test)
	solutions = map(str, solutions)
	print(' '.join(solutions))


def prog2():
	for i in range(int(input())):
		(steps, a, b) = (int(input()), int(input()), int(input()))
		if steps == 0:
			print('0')
			return
		nums = []
		for i in range(steps):
			nums.append(a * i + b * (steps - 1 - i))
		print(' '.join([str(x) for x in sorted(list(set(nums)))]))
prog2()


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())

def computeValues(a, b, n):
	solutionSpace = set([0])
	for _ in range(n - 1):
		newFrontier = set()
		for currentState in solutionSpace:
			newFrontier.add(currentState + a)
			newFrontier.add(currentState + b)
		solutionSpace = newFrontier
	out = [solution for solution in solutionSpace]
	out.sort()
	print(' '.join([str(el) for el in out]))
for _ in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	computeValues(a, b, n)


def possible_values(n, a, b):
	if a == b:
		return [(n - 1) * a]
	return [i * a + (n - 1 - i) * b for i in range(n)]
T = int(input())
for _ in range(T):
	(n, a, b) = map(int, [input(), input(), input()])
	(a, b) = (max(a, b), min(a, b))
	result = possible_values(n, a, b)
	print(' '.join(map(str, result)))


import sys
inp = iter(sys.stdin)

def read_line():
	return int(next(inp))

def resolve(steps, a, b):
	ret = []
	temp = 0
	for x in range(steps):
		a_times = (steps - x - 1) * a
		b_times = x * b
		temp = a_times + b_times
		ret.append(temp)
	unique = []
	for x in ret:
		if x not in unique:
			unique.append(x)
	unique.sort()
	return ' '.join((str(x) for x in unique))
T = read_line()
for _ in range(T):
	steps = read_line()
	a = read_line()
	b = read_line()
	print(resolve(steps, a, b))


for _ in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	s = set()
	for i in range(0, n):
		s.add(a * i + (n - i - 1) * b)
	print(' '.join((str(x) for x in sorted(list(s)))))


t = int(input())
for i in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	cur = set([0])
	for step in range(n - 1):
		next = set()
		for val in cur:
			next.add(val + a)
			next.add(val + b)
		cur = next
	output = [str(num) for num in sorted(list(cur))]
	print(' '.join(output))


def find_possible_ends(n, a, b):
	ends = []
	for i in range(n):
		ends.append(str(int(a * (n - 1 - i) + b * i)))
	return ends
count = int(input())
ends = []
for i in range(count):
	n = int(input())
	a = int(input())
	b = int(input())
	if a == b:
		ends = [str(a * (n - 1))]
	elif a < b:
		ends = find_possible_ends(n, a, b)
	else:
		ends = find_possible_ends(n, b, a)
	print(' '.join(ends))


t = int(input())
for _ in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	result = []
	for i in range(n):
		result += [i * a + b * (n - i - 1)]
	print(str(sorted(list(set(result))))[1:-1].replace(',', ''))


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()


def possible_values(n, a, b):
	values = set([0])
	for _ in range(n - 1):
		values_a = set([x + a for x in values])
		values_b = set([x + b for x in values])
		values = values_a.union(values_b)
	return values
cases = int(input())
for _ in range(cases):
	n = int(input())
	a = int(input())
	b = int(input())
	values = possible_values(n, a, b)
	values = list(values)
	values.sort()
	print(' '.join(map(str, values)))


def findLasts(n, a, b):
	s = []
	j = 0
	k = n - 1
	while j < n and k >= 0:
		i = k * a + j * b
		s.append(i)
		j += 1
		k -= 1
	s = list(set(s))
	s.sort()
	p = convert(s)
	return p

def convert(l):
	s = ''
	for elem in l[:-1]:
		s = s + str(elem) + ' '
	s = s + str(l[-1])
	return s
T = int(input())
while T > 0:
	n = int(input())
	a = int(input())
	b = int(input())
	o = findLasts(n, a, b)
	print(o)
	T -= 1


for i in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	s = {k * a + (n - k - 1) * b for k in range(0, n)}
	print(' '.join(map(str, sorted(s))))


for _ in range(int(input())):
	setvalue = set()
	n = int(input())
	a = int(input())
	b = int(input())
	for x in range(0, n):
		setvalue.add(x * a + (n - x - 1) * b)
	setvalue = sorted(list(setvalue))
	setvalue = map(str, setvalue)
	print(' '.join(setvalue))


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


T = int(input())
for _ in range(T):
	(n, a, b) = (int(input()), int(input()), int(input()))
	if a == b:
		print((n - 1) * b)
	else:
		if a < b:
			(a, b) = (b, a)
		print(' '.join((str(k * a + (n - 1 - k) * b) for k in range(n))))


import sys, random
T = int(sys.stdin.readline())
for t in range(T):
	n = int(sys.stdin.readline())
	a = int(sys.stdin.readline())
	b = int(sys.stdin.readline())
	step_list = [a, b]
	last_stone_list = []
	for k in range(n):
		stone_list = [0]
		step_list = [a] * k + [b] * (n - 1 - k)
		last_stone = sum(step_list)
		if last_stone not in last_stone_list:
			last_stone_list.append(last_stone)
	last_stone_list.sort()
	print(' '.join(map(str, last_stone_list)))


from itertools import combinations_with_replacement

def generate_stone_paths(n, a, b):
	for c in combinations_with_replacement([a, b], n - 1):
		l = [0]
		for (num, delta) in zip(l, c):
			l.append(num + delta)
		yield l
t = int(input())
for i in range(t):
	(n, a, b) = [int(input()) for i in range(3)]
	final_stones = set((c[-1] for c in generate_stone_paths(n, a, b)))
	print(' '.join((str(c) for c in sorted(final_stones))))


def possibilities(stones, a, b):
	if a < b:
		(a, b) = (b, a)
	elif a == b:
		return str(stones * a)
	res = []
	for i in range(stones + 1):
		res += [a * i + b * (stones - i)]
	return ' '.join([str(x) for x in res])
test_cases = int(input())
while test_cases > 0:
	test_cases -= 1
	stones = int(input()) - 1
	a = int(input())
	b = int(input())
	print(possibilities(stones, a, b))


for t in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	vals = {}
	for i in range(n):
		vals[str((n - i - 1) * a + i * b)] = True
	print(' '.join(sorted(vals, key=lambda x: int(x))))


def enumerate_possibilities(n, a, b):
	assert n >= 1
	if n == 1:
		return [0]
	elif a == b:
		return [(n - 1) * a]
	else:
		if a < b:
			(a, b) = (b, a)
		l = range(n)

		def f(x, y):
			return x * a + y * b
		return list(map(f, l, reversed(l)))
for i in range(int(input())):
	print(*enumerate_possibilities(int(input()), int(input()), int(input())))


def stones(n, a, b):
	combinations = set()
	for i in range(n):
		combinations.add(i * a + (n - 1 - i) * b)
	combinations = list(combinations)
	combinations.sort()
	return combinations
testCases = int(input())
for i in range(testCases):
	n = int(input())
	a = int(input())
	b = int(input())
	print(' '.join(map(str, stones(n, a, b))))


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)


from itertools import combinations_with_replacement
for i in range(int(input())):
	n = int(input())
	print(' '.join([str(sum(c)) for c in combinations_with_replacement(sorted(set([int(input()), int(input())])), n - 1)]))


n = int(input())
for a in range(0, n):
	T = int(input()) - 1
	a = int(input())
	b = int(input())
	ct = 1
	solns = []
	for c in range(0, T + 1):
		solns.append(str(c * a + (T - c) * b))
	s = list(set(solns))
	s.sort(key=int)
	print(' '.join(s))


def step(n, a, b):
	if a > b:
		(a, b) = (b, a)
	x = (n - 1) * a
	if a == b:
		return [x]
	d = b - a
	return [x + i * d for i in range(n)]
for t in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	print(*step(n, a, b), sep=' ')


for _ in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	if a == b:
		print(a * (n - 1))
	else:
		print(' '.join(map(str, range(min([a, b]) * (n - 1), max([a, b]) * (n - 1) + 1, abs(a - b)))))


T = int(input())
for _ in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	k = n - 1
	if a > b:
		(a, b) = (b, a)
	if a == b:
		result = [k * a]
	else:
		result = [b * i + a * (k - i) for i in range(k + 1)]
	print(*result, sep=' ')


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()


for _ in range(int(input())):
	(limit, a, b) = (int(input()), int(input()), int(input()))
	result = []
	i = 0
	while i <= limit - 1:
		result.append((limit - 1 - i) * a + i * b)
		i += 1
	result = list(set(result))
	result.sort()
	print(' '.join((str(x) for x in result)))


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()


for i in range(int(input())):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	(a, b) = sorted((a, b))
	if a == b:
		print(a * n)
	else:
		print(' '.join((str(e) for e in range(a * n, b * n + 1, b - a))))


for _ in range(int(input())):
	s = set()
	n = int(input())
	a = int(input())
	b = int(input())
	for i in range(0, n):
		s.add(i * a + (n - i - 1) * b)
	s = list(s)
	s = sorted(s)
	s = map(str, s)
	print(' '.join(s))


cases = int(input())

def run_task(n, a, b):
	(a, b) = (min(a, b), max(a, b))
	result = [a * (n - 1)]
	if a == b:
		return [str(result[0])]
	diff = b - a
	while result[-1] + diff <= b * (n - 1):
		result.append(result[-1] + diff)
	return map(str, result)
for _ in range(cases):
	(n, a, b) = (int(input()), int(input()), int(input()))
	print(' '.join(run_task(n, a, b)))


T = int(input())
for i in range(T):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(a * n)
	else:
		answer = ' '.join([str(x) for x in range(a * n, b * n + 1, b - a)])
		print(answer)


def solve(N, a, b):
	sol = set()
	for p1 in range((N - 1) // 2 + 1):
		sol |= {p1 * a + (N - 1 - p1) * b}
		sol |= {p1 * b + (N - 1 - p1) * a}
	print(' '.join(map(str, sorted(list(sol)))))
for _ in range(int(input())):
	N = int(input())
	a = int(input())
	b = int(input())
	solve(N, a, b)


t = int(input())
for i in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	sums = []
	for i in range(n):
		sums.append(a * i + b * (n - i - 1))
	print(' '.join([str(s) for s in sorted(set(sums))]))


T = int(input())
for t in range(T):
	(n, a, b) = [int(input()) for i in range(3)]
	possibles = set()
	if a < b:
		(a, b) = (b, a)
	current = (n - 1) * b
	for i in range(n):
		possibles.add(current)
		current += a - b
	print(' '.join([str(i) for i in sorted(possibles)]))


def manasa(n, a, b):
	nums = {0}
	for i in range(n - 1):
		new_nums = set()
		for j in nums:
			new_nums.add(j + a)
			new_nums.add(j + b)
		nums = new_nums
	return sorted(new_nums)
t = int(input())
for i in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	print(' '.join([str(x) for x in manasa(n, a, b)]))


T = int(input())
for _ in range(T):
	s = set()
	n = int(input())
	a = int(input())
	b = int(input())
	for i in range(0, n):
		s.add(i * a + (n - i - 1) * b)
	s = list(s)
	s = sorted(s)
	print(' '.join(map(str, s)))


T = int(input())
for i in range(T):
	(n, a, b) = (int(input()) for i in range(3))
	n -= 1
	answers = set()
	for i in range(n + 1):
		j = n - i
		answers.add(i * a + j * b)
	print(' '.join(map(str, sorted(answers))))


length = int(input())
for i in range(0, length):
	k = int(input())
	a = int(input())
	b = int(input())
	c = max(a, b)
	d = min(a, b)
	if c != d:
		for i in range(0, k - 1):
			print((k - 1) * d + (c - d) * i, end=' ')
		print((k - 1) * c)
	else:
		print((k - 1) * c)


num_cases = int(input())
for i in range(num_cases):
	length = int(input())
	poss_lasts = []
	a = int(input())
	b = int(input())
	for j in range(length):
		s = a * j + b * (length - j - 1)
		if not s in poss_lasts:
			poss_lasts.append(s)
	poss_lasts.sort()
	print(' '.join(map(str, poss_lasts)))


def get_answers(n, a, b):
	answers = list(set([a * (n - i - 1) + b * i for i in range(0, n)]))
	print(' '.join((str(x) for x in sorted(answers))))
for i in range(0, int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	get_answers(n, a, b)


T = int(input())
for i in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	if a == b:
		print(a * (n - 1))
	elif n == 0 or n == 1:
		print(0)
	else:
		l = set()
		for j in range(0, n):
			l.add(j * a + (n - j - 1) * b)
		print(str(sorted(list(l))).replace(',', '').replace('[', '').replace(']', ''))


def solve(num_stones, a, b):
	if a == b:
		return [(num_stones - 1) * a]
	(a, b) = (min(a, b), max(a, b))
	last_stones = []
	for i in range(num_stones - 1, -1, -1):
		last_stones.append(a * i + b * (num_stones - 1 - i))
	return last_stones

def main():
	T = int(input())
	for _ in range(T):
		n = int(input())
		a = int(input())
		b = int(input())
		print(' '.join(map(str, solve(n, a, b))))
main()


def lastStoneList(n, a, b):
	listOfPossibilities = []
	for i in range(n):
		possibility = a * i + b * (n - i - 1)
		if listOfPossibilities.count(possibility) == 0:
			listOfPossibilities.append(possibility)
	listOfPossibilities.sort(key=lambda x: x)
	return ' '.join([str(i) for i in listOfPossibilities])

def getInput():
	return int(input())
testCases = getInput()
for i in range(testCases):
	n = getInput()
	a = getInput()
	b = getInput()
	print(lastStoneList(n, a, b))


t = int(input())
for _ in range(t):
	n = int(input())
	a = int(input())
	b = int(input())
	l = set()
	for i in range(n):
		l.add(i * a + (n - i - 1) * b)
	print(' '.join(map(str, sorted(list(l)))))


T = int(input())
testcases = []
for c in range(T):
	n = int(input()) - 1
	a = int(input())
	b = int(input())
	onetest = [n, a, b]
	testcases.append(onetest)

def printlist(lst):
	ans = ''
	for x in lst:
		ans += str(x) + ' '
	return ans[:-1]

def allfinals(nab):
	(n, a, b) = nab
	results = []
	for i in range(n)[::-1]:
		results.append(i * a + (n - i) * b)
	results.append(n * a)
	results = sorted(results)
	results = removeduplicate(results, what='list')
	return results

def removeduplicate(inp, what='string'):
	if what == 'string':
		nondup = ''
		for x in inp:
			if x not in nondup:
				nondup += x
		return nondup
	if what == 'list':
		nondup = []
		for x in inp:
			if x not in nondup:
				nondup.append(x)
		return nondup
outlist = []
for eachtest in testcases:
	results = allfinals(eachtest)
	outlist.append(results)
for lst in outlist:
	print(printlist(lst))


def solve(stones, a, b):
	results = set()
	for i in range(stones):
		j = stones - 1 - i
		results.add(i * a + j * b)
	return results

def read_testcase():
	stones = int(input())
	a = int(input())
	b = int(input())
	return (stones, a, b)

def main():
	testcases = int(input())
	tests = [solve(*read_testcase()) for _ in range(testcases)]
	for results in tests:
		print(' '.join((str(result) for result in sorted(results))))
main()


T = int(input())
for _ in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	print(*sorted(set((x * a + (n - 1 - x) * b for x in range(n)))))


def remove_dub(seq):
	seen = set()
	seen_add = seen.add
	return [x for x in seq if not (x in seen or seen_add(x))]
T = int(input())
for case in range(T):
	answer = []
	n = int(input())
	a = int(input())
	b = int(input())
	if b < a:
		t = a
		a = b
		b = t
	for amount_as in range(n):
		answer.append(amount_as * b + (n - 1 - amount_as) * a)
	print(' '.join(map(str, remove_dub(answer))))


cases = int(input())
i = 1
while i <= cases:
	n = int(input())
	a = int(input())
	b = int(input())
	if a == b:
		print(a * (n - 1))
	else:
		dist = [j * a + (n - j - 1) * b for j in range(n)]
		dist = sorted(dist)
		dist = map(str, dist)
		print(' '.join(dist))
	i = i + 1


def treasure(n, a, b):
	h = {}
	for i in range(n):
		total = i * a + (n - 1 - i) * b
		h[total] = 1
	return sorted(list(h.keys()))
for i in range(int(input())):
	n = int(input())
	l = sorted([int(input()), int(input())])
	(b, a) = l
	print(' '.join([str(x) for x in treasure(n, a, b)]))


import sys

def solve(n, a, b):
	r = set([a, b])
	for i in range(n - 2):
		s = set()
		for j in r:
			s.add(j + a)
			s.add(j + b)
		r = s
	return r
T = int(sys.stdin.readline().strip())
for t in range(T):
	n = int(sys.stdin.readline().strip())
	a = int(sys.stdin.readline().strip())
	b = int(sys.stdin.readline().strip())
	print(' '.join(map(str, sorted(solve(n, a, b)))))


for _ in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	res = set([0])
	for i in range(1, n):
		new = set()
		for x in res:
			new.add(x + a)
			new.add(x + b)
		res = new
	print(*sorted(res))


for t in range(int(input())):
	n = int(input())
	a = int(input())
	b = int(input())
	end = []
	x = 0
	for i in range(n):
		end.append(int(i * a + (n - 1) * b))
		n -= 1
	end = list(set(end))
	end.sort()
	print(' '.join((str(x) for x in end)))


T = int(input())
for _ in range(T):
	(n, a, b) = (int(input()), int(input()), int(input()))
	s = set()
	for i in range(n):
		s.add(b * i + (n - i - 1) * a)
	print(' '.join(map(str, sorted(s))))


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()


import sys

def main(argv=None):
	if argv is None:
		argv = sys.argv
T = int(input())
for t in range(0, T):
	nbStone = int(input())
	incA = int(input())
	incB = int(input())
	solutions = set([0])
	for i in range(1, nbStone):
		newSolution = set()
		for val in solutions:
			newSolution.add(val + incA)
			newSolution.add(val + incB)
		solutions = newSolution
	print(' '.join(map(str, sorted(solutions))))
sys.exit(main())


def finalStone(n, a, b):
	if a == b:
		yield ((n - 1) * a)
	else:
		if b < a:
			(a, b) = (b, a)
		for i in range(n):
			yield ((n - i - 1) * a + i * b)
T = int(input())
for i in range(T):
	count = int(input())
	a = int(input())
	b = int(input())
	print(' '.join((str(v) for v in finalStone(count, a, b))))


def calc(a, b, k):
	posslist = []
	for x in range(k):
		posslist.append(x * a + (k - x - 1) * b)
	posslist = list(set(posslist))
	posslist.sort()
	result = ''
	for element in posslist:
		result += ' '
		result += str(element)
	return result[1:]
tcs = int(input())
for tc in range(tcs):
	k = int(input())
	a = int(input())
	b = int(input())
	print(calc(a, b, k))


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()


T = int(input())
for _ in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	results = set()
	for i in range(n):
		results.add(a * i + b * (n - 1 - i))
	print(*sorted(list(results)))


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	a = int(sys.stdin.readline())
	b = int(sys.stdin.readline())
	print(*sorted(set((x * a + (n - 1 - x) * b for x in range(n)))))


t = int(input())
for i in range(t):
	r = []
	n = int(input())
	a = int(input())
	b = int(input())
	for i in range(n):
		d = a * i + (n - i - 1) * b
		if d not in r:
			r.append(a * i + (n - i - 1) * b)
			r.sort()
	print('%s' % ' '.join(map(str, r)))


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)


T = int(input())
for i in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	answer = []
	finalSet = set([0])
	for j in range(n - 1):
		newSet = set([])
		for k in finalSet:
			newSet.add(k + a)
			newSet.add(k + b)
		finalSet = newSet
	array = []
	for j in finalSet:
		array.append(j)
	array = sorted(array)
	strArray = []
	for j in array:
		strArray.append(str(j))
	print(' '.join(strArray))


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()


intput = lambda : int(input())
T = intput()
for _ in range(T):
	(n, a, b) = [intput() for _ in range(3)]
	N = n - 1
	out = set((a * x + b * (N - x) for x in range(0, N + 1)))
	out = map(str, sorted(out))
	print(' '.join(out))


T = int(input())
for testcase in range(T):
	n = int(input())
	a = int(input())
	b = int(input())
	possible = set([0])
	for i in range(n - 1):
		p_n = set()
		for p_t in possible:
			for a_t in [a, b]:
				p_n.add(p_t + a_t)
		possible = p_n
	print(' '.join([str(x) for x in sorted(possible)]))