Kshitij has recently started solving problems on codechef. As he is real problem solving enthusiast, he wants continuous growth in number of problems solved per day.
He started with $a$  problems on first day. 
He solves $d$ problems more than previous day. But after every $k$ days , he increases $d$ by
$inc$ .
Can you guess how many questions he will solve on $nth $ day ?

-----Input:-----
- First line  contains $T$, number of testcases. Then the testcases follow. 
- Each testcase contains of a single line of input,five integers $a, d, k, n, inc$. 

-----Output:-----
For each testcase, output in a single line number of questions solved on $nth$ day.

-----Constraints-----
- $1 \leq T \leq 15$
- $1 \leq a \leq 99$
- $1 \leq d \leq 100$
- $1 \leq n \leq 10000$
- $1 \leq k \leq n$
- $0 \leq inc \leq 99$

-----Sample Input:-----
1
1 4 3 8 2

-----Sample Output:-----
43

-----EXPLANATION:-----
The number of questions solved in first 8 days is :
$1$ $5$ $9$ $15$ $21$ $27$ $35$ $43$ .
On first day he solved 1 problem . Here $d$ is  4 for first 3 days.
Then after 3 days $d$ increases by 2 (that is 6).

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
t = int(input())
for _ in range(t):
	(a, d, k, n, inc) = map(int, input().strip().split())
	res = a
	for i in range(1, n):
		if i % k == 0:
			d += inc
		res += d
	print(res)


try:
	for i in range(int(input())):
		inp = list(map(int, input().split()))
		for i in range(2, inp[3] + 1):
			if inp[3] == 1:
				break
			inp[0] += inp[1]
			if int(i % inp[2]) == 0:
				inp[1] += inp[4]
		print(inp[0])
except:
	pass


t = int(input())
for i in range(t):
	(a, d, k, n, inc) = map(int, input().split())
	for i in range(1, n):
		if i % k == 0:
			d = d + inc
			a = a + d
		else:
			a = a + d
	print(a)


try:
	for i in range(int(input())):
		a1 = list(map(int, input().split()))
		a = a1[0]
		d = a1[1]
		k = a1[2]
		n = a1[3]
		inc = a1[4]
		for i in range(1, n):
			if i % k == 0:
				d = d + inc
			a = a + d
		print(a)
except:
	pass


t = int(input())
for i in range(t):
	(a, d, k, n, inc) = map(int, input().split())
	l = [a]
	for i in range(2, n + 1):
		a += d
		l.append(a)
		if i % k == 0:
			d += inc
	print(l[n - 1])


import sys, math, collections
from collections import defaultdict

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

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

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def chk(aa, bb):
	f = 0
	for i in aa:
		for j in bb:
			if j[0] >= i[0] and j[1] <= i[1]:
				f += 1
			elif j[0] <= i[0] and j[1] >= i[1]:
				f += 1
			elif i[0] == j[1] or i[1] == j[0]:
				f += 1
			else:
				continue
	return f

def main():
	for tt in range(int(input())):
		(a, d, k, n, inc) = get_ints()
		j = 1
		for i in range(n - 1):
			if j == k:
				d += inc
				j = 1
			else:
				j += 1
			a = a + d
		print(a)

def __starting_point():
	main()
__starting_point()


try:
	t = int(input())
	ans = []
	while t > 0:
		t -= 1
		li = list(map(int, input().split()))
		a = li[0]
		d = li[1]
		k = li[2]
		n = li[3]
		inc = li[4]
		for i in range(1, n):
			if i % k == 0:
				d = d + inc
			a = a + d
		ans.append(a)
	for i in ans:
		print(i)
except:
	pass


p = int(input())
for j in range(p):
	(a, d, k, n, inc) = list(map(int, input().split()))
	l = [a]
	for i in range(2, n + 1):
		a = a + d
		l.append(a)
		if i % k == 0:
			d = d + inc
	print(l[n - 1])


T = int(input())
for i in range(T):
	(a, d, k, n, inc) = list(map(int, input().split()))
	for i in range(1, n + 1):
		if i == 1:
			a = a
		elif i % k != 0:
			a += d
		else:
			a += d
			d += inc
	print(a)


for _ in range(int(input())):
	(a, d, k, n, inc) = map(int, input().split())
	sum = a
	for i in range(1, n):
		if i % k == 0:
			d = d + inc
		sum = sum + d
	print(sum)


t = int(input())
while t > 0:
	t -= 1
	(a, d, k, n, inc) = map(int, input().split())
	s = a
	count = 1
	for i in range(1, n):
		if count == k:
			d += inc
			count = 0
		s = s + d
		count += 1
	print(s)


t = int(input())
for _ in range(t):
	(a, d, k, n, inc) = map(int, input().split())
	a -= d
	day = 0
	while day < n:
		for j in range(k):
			a += d
			day += 1
			if day == n:
				break
		d += inc
	print(a)


try:
	for _ in range(int(input())):
		(a, d, k, n, inc) = map(int, input().split())
		p = 0
		s = a
		for i in range(n // k):
			if i == 0:
				s += (k - 1) * d
				d += inc
			else:
				s += k * d
				d += inc
		s += n % k * d
		print(s)
except:
	pass


for _ in range(int(input())):
	(a, d, k, n, inc) = list(map(int, input().split()))
	ans = a
	for i in range(2, n + 1):
		if i % k != 1:
			ans = ans + d
		else:
			d = d + inc
			ans = ans + d
	print(ans)


for i in range(int(input())):
	(a1, d, k, n, inc) = list(map(int, input().split()))
	a = [a1]
	for i in range(1, n):
		if i % k == 0:
			d += inc
		a.append(a[i - 1] + d)
	print(a[n - 1])


t = int(input())
for _ in range(t):
	(a, d, k, n, inc) = list(map(int, input().split()))
	if n % k == 0:
		c = n // k
	else:
		c = n // k + 1
	while c > 0:
		s = a + (k - 1) * d
		d = d + inc
		a = s + d
		c = c - 1
	if n % k == 0:
		print(s)
	else:
		r = n % k
		r1 = k - r
		print(s - r1 * (d - inc))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	for i in range(l[-2] - 1):
		if (i + 1) % l[2] == 0:
			l[1] += l[-1]
		l[0] += l[1]
	print(l[0])


for _ in range(int(input())):
	(a, d, k, n, inc) = list(map(int, input().split()))
	sum1 = a
	for i in range(0, n):
		if i == 0:
			pass
		else:
			if i % k == 0:
				d += inc
			sum1 += d
	print(sum1)


t = int(input())
while t:
	(a, d, k, n, inc) = map(int, input().split())
	n -= 1
	if inc and n >= k:
		a += d * (k - 1)
		n -= k - 1
		d += inc
		while k <= n:
			a += d * k
			d += inc
			n -= k
	if n:
		a += d * n
	print(a)
	t -= 1