There is a special offer in Vasya's favourite supermarket: if the customer buys $a$ chocolate bars, he or she may take $b$ additional bars for free. This special offer can be used any number of times.

Vasya currently has $s$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $c$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 100$) — the number of testcases.

Each of the next $t$ lines contains four integers $s, a, b, c~(1 \le s, a, b, c \le 10^9)$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.


-----Output-----

Print $t$ lines. $i$-th line should contain the maximum possible number of chocolate bars Vasya can get in $i$-th test.


-----Example-----
Input
2
10 3 1 1
1000000000 1 1000000000 1

Output
13
1000000001000000000



-----Note-----

In the first test of the example Vasya can buy $9$ bars, get $3$ for free, buy another bar, and so he will get $13$ bars.

In the second test Vasya buys $1000000000$ bars and gets $1000000000000000000$ for free. So he has $1000000001000000000$ bars.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
qq = int(input())
for i in range(qq):
	(s, a, b, c) = map(int, input().split())
	ww = int(s / (a * c)) * b
	we = int(s / c)
	print(ww + we)


t = int(input())
while t:
	(s, a, b, c) = map(int, input().split())
	totc = s // c
	ext = totc // a * b
	print(totc + ext)
	t -= 1


t = int(input())
snt = 0
add = 0
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	snt = s // c
	x = snt // a
	add = x * b
	print(snt + add)
	snt = 0
	add = 0


def main():
	t = int(input())
	arr = []
	for i in range(t):
		arr.append(input().split())
	for e in arr:
		num = int(e[0]) // int(e[3])
		gift = num // int(e[1]) * int(e[2])
		print(num + gift)
main()


def main():
	t = int(input(''))
	while t > 0:
		lista = input('').split()
		calcular(lista[0], lista[1], lista[2], lista[3])
		t -= 1

def calcular(s, a, b, c):
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	comprando = s // c
	gratis = comprando // a * b
	print(comprando + gratis)
main()


T = int(input())
for q in range(T):
	(s, a, b, c) = map(int, input().strip().split())
	x = s // c
	t = x // a * b
	x += t
	print(x)


t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, input().split())
	print(s // c + s // c // a * b)


t = int(input())
while t:
	t -= 1
	(s, a, b, c) = [int(x) for x in input().split()]
	tot = s // c
	ans = tot + tot // a * b
	print(ans)


def fun():
	t = int(input())
	for i in range(t):
		lst = input().split(' ')
		lst = [int(x) for x in lst]
		sum = lst[0] // lst[3]
		sum += sum // lst[1] * lst[2]
		print(sum)
fun()


for i in range(int(input())):
	d = list(map(int, input().split(' ')))
	print(d[0] // d[3] + d[0] // d[3] // d[1] * d[2])


n = int(input())
for i in range(n):
	(s, a, b, c) = list(map(int, input().split()))
	print(s // c + s // (c * a) * b)


q = int(input())
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	print(a // d + c * (a // d // b))


for x in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	bar = s // (a * c) * b
	choc = s // c
	print(bar + choc)


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	k = int(s / c)
	if k < a:
		print(k)
	else:
		k = int(s / c)
		k += int(k / a) * b
		print(k)


t = int(input())
ss = 0
d = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	ss += s // c // a * b + s // c
	d.append(ss)
	ss = 0
for i in d:
	print(i)


from __future__ import division, print_function
import collections

def main():
	import sys
	data = iter(map(int, sys.stdin.buffer.read().decode('ascii').split()))
	t = next(data)
	res = [-1] * t
	for tid in range(t):
		(s, a, b, c) = tuple((next(data) for i in range(4)))
		nb = s // (a * c)
		res[tid] = nb * (a + b)
		s -= nb * a * c
		res[tid] += s // c
	sys.stdout.buffer.write('\n'.join((str(x) for x in res)).encode('ascii'))
	return 0
main()


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	A = s // c
	B = A // a
	print(A + B * b)


t = int(input())
result = list()
for i in range(t):
	(s, a, b, c) = map(int, input().split(' '))
	k = s // c
	l = k // a
	result.append(k + l * b)
for i in result:
	print(i)


t = int(input())
i = 1
while i <= t:
	stri = input()
	digit = stri.split(' ')
	s = int(digit[0])
	a = int(digit[1])
	b = int(digit[2])
	c = int(digit[3])
	k = s // c
	bk = k // a
	k = k + b * bk
	print(k)
	i = i + 1


a = int(input())
a2 = 0
b2 = 0
for i in range(a):
	(a1, b1, c1, d1) = map(int, input().split())
	a2 = a1 // d1
	b2 = a2
	b2 //= b1
	b2 *= c1
	a2 += b2
	print(a2)
	a2 = 0
	b2 = 0


t = int(input())
import math
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	e = math.floor(a / d)
	e += math.floor(e / b) * c
	print(e)


a = int(input())
x = a
i = 0
c = [] * 4
p = []
h = 0
while a > 0:
	b = input()
	a = a - 1
	c = b.split()
	r = int(c[i])
	t = int(c[i + 1])
	y = int(c[i + 2])
	u = int(c[i + 3])
	if r > 0 and t > 0 and (y > 0) and (u > 0):
		q = int(r / u)
		w = int(q / t)
		e = q + w * y
		p.append(e)
	else:
		b = input()
while x > 0:
	x = x - 1
	print(p[h])
	h = h + 1


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	if c > s:
		print(0)
	elif s // c < a:
		print(s // c)
	elif s // c >= a:
		print(s // c + s // c // a * b)


n = int(input())
for i in range(n):
	(argent, offre, gratos, cout) = map(int, input().split())
	tablette = 0
	while argent >= cout:
		barAchetes = argent // cout
		reste = argent % cout
		ajout = gratos * (barAchetes // offre)
		argent = reste
		tablette += barAchetes + ajout
	print(tablette)


for i in range(int(input())):
	(s, a, b, c) = list(map(int, input().split()))
	m = s // c
	ans = m // a * (a + b) + m % a
	print(ans)


n = int(input())
for i in range(n):
	inputs = input()
	inlst = list(map(int, inputs.split(' ')))
	s = inlst[0]
	a = inlst[1]
	b = inlst[2]
	c = inlst[3]
	paid = s // c
	free = paid // a * b
	count = paid + free
	print(count)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	nob = int(s / c)
	k = int(nob / a)
	tn = nob + k * b
	print(tn)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

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

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

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

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(s, a, b, c) = inar()
		take = s // (a * c)
		get = take * a + take * b
		lol = s % (a * c)
		print(get + lol // c)
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 x in range(t):
	(s, a, b, c) = map(int, input().split())
	out = 0
	temp = 0
	temp = s // c
	fcount = temp // a
	out = temp + fcount * b
	print(out)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	total = int(s / c)
	pair = int(total / a)
	print(pair * b + total)


def chocolate(lst):
	z = list()
	for elem in lst:
		z.append(elem[0] // elem[3] + elem[0] // elem[3] // elem[1] * elem[2])
	return z
n = int(input())
x = list()
for i in range(n):
	s = [int(i) for i in input().split()]
	x.append(s)
print(*chocolate(x), sep='\n')


a = int(input())
b = []
for i in range(a):
	c = input().split()
	for j in range(len(c)):
		c[j] = int(c[j])
	b.append(c)
for j in b:
	count = j[0] // j[3]
	print(count // j[1] * (j[1] + j[2]) + count % j[1])


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	chocolates = s // c
	if chocolates >= a:
		print(chocolates + b * (chocolates // a))
	else:
		print(chocolates)


t = int(input())
for i in range(0, t):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	br = s // c
	f = br // a
	fr = f * b
	print(br + fr)


t = int(input())
res = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	k = s // c
	l = k // a
	d = s - a * c * l
	e = d // c
	w = k // a
	x = w * a
	y = w * b
	res.append(x + y + e)
for i in range(t):
	print(res[i])


t = int(input())
info = []
for _ in range(t):
	info.append([int(i) for i in input().split()])
for j in info:
	bought = j[0] // j[3]
	gifts = j[2] * (bought // j[1])
	print(bought + gifts)


c = int(input())
for i in range(c):
	(s, a, b, c) = map(int, input().split())
	bought = s // c
	bonus = bought // a * b
	print(bought + bonus)


t = int(input())
for i in range(t):
	x = list(map(int, input().split()))
	temp1 = x[0] // x[3]
	temp2 = temp1 // x[1]
	x[1] = temp2 * x[2]
	final = temp1 + x[1]
	print(final)


tests = int(input())
for i in range(tests):
	(s, a, b, c) = [int(w) for w in input().split()]
	cost_packet = a * c
	res = 0
	if s >= cost_packet:
		kol_packet = s // cost_packet
		res = (a + b) * kol_packet
		ost = (s - cost_packet * kol_packet) // c
		res += ost
	else:
		res += s // c
	print(res)


for _ in range(int(input())):
	(s, a, b, c) = [int(x) for x in input().split()]
	num = s // c
	ans = num
	num //= a
	ans += num * b
	print(ans)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	max_bar = s // c
	fre_bar = max_bar // a * b
	print(max_bar + fre_bar)


t = int(input())
for i in range(t):
	arr = input().split(' ')
	s = int(arr[0])
	a = int(arr[1])
	b = int(arr[2])
	c = int(arr[3])
	print(s // c + s // c // a * b)


import math as mt
t = int(input())
for i in range(t):
	(a, b, c, d) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	barras = mt.floor(a / d)
	brinde = mt.floor(barras / b) * c
	print(barras + brinde)


t = int(input())
for I in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	buy = s // c
	extra = b * (buy // a)
	print(buy + extra)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
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 [int(x) for x in sys.stdin.readline().split()]

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

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

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

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(s, a, b, c) = LI()
		ans.append(s // c + s // c // a * b)
	for x in ans:
		print(x)
main()


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	can_buy = s // c
	cnt_package_a = can_buy // a
	add_bars = cnt_package_a * b
	ans = add_bars + can_buy
	print(ans)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	buns = int(s / (a * c))
	payed = int(s / c)
	all = payed + buns * b
	print(all)


def get_input_list():
	return list(map(int, input().split()))
t = int(input())
data = []
for _ in range(t):
	data.append(get_input_list())
for i in range(t):
	(s, a, b, c) = data[i]
	n = int(s / c)
	print(n + int(n / a) * b)


n = int(input())
for i in range(n):
	(x, a, b, c) = map(int, input().split())
	print(x // c + x // c // a * b)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(f) for f in input().split()]
	print(s // c + s // c // a * b)


query = int(input())
for _ in range(query):
	(wallet, bundle, free, rate) = map(int, input().split())
	count = 0
	r = wallet // (bundle * rate)
	count += r * (bundle + free)
	wallet -= r * bundle * rate
	count += wallet // rate
	print(count)


n = int(input())
for _ in range(n):
	(r, ch, f, cost) = [int(x) for x in input().split()]
	inc = r // cost // ch * f
	print(inc + r // cost)


testCases = int(input())
for test in range(testCases):
	sabc = [int(x) for x in input().split()]
	candiesCanBuy = sabc[0] // sabc[3]
	offerON = candiesCanBuy // sabc[1]
	offerCandies = offerON * sabc[2]
	answer = candiesCanBuy + offerCandies
	print(answer)


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = nu()
for i in range(t):
	(s, a, b, c) = num()
	z = s // c
	if z >= a:
		print(z + z // a * b)
	else:
		print(z)


def main():
	[s, a, b, c] = [int(i) for i in input().split()]
	print(s // (a * c) * (a + b) + s % (a * c) // c)
for i in range(int(input())):
	main()


def solve():
	(s, a, b, c) = map(int, input().split())
	ans = s // c
	ans += ans // a * b
	return ans
for _ in range(int(input())):
	print(solve())


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	x = s // (a * c)
	ans = x * (a + b)
	s -= x * a * c
	ans += s // c
	print(ans)


t = int(input())
for _ in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	can_buy = s // c
	with_bonus = can_buy // a
	print(with_bonus * (a + b) + (can_buy - with_bonus * a))


t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	buy = int(s / c)
	total = buy + int(buy / a) * b
	print(total)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	k = s // (a * c)
	o = s - k * a * c
	print(k * (a + b) + o // c)


t = int(input())
for q in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	print(s // c + s // c // a * b)


for i in range(int(input())):
	(m, t, n, p) = map(int, input().split())
	m = m // p
	t = m // t
	print(m + t * n)


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	k = s // c
	f = k // a * b
	print(k + f)


import math
t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	f = s // c // a * b
	print(s // c + f)


from math import floor
t = input()
t = int(t)
for i in range(t):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	print(floor(s / c) + floor(s / c / a) * b + floor((s - floor(s / c / a) * c * a) / c / a))


t = int(input())
while t > 0:
	(s, a, b, c) = map(int, input().split())
	x = s // c
	y = x // a * b
	print(x + y)
	t -= 1


for i in ' ' * int(input()):
	(s, a, b, c) = map(int, input().split())
	x = s // (a * c)
	print(x * (a + b) + s % (a * c) // c)


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

def ss():
	return [x for x in input()]

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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(s, a, b, c) = mi()
	print(s // c + s // c // a * b)


t = int(input())
for _ in range(t):
	(s, deal_qty, extra_qty, price) = map(int, input().split())
	deal_possible_times = s // (deal_qty * price)
	counter = deal_possible_times * (deal_qty + extra_qty)
	s = s % (deal_qty * price)
	regular_possible_qty = s // price
	counter += regular_possible_qty
	print(counter)


import sys
from collections import *
from math import *
import re

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

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

def lcm(a, b):
	return a * b / gcd(a, b)
max_int = sys.maxsize
mod = 10 ** 9 + 7
t = int(input())
while t:
	(s, a, b, c) = inp()
	print(s // c + s // c // a * b)
	t -= 1


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = 0
	c = 0
	d = 0
	s = 0
	h = 0
	p = 0
	b = a[0] // a[3]
	c = b // a[1]
	p = c * a[1]
	h = c * a[2]
	d = b - p
	s = p + h + d
	if a[1] > b:
		print(b)
	else:
		print(s)


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	t = s // c
	o = t // a * b
	print(t + o)


import math
T = int(input())
for x in range(T):
	(s, a, b, c) = input().split(' ')
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	buy = s // c
	buy += buy // a * b
	print(int(buy))


t = input()
t = int(t)
n = []
for i in range(t):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	totalchoc = s // c
	z = totalchoc // a
	x = z * b
	totalchoc = totalchoc + x
	n.append(totalchoc)
for i in range(t):
	print(n[i])


FREE = 0
for _ in range(int(input())):
	FREE = 0
	N = list(map(int, input().split()))
	X = N[0] // N[3]
	FREE += X
	FREE += X // N[1] * N[2]
	print(FREE)


iter = int(input())
while iter >= 1:
	[s, a, b, c] = map(int, input().split())
	temp = s // c
	print(temp + temp // a * b)
	iter -= 1


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	m = s // c
	print(m + m // a * b)


t = int(input())
for i in range(t):
	y = 0
	(s, a, b, c) = list(map(int, input().split()))
	k = s // (a * c)
	y += k * (a + b)
	y += (s - k * a * c) // c
	print(y)


testCases = int(input())
while testCases > 0:
	(s, a, b, c) = map(int, input().split())
	res = int(s / c) + int(s / (a * c)) * b
	print(res)
	testCases -= 1


t = int(input())
while t:
	(s, a, b, c) = map(int, input().split())
	ans = s // c
	print(ans + ans // a * b)
	t = t - 1


from math import ceil
t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, input().split())
	res = s // c
	res += res // a * b
	print(res)


n = int(input())
for i in range(n):
	s1 = input().split()
	s = int(s1[0])
	a = int(s1[1])
	b = int(s1[2])
	c = int(s1[3])
	ans = 0
	tmp = s // c
	ans += tmp + tmp // a * b
	print(ans)


n = int(input())
for x in range(n):
	total = 0
	(a, b, c, d) = map(int, input().split())
	m = int(a / d)
	if m < b:
		print(m)
	elif int(m / b) >= 1:
		print(m + int(m / b) * c)


t = int(input())
for x in range(0, t):
	li = [int(x) for x in input().split()]
	s = li[0]
	a = li[1]
	b = li[2]
	c = li[3]
	chocos = s // c
	frees = chocos // a
	sum1 = frees * b
	total = chocos + sum1
	print(total)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
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 [int(x) for x in sys.stdin.readline().split()]

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 main():
	t = I()
	aa = [LI() for _ in range(t)]
	rr = []
	for (s, a, b, c) in aa:
		r = s // c
		r += r // a * b
		rr.append(r)
	return '\n'.join(map(str, rr))
print(main())


n = int(input())
for i in range(0, n):
	nomber = list(map(int, input().split()))
	print(nomber[0] // nomber[3] + nomber[0] // nomber[3] // nomber[1] * nomber[2])


n = int(input())
for _ in range(n):
	l = list(map(int, input().split()))
	nc = l[0] // l[3]
	nc += nc // l[1] * l[2]
	print(nc)


tc = int(input())
for i in range(tc):
	(s, a, b, c) = map(int, input().split())
	d = s // c
	p = d // a
	p = p * b
	print(p + d)


t = int(input())
for i in range(0, t):
	q = list(map(int, input().split()))
	s = q[0]
	a = q[1]
	b = q[2]
	c = q[3]
	mon = s // c
	want = mon // a
	total = mon + want * b
	print(total)


range_ = input()
arr = []
for _ in range(int(range_)):
	arr.append([int(i) for i in input().split()])
for i in arr:
	(money, choko_acii, amount_acii, price) = i
	if money < price:
		print(0)
	else:
		print(int(round(money // price + money // price // choko_acii * amount_acii)))


t = int(input())
l = []
for i in range(t):
	l += input().split()
for i in range(len(l) // 4):
	tot = 0
	free = 0
	s = int(l[(i + 1) * 4 - 4])
	a = int(l[(i + 1) * 4 - 3])
	b = int(l[(i + 1) * 4 - 2])
	c = int(l[(i + 1) * 4 - 1])
	tot = s // c
	free = tot // a * b
	print(tot + free)


for i in range(int(input())):
	(s, a, b, c) = list(map(int, input().split()))
	nc = s // c
	if nc >= a:
		nc += nc // a * b
		print(nc)
	else:
		print(nc)


q = int(input())
s = int(0)
for i in range(q):
	(a, b, c, d) = map(int, input().split())
	ans = a // d
	s = ans // b * c
	ans += s
	print(ans)


def solve():
	t = int(input())
	result = ''
	for i in range(t):
		(s, a, b, c) = [int(x) for x in input().split(' ')]
		chocolate_bought = s // c
		total = chocolate_bought + b * (chocolate_bought // a)
		result += str(total)
		if i < t - 1:
			result += '\n'
	return result
print(solve())


n = int(input())
listInput = []
for i in range(n):
	listInput.append([int(item) for item in input().split(' ')])

def getChocolate(s, a, b, c):
	buyGet = int(s / c)
	bonusGet = int(buyGet / a) * b
	return buyGet + bonusGet
for j in range(n):
	s = listInput[j][0]
	a = listInput[j][1]
	b = listInput[j][2]
	c = listInput[j][3]
	print(getChocolate(s, a, b, c))


t = int(input())
s = []
a = []
b = []
c = []
for i in range(t):
	(q, w, e, r) = [int(el) for el in input().split()]
	s.append(q)
	a.append(w)
	b.append(e)
	c.append(r)
for i in range(t):
	k = s[i] // (a[i] * c[i])
	out = k * (a[i] + b[i]) + (s[i] - k * a[i] * c[i]) // c[i]
	print(out)


t = int(input())
for _ in range(t):
	(s, a, b, c) = list(map(int, input().split(' ')))
	totalPurchased = s // c
	freebies = s // c // a * b
	print(totalPurchased + freebies)


n = int(input())
l = []
for i in range(n):
	m = list(map(int, input().split()))
	l.append(m)
for i in l:
	buy = i[0] // i[3]
	mul = buy // i[1]
	free = mul * i[1] + mul * i[2]
	dif = buy - mul * i[1]
	print(dif + free)


n = int(input())
for i in range(n):
	(money, minCount, presCount, price) = map(int, input().split())
	res = 0
	count = int(money / price)
	res += count
	res += int(count / minCount) * presCount
	print(res)


T = int(input())
for t in range(T):
	(s, a, b, c) = map(int, input().split())
	ans = s // c
	print(ans + ans // a * b)


import sys
import os

def solve(s, a, b, c):
	return s // (a * c) * (a + b) + s % (a * c) // c

def main():
	n = int(input())
	for _ in range(n):
		(s, a, b, c) = (int(x) for x in input().split())
		print(solve(s, a, b, c))
main()


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	cho = a + b
	m = c * a
	co = s // m * cho
	m1 = s % m
	co += m1 // c
	print(co)


a = int(input())
for i in range(a):
	l = list(map(int, input().split()))
	s = l[0] // l[3]
	s = s // l[1] * l[2] + s
	print(s)


n = int(input())
g = 0
t = 0
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	g = s // (a * c)
	s -= g * a * c
	t = g * (a + b) + s // c
	print(t)


x = int(input())
i = 0
while i < x:
	i = i + 1
	y = input()
	z = y.split()
	w = [int(d) for d in z]
	budget = w[0]
	min_no = w[1]
	extra_bar = w[2]
	cost_per_bar = w[3]
	if min_no * cost_per_bar < budget:
		no_of_bars = budget // cost_per_bar + budget // cost_per_bar // min_no * extra_bar
	elif min_no * cost_per_bar == budget:
		no_of_bars = min_no + extra_bar
	else:
		no_of_bars = budget // cost_per_bar
	print(no_of_bars)


n = int(input())
info = [[] for i in range(n)]
for i in range(n):
	info[i] = list(map(int, input().split()))
for prices in info:
	col_vo_po_bon = prices[0] // (prices[1] * prices[3])
	print(col_vo_po_bon * (prices[1] + prices[2]) + prices[0] % (prices[1] * prices[3]) // prices[3])


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	chok = s // c
	k = chok // a
	chok += k * b
	print(chok)


t = int(input())
while t:
	(s, a, b, c) = map(int, input().split())
	x = s // c
	if x >= a:
		x = x + x // a * b
	print(x)
	t = t - 1


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	tmp = int(s / c)
	res = tmp + int(tmp / a) * b
	print(res)


n = int(input())
for tests in range(n):
	[money, a, b, c] = [int(i) for i in input().split()]
	chocolates = money // c
	chocolates += chocolates // a * b
	print(chocolates)


n = int(input())
answer = list()
for t in range(n):
	(s, a, b, c) = map(int, input().split(' '))
	d = s // c
	answer.append(d // a * b + d)
for t in answer:
	print(t)


from sys import stdin, stdout, setrecursionlimit
from gc import disable
disable()
gets = input
puts = print
input = stdin.readline
print = stdout.write

def main() -> int:
	t = int(input())
	for i in range(t):
		(s, a, b, c) = map(int, input().split())
		kupil = s // c
		print('%i\n' % (kupil + kupil // a * b))
	return 0
main()


tc = int(input())
while tc:
	(s, a, b, c) = map(int, input().split())
	print(s // c + s // c // a * b)
	tc -= 1


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

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

def li():
	return list(mi())
for t in range(ii()):
	(s, a, b, c) = mi()
	n = s // c
	x = n // a
	ans = n + x * b
	print(ans)


def readInput():
	lines = []
	while True:
		try:
			line = input()
			lines.append(line)
		except EOFError:
			break
	return lines

def solve(l):
	(s, a, b, c) = map(int, l.split())
	s = s // c
	return int(s // a * (a + b) + s % a)
data = readInput()
for s in data[1:]:
	print(solve(s))


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	if s >= c:
		print(s // (a * c) * (a + b) + s % (a * c) // c)
	else:
		print(0)


T = int(input())
while T:
	(s, a, b, c) = (int(x) for x in input().split())
	print(s // c + s // (a * c) * b)
	T -= 1


n = int(input())
while n:
	(s, a, b, c) = map(int, input().split())
	t = s // c
	t1 = t // a * b
	print(t + t1)
	n -= 1


from sys import *
t = int(stdin.readline())
while t:
	t -= 1
	(s, a, b, c) = map(int, stdin.readline().split())
	stdout.write('%d\n' % (s // c + s // c // a * b))


t = int(input())
for k in range(t):
	a = input().split(' ')
	a = list(map(int, a))
	print(int(int(a[0] / a[3]) / a[1]) * a[2] + int(a[0] / a[3]))


t = int(input())
for o in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	ans = s // c
	ans += b * (ans // a)
	print(ans)


import sys
import math
t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, input().split())
	print(s // c // a * b + s // c)


for i in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	alfa = s // c
	ans = alfa // a * (a + b) + alfa % a
	print(ans)


from math import *
t = int(input())
for j in range(t):
	(s, a, b, c) = map(int, input().split())
	lu = s // c
	du = lu // a
	print(s // c + du * b)


n = int(input())
res = []
for i in range(n):
	inp = input().split(' ')
	s = int(inp[0])
	a = int(inp[1])
	b = int(inp[2])
	c = int(inp[3])
	res.append(s // c + s // c // a * b)
for i in res:
	print(i)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	gs = s // c
	print(gs + gs // a * b)


t = int(input())
while t != 0:
	t -= 1
	(money, a, b, c) = [int(x) for x in input().split()]
	ans = 0
	number = money // (a * c)
	ans += number * a + number * b
	money -= number * a * c
	number = money // c
	ans += number
	print(ans)


t = int(input())
for i in range(t):
	inp = list(map(int, input().split()))
	s = inp[0]
	a = inp[1]
	b = inp[2]
	c = inp[3]
	k1 = s // (a * c)
	r = s - k1 * a * c
	k2 = r // c
	print(k1 * (a + b) + k2)


t = int(input())
for _ in range(t):
	(r, k, f, p) = map(int, input().split())
	t = r // p
	t += t // k * f
	print(t)


import math
case = int(input())
for caseNum in range(0, case):
	(money, a, b, pricePerChocolate) = [int(x) for x in input().split()]
	bought = math.floor(money / pricePerChocolate)
	discountedChoc = math.floor(bought / a) * b
	print(bought + discountedChoc)


import math
ans = []
t = int(input())
for i in range(t):
	n = input()
	q = n.split()
	s = int(q[0])
	a = int(q[1])
	b = int(q[2])
	c = int(q[3])
	d = s / (a * c)
	ans.append(math.floor(s / c) + b * math.floor(d))
for i in ans:
	print(i)


n = int(input())
x = 0
sum = 0
for i in range(n):
	(s, a, b, c) = [int(i) for i in input().split()]
	x = s // c // a * b
	sum = s // c
	print(x + sum)


t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, input().strip().split(' '))
	n1 = s // c
	n2 = n1 // a
	free = n2 * b
	max = n1 + free
	print(max)


import math
n = int(input())
for i in range(n):
	count = 0
	(roubles, buy, free, cost) = map(int, input().split())
	count += math.floor(roubles / cost)
	x = math.floor(count / buy)
	additional = x * free
	result = additional + count
	print(result)


t = int(input())
z = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	m = s // c
	if s == m * c:
		x = m + (s - m * c) + int(m / a) * b
	else:
		x = m + int(m / a) * b
	z.append(x)
for i in range(len(z)):
	print(z[i])


def solve():
	line = input()
	n = int(line.split(' ')[0])
	i = 0
	s = []
	a = []
	b = []
	c = []
	while i < n:
		line = input()
		s.append(int(line.split(' ')[0]))
		a.append(int(line.split(' ')[1]))
		b.append(int(line.split(' ')[2]))
		c.append(int(line.split(' ')[3]))
		i += 1
	i = 0
	while i < n:
		sum = int(s[i] // c[i] + s[i] // c[i] // a[i] * b[i])
		print(sum)
		i += 1
solve()


t = int(input())
i = 0
op = []
while i < t:
	(s, a, b, c) = map(int, input().split(' '))
	n = int(s / c)
	count = n + b * int(n / a)
	op.append(count)
	i += 1
j = 0
while j < t:
	print(op[j])
	j += 1


t = int(input())
if 1 <= t <= 100:
	for i in range(t):
		(s, a, b, c) = input().split()
		s = int(s)
		a = int(a)
		b = int(b)
		c = int(c)
		p = s // c
		v = p // a
		z = p + v * b
		print(z)


T = int(input())
while T > 0:
	T -= 1
	s = input().split()
	sum = int(s[0])
	a = int(s[1])
	b = int(s[2])
	c = int(s[3])
	print('%d' % (int(sum / c) + int(sum / c / a) * b))


t = int(input())
m = []
for i in range(t):
	m += [input().split(' ')]
for i in range(t):
	x = m[i]
	n = int(x[0]) // int(x[3])
	print(n + n // int(x[1]) * int(x[2]))


t = int(input())
for case in range(t):
	(s, a, b, c) = [int(x) for x in input().split(' ')]
	ans = s // (c * a) * (a + b)
	s = s % (c * a)
	ans += s // c
	print(ans)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	p = s // c
	q = p // a
	r = q * b
	print(int(p + r + (s - p * c) // c))


t = int(input())
for i in range(t):
	(s, a, b, c) = input().split(' ')
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	x = int(s / c)
	y = int(x / a)
	z = int(y * b)
	ans = int(x + z)
	print(ans)


for u in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	r = s // (a * c)
	z = r * b
	x = r * a
	y = s % (a * c) // c
	print(x + y + z)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split(' ')]
	bars_buy = int(s / c)
	bars_free = int(bars_buy / a) * b
	bars_total = bars_free + bars_buy
	print(bars_total)


T = int(input())
for t in range(T):
	(s, a, b, c) = list(map(int, input().split()))
	x = s // c
	x += x // a * b
	print(x)


def test():
	(s, a, b, c) = map(int, input().split())
	chocs = s // c
	offers = chocs // a
	print(offers * b + chocs)
	return
tests = int(input())
for t in range(tests):
	test()


n = int(input())
for i in range(n):
	ls = [int(i) for i in input().split()]
	s = ls[0]
	a = ls[1]
	b = ls[2]
	c = ls[3]
	count = 0
	soffer = s // (a * c)
	count += soffer * (a + b)
	s -= soffer * (a * c)
	count += s // c
	print(count)


for k in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	x = s // c
	y = x // a
	print(x + y * b)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	cnt = s // c
	x = cnt // a
	additional = x * b
	print(cnt + additional)


import math
import sys
DEBUG = False

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

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(S, A, B, C):
	cnt = S // C
	cnt += B * (cnt // A)
	return cnt

def main():
	T = int(inp())
	for _ in range(T):
		(S, A, B, C) = [int(e) for e in inp().split()]
		print(solve(S, A, B, C))
main()


n = input()
res = []
for x in range(int(n)):
	(s, a, b, c) = map(int, input().split())
	num = int(s / c) + int(int(int(s / c) / int(a)) * int(b))
	res.append(int(num))
for result in res:
	print(result)


offers = int(input())
for i in range(offers):
	stats = input().split()
	money = int(stats[0])
	the_deal = int(stats[1])
	free_chocks = int(stats[2])
	mpc = int(stats[3])
	chocks_bought = money // mpc
	chocks_got = chocks_bought // the_deal * free_chocks
	print(chocks_bought + chocks_got)


def choco(s, a, b, c):
	bars = s // c
	offer = bars // a
	free = offer * b
	return bars + free
t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().rstrip().split()))
	print(choco(s, a, b, c))


def main():
	for _ in range(int(input())):
		(s, a, b, c) = map(int, input().split())
		print(s // (a * c) * (a + b) + s % (a * c) // c)
main()


t = int(input())
for _ in range(0, t):
	(s, a, b, c) = tuple(map(int, input().strip().split(' ')))
	first = s // c
	num = s // (a * c)
	extra = num * b
	print(extra + first)


n1 = int(input())
for i in range(n1):
	n = list(map(int, input().split()))
	r = n[3]
	e = n[0] // (n[1] * r)
	t = (n[1] + n[2]) * e
	t = t + n[0] % (n[1] * r) // r
	print(t)


tc = int(input())
for i in range(tc):
	(s, a, b, c) = [int(x) for x in input().split()]
	ans = s // c + s // c // a * b
	print(ans)


def solve():
	global s, a, b, c
	return s // c + s // c // a * b

def main():
	global s, a, b, c
	for _ in range(int(input())):
		(s, a, b, c) = list(map(int, input().split()))
		print(solve())
main()


import sys
from math import sqrt, floor, factorial
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def c_p(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return True
	return False

def solve():
	for _ in range(int(inp())):
		(s, a, b, c) = read()
		print(s // c + b * (s // c // a))
solve()


n = eval(input())
list1 = []
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	sum1 = s // c + s // c // a * b
	list1.append(sum1)
for j in list1:
	print(j)


er = int(input())
for i in range(er):
	(t, x, y, z) = map(int, input().split())
	a = t // z
	q = a // x
	q = q * y
	print(q + a)


x = int(input())
for i in range(x):
	(s, a, b, c) = map(int, input().split())
	r = int(s / c)
	r1 = int(r / a)
	print(r1 * b + r)


n = int(input())
w = []
for i in range(n):
	l = list(map(int, input().split()))
	w.append(l)
for i in range(n):
	a = w[i][0] // (w[i][1] * w[i][3])
	f = a * w[i][2]
	g = w[i][0] // w[i][3]
	print(f + g)


n = int(input())
while n > 0:
	sabc = [int(x) for x in input().split()]
	buy_bar = sabc[0] // sabc[3]
	get_free = buy_bar // sabc[1] * sabc[2]
	print(int(buy_bar + get_free))
	n -= 1


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	d = s // c
	g = d // a
	ans = d + g * b
	print(ans)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	if s < c:
		num = 0
	else:
		buy = s // c
		times = buy // a
		extra = b * times
		num = buy + extra
	print(num)


def main():
	cases = [solve(case) for case in [tuple(map(int, input().split())) for _ in range(int(input()))]]

def solve(case):
	(money, offer_number, free_number, cost) = case
	print(money // (offer_number * cost) * (offer_number + free_number) + money % (offer_number * cost) // cost)
main()


t = int(input())
while t > 0:
	(s, a, b, c) = map(int, input().split())
	free = int(s / (a * c)) * b
	bought = int(s / c)
	print(bought + free)
	t -= 1


a = int(input())
p = []
for i in range(a):
	(b, c, d, e) = map(int, input().split())
	w = b // e
	r = w // c
	p = r * d
	print(p + c * r + (b - r * c * e) // e)


def choco(s, a, b, c):
	n = s // c
	return n // a * b + n
for _ in range(int(input())):
	print(choco(*map(int, input().split())))


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	p = s // c
	j = p // a * b
	print(p + j)


for _ in range(int(input())):
	(s, a, b, c) = list(map(int, input().split()))
	x = s // c
	x += b * (x // a)
	print(x)


T = int(input())
for _ in range(T):
	(s, a, b, c) = list(map(int, input().split()))
	amount = s // c
	free = amount // a * b
	print(free + amount)


T = int(input())
for i in range(0, T):
	(s, a, b, c) = list(map(int, input().split()))
	out = 0
	val = s // (a * c)
	out += b * val
	out += a * val
	val = s % (a * c)
	out += val // c
	print(out)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	e = s // c
	f = e // a
	g = f * a
	h = f * b
	i = s - a * c * f
	j = i // c
	print(g + h + j)


x = int(input())
for i in range(x):
	tot = 0
	(s, a, b, c) = map(int, input().split())
	p = s // c
	if p < a:
		print(p)
	else:
		p += p // a * b
		print(p)


for a in range(int(input())):
	s = input().split()
	i = int(s[0])
	j = int(s[1])
	k = int(s[2])
	l = int(s[3])
	print(i // l + i // l // j * k)


t = int(input())
for y in range(0, t):
	(s, a, b, c) = map(int, input().split())
	print(s // c + s // c // a * b)


a = int(input())
a1 = 0
b1 = 0
for i in range(a):
	(a, b, c, d) = map(int, input().split())
	a1 += a // d
	b1 = a1
	b1 //= b
	b1 *= c
	a1 += b1
	print(a1)
	a1 = 0
	b1 = 0


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	ans = 0
	ans = s // (a * c) * (b + a)
	ans += s % (a * c) // c
	print(ans)


t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().strip().split(' ')))
	ans1 = s // c
	ans2 = s // c // a
	ans3 = ans2 * b
	print(ans1 + ans3)


for i in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	sum = int(s / c)
	print(sum + int(sum / a) * b)


for t in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	cnt = 0
	d = s // c
	cnt = d + d // a * b
	print(cnt)


t = int(input())
for i in range(t):
	ss = input().split()
	s = int(ss[0])
	a = int(ss[1])
	b = int(ss[2])
	c = int(ss[3])
	d = s // c + s // c // a * b
	print(d)
	print('\n')


t = int(input())
for _ in [1] * t:
	(s, a, b, c) = list(map(int, input().split()))
	print(s // c + s // c // a * b)


import sys
t = int(input())
while t > 0:
	inp = list(map(int, input().split()))
	s = inp[0]
	a = inp[1]
	b = inp[2]
	c = inp[3]
	ans = s // c
	ans += ans // a * b
	print(ans)
	t = t - 1


def program():
	(s, a, b, c) = map(int, input().split())
	sum = s // c
	free = sum // a * b
	print(sum + free)
t = int(input())
for i in range(t):
	program()


n = int(input())
for _ in range(n):
	(s, a, b, c) = map(int, input().split())
	res = s // c
	res += res // a * b
	print(res)


T = int(input())
while T > 0:
	(s, a, b, c) = map(int, input().strip().split())
	s //= c
	compra = s // a * a
	compra += s // a * b
	compra += s % a
	print(compra)
	T -= 1


n = int(input())
for x in range(n):
	(s, a, b, c) = map(int, input().strip().split()[:4])
	k = s // c
	if k < a:
		print(k)
	else:
		p = k // a
		print(k + p * b)


for i in range(int(input())):
	abcd = input().split()
	a = int(abcd[0])
	b = int(abcd[1])
	c = int(abcd[2])
	d = int(abcd[3])
	e = a // d
	f = 0
	if e >= b:
		f = e // b
	total = e + f * c
	print(total)


def main():
	number = int(input())
	main_ls = list()
	for _ in range(1, number + 1):
		ls = list(map(int, input().split()))
		main_ls.append(ls)
	for i in range(0, number):
		s = main_ls[i][0]
		a = main_ls[i][1]
		b = main_ls[i][2]
		c = main_ls[i][3]
		raz = int(s / c)
		pod = int(raz / a) * b
		sum = raz + pod
		print(sum)
main()


t = int(input())
for j in range(t):
	x = [int(y) for y in input().split(' ')]
	c = x[0] // x[3]
	c = c + c // x[1] * x[2]
	print(c)


t = int(input())
while t:
	count = 0
	(s, a, b, c) = map(int, input().split())
	count += int(s / c)
	count += int(count / a) * b
	print(count)
	t -= 1


testCases = int(input())
for test in range(testCases):
	sabc = [int(x) for x in input().split()]
	candiesCanBuy = sabc[0] // sabc[3]
	print(candiesCanBuy + candiesCanBuy // sabc[1] * sabc[2])


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	k = s // c
	su = k
	u = k // a
	su += u * b
	print(su)


def solve():
	(s, a, b, c) = map(int, input().split())
	x = s // (a * c)
	ans = x * (a + b)
	s -= x * a * c
	ans += s // c
	return ans

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


z = input
for i in range(int(z())):
	(a, b, c, e) = map(int, z().split())
	s = a // e
	t = s // b
	p = s + t * c
	print(p)


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	(s, a, b, c) = gi()
	print(s // c + s // c // a * b)


for _ in [0] * int(input()):
	(s, a, b, c) = map(int, input().split())
	d = s // c
	print(d + d // a * b)


n = int(input())
for i in range(n):
	(a, b, c, d) = map(int, input().split())
	buy = a // d
	get = buy // b * c
	print(buy + get)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	p = s // c
	l = p // a
	d = s - a * c * l
	e = d // c
	w = p // a
	x = w * b
	y = w * a
	print(e + y + x)


n = int(input())
for i in range(n):
	a = input().split()
	x = int(a[0]) // int(a[3])
	print(x + x // int(a[1]) * int(a[2]))


for test in range(int(input())):
	[s, a, b, c] = [int(x) for x in input().split()]
	num_bars = s // c
	num_special_offers = num_bars // a
	num_bars += num_special_offers * b
	print(num_bars)


t = int(input())
a1 = 0
b1 = 0
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	a1 = s // c
	b1 = a1
	b1 //= a
	b1 *= b
	a1 += b1
	print(a1)
	a1 = 0
	b1 = 0


T = int(input())
for i in range(T):
	(s, a, b, c) = map(int, input().split(' '))
	cb = s // c
	if cb >= a:
		cb += cb // a * b
	print(cb)


numcases = int(input())
for i in range(numcases):
	(s, a, b, c) = map(int, input().split())
	choc = s // c
	print(choc // a * b + choc)


t = int(input())
for i in range(t):
	(s, a, b, c) = input().split(' ')
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	x = int(s / c)
	y = int(x / a)
	result = x + y * b
	print(int(result))


t = int(input())
for i in range(t):
	ns = [int(x) for x in input().split()]
	num = ns[0] // ns[-1]
	a = ns[1]
	b = ns[2]
	bo = num // a * b
	print(num + bo)


t = int(input())
for _ in range(t):
	(s, a, b, c) = (int(x) for x in input().split())
	ans = 0
	block_cost = a * c
	blocks = s // block_cost
	ans += blocks * (a + b)
	s -= blocks * block_cost
	ans += s // c
	print(ans)


t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().strip().split()))
	d = s // c
	print(d + d // a * b)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(t) for t in input().split()]
	if s // c < a:
		print(s // c)
	elif s // c >= a:
		print(s // c + b * (s // (c * a)))


t = int(input())
for i in range(t):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	cnt = s // c
	x = cnt // a
	add = x * b
	print(add + cnt)


from sys import stdin
cases = int(input())
for case in range(cases):
	(s, a, b, c) = map(int, stdin.readline().strip().split())
	x = s // c
	y = x // a
	x += y * b
	print(x)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(o) for o in input().split()]
	ans = s // c + s // (a * c) * b
	print(ans)


t = int(input())
sabci = [list(map(int, input().split())) for i in range(t)]
for i in range(t):
	num = sabci[i][0] // (sabci[i][1] * sabci[i][3])
	num2 = (sabci[i][0] - num * sabci[i][1] * sabci[i][3]) // sabci[i][3]
	print(num * (sabci[i][1] + sabci[i][2]) + num2)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	n_pooli = s // c
	portion_free = n_pooli // a
	n_free = portion_free * b
	print(n_pooli + n_free)


def mainA():
	T = int(input())
	for i in range(T):
		(s, a, b, c) = map(int, input().split())
		ans = s // c
		ans += ans // a * b
		print(ans)
mainA()


def main():
	t = int(input())
	for i in range(t):
		(s, a, b, c) = map(lambda x: int(x), input().split(' '))
		pay = s // c
		free = pay // a * b
		ans = pay + free
		print(ans)
main()


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	d = s // c
	f = d // a
	g = f * b
	print(d + g)


t = int(input())
for i in range(0, t):
	a = input().split()
	print(int(a[0]) // int(a[3]) // int(a[1]) * (int(a[1]) + int(a[2])) + int(a[0]) // int(a[3]) % int(a[1]))


e = int(input())
for i in range(e):
	f = input().split()
	s = int(f[0])
	a = int(f[1])
	b = int(f[2])
	c = int(f[3])
	print(s // c + s // (c * a) * b)


n = int(input())
while n != 0:
	l = list(map(int, input().split()))
	Coin = l[0]
	GetOffer = l[1]
	GiveOffer = l[2]
	Cost = l[3]
	ans = Coin // Cost // GetOffer * GiveOffer + Coin // Cost
	print(ans)
	n -= 1


n = int(input())
for x in range(n):
	(s, a, b, c) = list(map(int, input().split()))
	tam = a * c
	lam = s // tam
	print(lam * b + int(s // c))


for _ in range(int(input())):
	(s, a, b, c) = list(map(int, input().split()))
	tot = s // c
	mod = tot % a
	pur = tot - mod
	totPur = pur + pur // a * b
	price = pur * c
	diff = s - price
	newPur = diff // c
	totPur += newPur
	print(totPur)


i = int(input())
for i in range(i):
	(s, a, b, c) = map(int, input().split())
	l = s // c
	e = a * c
	f = s // e * b
	print(l + f)


t = int(input())
while t > 0:
	t = t - 1
	y = input()
	arr = [int(y) for y in y.split()]
	print(arr[0] // arr[3] + arr[0] // arr[3] // arr[1] * arr[2])


import os
import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(s, a, b, c) = [int(s) for s in sys.stdin.readline().split()]
	s = s // c
	res = (a + b) * (s // a) + s % a
	sys.stdout.write('{0}\n'.format(res))


t = int(input())
for i in range(t):
	b = list(map(int, input().split()))
	k = int(b[0] // b[3])
	p = k // b[1]
	print(k + p * b[2])


t = int(input())
for case in range(0, t):
	(s, a, b, c) = map(int, input().split())
	can_buy = s // c
	special_get = can_buy // a
	ans = special_get * b + can_buy
	print(ans)


tc = int(input())
for i in range(0, tc):
	(s, a, b, c) = list(map(int, input().strip().split(' ')))
	value = s // c + s // c // a * b
	print(value)


n = int(input())
for i in range(n):
	(m, p, pc, c) = [int(v) for v in input().split(' ')]
	v = m // c
	print(v // p * pc + v)


T = int(input())
for t in range(T):
	(s, a, b, c) = [int(i) for i in input().split()]
	withoutdeal = s // c
	deal = withoutdeal // a * b
	print(withoutdeal + deal)


t = int(input())

def solve():
	(s, a, b, c) = list(map(int, input().split()))
	print(int(int(s / (a * c)) * b + int(s / c)))
while t > 0:
	solve()
	t -= 1


q = int(input())
for i in range(q):
	(w, e, r, t) = map(int, input().split())
	y = w // t
	u = y // e * r
	print(y + u)


t = int(input())
for est in range(t):
	(s, a, b, c) = map(int, input().split())
	xx = s // c
	bb = xx // a
	cc = bb * b
	print(xx + cc)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	t = s // c
	count = 0
	if t >= a:
		count += t // a * b
		count += t
		print(int(count))
	else:
		print(int(t))


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(t,) = I()
while t:
	(r, n, b, c) = I()
	print(r // c + r // c // n * b)
	t -= 1


n = int(input())
for _ in range(n):
	(s, a, b, c) = tuple(map(int, input().split()))
	x = s // (a * c)
	result = x * (a + b) + (s - x * a * c) // c
	print(result)


T = int(input())
for i in range(T):
	(s, a, b, c) = list(map(int, input().split()))
	ans = 0
	num1 = s // (a * c)
	num2 = s - num1 * a * c
	ans += num1 * (a + b)
	ans += num2 // c
	print(ans)


t = int(input())
while t:
	(s, a, b, c) = map(int, input().split())
	ru = a * c
	p = s // ru * a
	res = s // ru * b
	res += p
	res += s % ru // c
	print(int(res))
	t -= 1


t = int(input())
while t:
	t -= 1
	(s, a, b, c) = map(int, input().split())
	ans = 0
	canAfford = s // c
	if a <= canAfford:
		ans += canAfford // a * (a + b)
		canAfford = canAfford % a
	ans += canAfford
	print(ans)


for _ in range(int(input())):
	(s, a, b, c) = list(map(int, input().split()))
	cnt = s // c
	ans = cnt
	ans += cnt // a * b
	print(ans)


t = int(input())
for j in range(0, t):
	(s, a, b, c) = list(map(int, input().split()))
	no_of_choclate = s // c
	if no_of_choclate < a:
		print(no_of_choclate)
	else:
		a_limit_bar = no_of_choclate // a
		rem = no_of_choclate % a
		extra_choclate = a_limit_bar * b
		final_ans = a_limit_bar * a + extra_choclate + rem
		print(final_ans)


t = int(input())
for each_t in range(t):
	(s, a, b, c) = input().split()
	(s, a, b, c) = (int(s), int(a), int(b), int(c))
	number_of_chocolates = s // c
	result = number_of_chocolates // a * b + number_of_chocolates
	print(result)


t = int(input())
lst = []
for i in range(t):
	data = (int(i) for i in input().split())
	lst.append(data)
for item in lst:
	(s, a, b, c) = item
	sum = s // c + s // (a * c) * b
	print(sum)


t = int(input())
for i in range(t):
	x = list(map(int, input().split()))
	if x[3] > x[0]:
		print(0)
	else:
		print(x[0] // x[3] + x[0] // x[3] // x[1] * x[2])


t = int(input())
s = []
c = []
a = []
b = []
for i in range(t):
	(si, ai, bi, ci) = map(int, input().split(' '))
	s.append(si)
	c.append(ci)
	a.append(ai)
	b.append(bi)
for i in range(t):
	nb = s[i] // c[i]
	print(nb // a[i] * b[i] + nb)


import sys
t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, sys.stdin.readline().split())
	count = s // c
	ans = count + count // a * b
	print(ans)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(j) for j in input().split()]
	res = 0
	pack = a * c
	if s >= pack:
		count = s // pack
		res += (a + b) * count
		res += (s - count * pack) // c
	else:
		res = s // c
	print(res)


t = int(input())
for _ in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	n = s // c
	print(n + b * (n // a))


i = int(input())
for i in range(0, i):
	ans = 0
	(money, need, free, price) = input().split()
	money = int(money)
	need = int(need)
	free = int(free)
	price = int(price)
	sale_time = money // (price * need)
	ans = sale_time * need + sale_time * free
	money = money - sale_time * price * need
	ans = money // price + ans
	print(ans)


n = int(input())
while n > 0:
	n -= 1
	(s, a, b, c) = map(int, input().split())
	ans = s // (a * c) * (a + b)
	ans += s % (a * c) // c
	print(ans)


n = int(input())
for i in range(n):
	k = 0
	m = 0
	(s, a, b, c) = map(int, input().split())
	k = s // c
	m = k // a * b
	print(k + m)


tc = int(input())
for i in range(0, tc):
	(s, a, b, c) = list(map(int, input().split(' ')))
	get = int(s / c)
	extra = int(get / a) * b
	print(get + extra)


testcount = int(input())
for i in range(testcount):
	arr = []
	for j in input().split():
		arr.append(int(j))
	count = arr[0] // arr[3] + arr[0] // arr[3] // arr[1] * arr[2]
	print(count)


for i in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	y = s // c
	k = y // a * b
	f = k + y
	print(f)
	f = 0


t = int(input())
for _ in range(t):
	(s, a, b, c) = map(int, input().split())
	n = s // c
	m = n // a
	r = n + m * b
	print(r)


def readint():
	return int(input())

def readline():
	return [int(c) for c in input().split()]

def main():
	T = readint()
	for t in range(T):
		(s, a, b, c) = readline()
		num_bought = s // c
		res = num_bought + num_bought // a * b
		print(res)
main()


n = int(input())
m = 0
while m < n:
	(a, b, c, d) = list(map(int, input().split()))
	print(int(a / d) + int(int(a / d) / b) * c)
	m += 1


for i in range(int(input())):
	x = 0
	e = 0
	(s, a, b, c) = map(int, input().split())
	x = s // c
	e = x // a * b
	print(x + e)


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(t,) = map(int, input().split(' '))
	for _ in range(t):
		(s, a, b, c) = map(int, input().split(' '))
		n = s // c
		ans = n // a * (a + b) + n % a
		print(ans)
main()


t = int(input())
for l in range(t):
	(s, a, b, c) = map(int, input().split())
	d = s // c + b * (s // c // a)
	print(d)


for __ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	print(s // c // a * b + s // c)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	buy = int(s / c)
	bonus = int(buy // a * b)
	print(buy + bonus)


for t in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	ch = s // c
	f = ch // a
	off = f * b
	print(ch + off)


a = int(input())
h = 0
for i in range(a):
	b = [int(i) for i in input().split()]
	onepack = b[1] * b[3]
	packquantity = b[0] // (b[1] * b[3])
	sediment = b[0] - onepack * packquantity
	h = (b[1] + b[2]) * packquantity
	h += sediment // b[3]
	print(h)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	x = s // c
	if x < a:
		choc = x
	else:
		choc = x // a * b + x
	print(choc)


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, a, b, c) = map(int, input().split())
		s = n // c
		k = s // a
		s += k * b
		print(s)
main()


n = int(input())
for i in range(n):
	(a, b, c, d) = map(int, input().split())
	z = a // d
	x = z // b
	v = x * c
	print(z + v)


t = int(input())
for i in range(0, t, 1):
	(s, a, b, c) = map(int, input().split())
	d = s // c
	e = d // a
	f = e * b
	ans = d + f
	print(ans)


for _ in range(int(input())):
	(s, a, b, c) = map(str, input().split())
	s = int(s.replace(',', ''))
	a = int(a.replace(',', ''))
	b = int(b.replace(',', ''))
	c = int(c.replace(',', ''))
	p = s // (a * c)
	q = p * (a + b)
	r = s % (a * c)
	if r >= c:
		q += r // c
	print(q)


t = int(input())
b = list()
for i in range(t):
	a = list(map(int, input().split()))
	k = a[0] // a[3]
	d = k // a[1] * a[2]
	b.append(k + d)
for i in range(t):
	print(b[i])


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	nb = s // c
	if nb >= a:
		nb += nb // a * b
	print(nb)


T = int(input())
for i in range(T):
	(s, a, b, c) = map(int, input().split())
	co = a * c
	gp = s // co
	b = gp * (a + b) + (s - gp * co) // c
	print(b)


test_cases = int(input())
for i in range(test_cases):
	(s, a, b, c) = map(int, input().split(' '))
	chocos_bought = s // c
	free = chocos_bought // a * b
	print(chocos_bought + free)


numTests = int(input())
for i in range(numTests):
	(s, a, b, c) = map(int, input().split())
	purchased = s // c
	numOffer = purchased // a
	free = numOffer * b
	total = purchased + free
	print(total)


T = int(input())
while T > 0:
	(s, a, b, c) = map(int, input().split(' '))
	pur = s // c
	ext = pur // a
	ext = ext * b
	total = ext + pur
	print(total)
	T = T - 1


p = 0
q = 0
for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	if a * c <= s:
		p += s // c
		l = p // a
		q += l * b
		print(p + q)
		(p, q) = (0, 0)
	else:
		p += s // c
		print(p)
		p = 0


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	count = s // c // a
	extra = count * b
	result = s // c + extra
	print(result)


t = int(input())
arr = []
for i in range(t):
	arr.append([int(s) for s in input().split()])
for i in range(t):
	mySum = 0
	s = arr[i][0]
	a = arr[i][1]
	b = arr[i][2]
	c = arr[i][3]
	a1 = a * c
	a2 = s // a1
	mySum += a2 * a + a2 * b
	a3 = s - a2 * a * c
	mySum += a3 // c
	print(mySum)


a = int(input())
input_list = list()
while a:
	input_list.append(input().split())
	a -= 1
for item in input_list:
	count_choco = int(int(item[0]) / int(item[3]))
	count_bonus_choco = int(count_choco / int(item[1])) * int(item[2])
	print(count_choco + count_bonus_choco)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	can_buy = s // c
	prize = can_buy // a
	print(can_buy + prize * b)


alpha_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}

def i_i():
	return int(input())

def i_s():
	return input()

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

def m_s():
	return list(map(str, input().split()))
t = i_i()
for i in range(t):
	k = m_i()
	val = k[0] // k[3]
	val1 = val // k[1]
	val2 = k[2] * val1
	print(val + val2)


t = int(input())
for i in range(1, t + 1):
	(s, a, b, c) = [int(s) for s in input().split(' ')]
	bought = s // c
	special = bought // a * b
	print(special + bought)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_test = read_int()
for _ in range(nb_test):
	(have_roubles, if_bought, get_free, price) = read_ints()
	bought = have_roubles // price
	bought += bought // if_bought * get_free
	print(bought)


T = int(input())
a = {}
for i in range(T):
	(s, a, b, c) = map(int, input().split())
	m = int(int(s / c) / a)
	n = int(int(s / c) % a)
	print(m * (a + b) + n)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	if a > s // c:
		print(s // c)
	else:
		k = s // c
		p = k // a
		q = p * b
		if s - k * c > c:
			print(s // c + q + 1)
		else:
			print(s // c + q)


t = int(input())
for i in range(t):
	l = list(map(int, input().split(' ')))
	s = l[0]
	a = l[1]
	b = l[2]
	c = l[3]
	k = s // c
	m = k // a
	num = k + m * b
	print(num)


for _ in range(int(input())):
	(total, c, p, cost) = [int(i) for i in input().split()]
	total = total // cost
	print(total // c * (c + p) + total % c)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for i in range(get_int()):
	(s, a, b, c) = get_list()
	ans = s // (a * c) * (a + b)
	rem = s % (a * c)
	ans += rem // c
	print(ans)


q = int(input())
for _ in range(q):
	(s, a, b, c) = map(int, input().split())
	x = s // c
	z = x // a
	print(x + b * z)


t = int(input())
res = []
for _ in range(t):
	(s, a, b, c) = map(int, input().split())
	no_of_choc_mon = s // c
	offer = no_of_choc_mon // a
	res.append(no_of_choc_mon + offer * b)
for x in res:
	print(x)


tc = int(input())
for i in range(tc):
	read = input().split(' ')
	s = int(read[0])
	a = int(read[1])
	b = int(read[2])
	c = int(read[3])
	ans = s // c + s // c // a * b
	print(ans)


t = int(input())
count = 0
ans = []
while count < t:
	(s, a, b, c) = input().split()
	tot = 0
	roub_need = int(a) * int(c)
	times = int(s) // roub_need
	s = int(s) - times * roub_need
	left = int(s) // int(c)
	tot += times * int(b)
	tot += times * int(a)
	tot += left
	ans.append(tot)
	count += 1
for y in ans:
	print(y)


t = int(input())
for o in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	tot = s // c
	ex = tot // a * b
	print(tot + ex)


def chocolates(aa):
	(s, a, b, c) = (aa[0], aa[1], aa[2], aa[3])
	lim = s // c
	return lim + lim // a * b
tc = int(input())
for i in range(tc):
	aa = list(map(int, input().split()))
	print(chocolates(aa))


import math
test = int(input())
for i in range(test):
	(s, a, b, c) = map(int, input().split())
	t = s // c
	print(t + t // a * b)


t = int(input().strip())
for test in range(t):
	(s, a, b, c) = [int(i) for i in input().strip().split(' ')]
	bars = int(s / c)
	bars += int(bars / a) * b
	print(bars)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	p = s // c
	if p < a:
		print(p)
	else:
		print(int(s / c) + p // a * b)


n = int(input())
list1 = []
for i in range(n):
	list1 = list(map(int, input().strip().split(' ')))
	money = list1[0] // list1[3]
	buy = money // list1[1]
	extra = buy * list1[2]
	sum = money + extra
	print(sum)


testcase = int(input())
while testcase:
	(money, buy, addon, cost) = map(int, input().strip().split())
	count = money // cost
	free = count // buy * addon
	count += free
	print(count)
	testcase -= 1


from sys import stdin

def main():
	T = int(input())
	for _ in range(T):
		choco = 0
		(S, A, B, C) = map(int, input().split())
		choco += S // C
		n = choco // A * B
		print(choco + n)
input = lambda : stdin.readline()
main()


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	bought = int(s / c)
	free = int(bought / a) * b
	total = bought + free
	print(total)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
from types import CodeType, new_class
for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	ans = s // c
	ans += ans // a * b
	print(ans)


n = int(input())
for i in range(n):
	sum = 0
	(s, a, b, c) = map(int, input().split())
	z = s // c
	t = z // a
	q = z
	if t > 0:
		sum += (a + b) * t
		q = z - a * t
	if q > 0:
		sum += q
	print(sum)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	k = s // c
	w = k + k // a * b
	print(w)


import string
count = int(input())
for i in range(count):
	line = input()
	line2 = line.split()
	s = int(line2[0])
	a = int(line2[1])
	b = int(line2[2])
	c = int(line2[3])
	x = s // c
	y = x // a
	print(y * (a + b) + x % a)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
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)]

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())):
	(s, a, b, c) = ilele()
	buy = s // c
	print(buy + buy // a * b)


n = int(input())
while n != 0:
	(s, a, b, c) = map(int, input().split())
	max = int(s / c)
	extra = int(max / a) * b
	print(int(max + extra))
	n = n - 1


a = int(input())
kit = []
for i in range(a):
	kit.append(list(map(int, input().split())))
for elem in kit:
	print(elem[0] // elem[3] + elem[0] // elem[3] // elem[1] * elem[2])


import math

def Chocolate(s, a, b, c):
	x = math.floor(s / c)
	v = math.floor(x / a) * b
	if x < a:
		num = x
	else:
		num = x + v
	print(num)
for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	Chocolate(s, a, b, c)


x = int(input())
i = 0
while i < x:
	y = input().split(' ')
	s = int(y[0])
	a = int(y[1])
	b = int(y[2])
	c = int(y[3])
	print(int(s / c) + int(int(int(s / c) / a)) * b)
	i = i + 1


def main():
	n = int(input())
	for _ in range(n):
		(s, a, b, c) = list(map(int, input().split()))
		d = s // c
		free = d // a * b
		print(d + free)
main()


t = int(input())
while t > 0:
	(s, a, b, c) = input().split(' ')
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	if s // c > 0:
		ans = s // c + s // (c * a) * b
	else:
		ans = 0
	print(ans)
	t -= 1


for i in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	p = s // (a * c)
	q = s - p * a * c
	print(p * a + p * b + q // c)


n = int(input())
(total, ans) = (0, 0)
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	b = s // c // a * b
	total = s // c
	ans = total + b
	print(ans)


tests = int(input())
for i in range(tests):
	(s, a, b, c) = map(int, input().split())
	k = s // c
	print(k + b * (k // a))


from math import floor
num = int(input())
lis = []
res = []
for i in range(num):
	temp = input().split()
	lis.append(temp)
for i in range(num):
	for q in range(4):
		lis[i][q] = int(lis[i][q])
for i in range(num):
	p = int(lis[i][0] / lis[i][3])
	tempres = int(p / lis[i][1]) * lis[i][2] + p
	print(int(tempres))


from math import *
t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	x = s // c
	print(x // a * b + x)


a = int(input())
for i in range(a):
	(b, c, d, e) = [*map(int, input().split())]
	f = b // e
	g = f // c * d
	print(f + g)


test = int(input())
for z in range(test):
	(duit, syarat, bonus, harga) = map(int, input().split())
	jumlah = duit // harga
	total = jumlah + jumlah // syarat * bonus
	print(total)


def sol():
	(s, a, b, c) = [int(x) for x in input().split(' ')]
	number_bought = s // c
	number_gained = number_bought // a * b
	return number_bought + number_gained
for t in range(int(input())):
	ans = sol()
	print(ans)


t = int(input())
counter = 0
bars = 0
while counter < t:
	try:
		(s, a, b, c) = list(map(int, input().split(' ')))
		bars = s // c
		if bars >= a:
			bars += bars // a * b
		print(bars)
		bars = 0
	except EOFError:
		break


t = int(input())
for i in range(t):
	(s, a, b, c) = input().split()
	num = int(int(s) / int(c))
	cnt = int(num / int(a)) * (int(b) + int(a))
	res = num % int(a)
	print(cnt + res)


t = int(input())
while t:
	t -= 1
	(s, a, b, c) = [int(i) for i in input().split()]
	choc = s // c
	if a <= choc:
		free = choc // a * b
	else:
		free = 0
	print(choc + free)


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	ans = int(int(a / d) + int(int(a / d) / int(b)) * int(c))
	print(str(int(ans)))


t = int(input())
while t != 0:
	(s, a, b, c) = map(int, input().split())
	no = s // c
	p = no // a
	net = no + p * b
	print(net)
	t -= 1


n = int(input())
otvet = ''
for x in range(n):
	(s, a, b, c) = map(int, input().split())
	N = 0
	N = s // c
	N += N // a * b
	otvet += str(N) + '\n'
print(otvet)


n = int(input())
for i in range(n):
	(s, a, b, c) = list(map(int, input().split()))
	buy = int(s / c)
	offer = int(buy / a)
	free = offer * b
	total = buy + free
	print(total)


n = int(input())
for i in range(n):
	(s, a, b, c) = list(map(int, input().split()))
	if a > s:
		print(s // c)
	else:
		n = 0
		p = a * c
		n += s // p * b + s // p * a
		s %= p
		n += s // c
		print(n)


n = int(input())
for i in range(n):
	(ai, bi, ci, di) = map(int, input().split())
	k = int(ai / di)
	x = int(k / bi)
	y = int(k % bi)
	z = ci * x
	print(bi * x + y + z)


t = int(input())
lst = list()
for i in range(t):
	lst.append(input())
for i in range(t):
	(s, a, b, c) = lst[i].split()
	x = int(int(s) / int(c))
	x = x + int(x / int(a)) * int(b)
	print(x)


t = int(input())
while t:
	(s, a, b, c) = map(int, input().split())
	actual = s // c
	extra = actual // a * b
	actual += extra
	print(actual)
	t -= 1


x = int(input())
for c in range(x):
	(s, a, b, c) = map(int, input().split())
	final = s // c
	free = final // a
	free = free * b
	final += free
	print(final)


num = int(input())
data = [list(map(int, input().split(' '))) for i in range(num)]
res = []
for (s, a, b, c) in data:
	res.append(s // c + s // c // a * b)
for i in res:
	print(i)


n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
for t in l:
	count = t[0] // t[3] // t[1]
	print(count * t[1] + count * t[2] + t[0] // t[3] % t[1])


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	count = 0
	present = 0
	count = s // c
	present = count // a * b
	print(count + present)


n = int(input())
while n > 0:
	list = input().split()
	(s, a, b, c) = (int(list[0]), int(list[1]), int(list[2]), int(list[3]))
	num_1 = s // c
	num_2 = num_1 // a * b
	print(num_1 + num_2)
	n -= 1


t = int(input())
tests = []
i = 1
while i <= t:
	test = [int(y) for y in input().split(' ')]
	tests += [test]
	i += 1
for x in tests:
	x1 = x[0] // x[3]
	x2 = x1 // x[1] * x[2]
	print(x1 + x2)


T = int(input())
while T:
	(s, a, b, c) = map(int, input().split())
	print(int(s / c) + int(int(s / c) / a) * b)
	T -= 1


t = [int(val) for val in input().split()][0]
for i in range(t):
	(s, a, b, c) = [int(val) for val in input().split()]
	amount = s // c
	print(amount + amount // a * b)


t = int(input())
for i in range(t):
	(n, a, b, c) = map(int, input().strip().split())
	buy = n // c
	remain = n - buy
	s = buy
	s += buy // a * b
	print(s)


t = int(input())
for i in range(t):
	tbars = 0
	(s, a, b, c) = [int(x) for x in input().split()]
	tbars = s // c
	tbars = tbars + tbars // a * b
	print(tbars)


n = int(input())
for _ in range(n):
	(s, a, b, c) = map(int, input().split())
	count = s // c
	if count // a >= 1:
		count += count // a * b
	print(count)


t_cases = int(input())
for n in range(t_cases):
	(s, a, b, c) = list(map(int, input().split()))
	buy = s // c
	free = buy // a * b
	print(buy + free)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	a = a // d
	res = a // b * (b + c) + a % b
	print(res)


n = int(input())
l = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
	s = l[i][0]
	a = l[i][1]
	b = l[i][2]
	c = l[i][3]
	if s < c:
		print(0)
	elif s < a * c:
		print(s // c)
	elif s >= a * c:
		print(s // c + s // (a * c) * b)


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split(' '))
	no = s // c
	res = no
	free = s // (a * c)
	res += free * b
	print(res)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	kol = s // c
	bon = kol // a * b
	print(kol + bon)


cases = int(input())
while cases:
	cases -= 1
	(s, a, b, c) = map(int, input().split())
	bought = s // c
	gift = bought // a * b
	print(bought + gift)


from math import *
n = int(input())
b1 = 0
ch = 0
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	ch += s // c
	b1 = ch
	b1 //= a
	b1 *= b
	ch += b1
	print(ch)
	b1 = 0
	ch = 0


t = int(input())
for i in range(t):
	sabc = list(map(int, input().split(' ')))
	s = sabc[0]
	a = sabc[1]
	b = sabc[2]
	c = sabc[3]
	ans = 0
	temp = s % (a * c)
	ans += s // (a * c) * (a + b)
	ans += temp // c
	print(ans)


T = int(input())
for _ in range(T):
	(dollars, deal, free, cost) = map(int, input().strip().split())
	total = int(dollars / cost) + int(dollars / cost) // deal * free
	print(total)


a = int(input())
cnt = 0
for i in range(a):
	(b, c, d, e) = map(int, input().split())
	x = b // (c * e)
	y = b - c * x * e
	z = x * d
	print(z + c * x + y // e)


n = int(input())
for i in range(n):
	arr = list(map(int, input().split(' ')))
	total = arr[0] // arr[3] + arr[0] // arr[3] // arr[1] * arr[2]
	print(total)


t = int(input())
while t > 0:
	arr = list(map(int, input().split()))
	s = int(arr[0])
	a = int(arr[1])
	b = int(arr[2])
	c = int(arr[3])
	x = s // c
	y = x // a * b
	print(x + y)
	t -= 1


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(s, a, b, c) = map(int, input().split())
		ans = s // c + s // c // a * b
		print(ans)
main()


n = int(input())
out = list()
for i in range(n):
	a = list(map(int, input().split()))
	b = a[0] // a[3]
	c = b // a[1]
	free = c * a[2]
	chocolates = a[0] // a[3]
	total = chocolates + free
	print(total)


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

def main():
	t = int(input())
	l = []
	for i in range(t):
		(money, has_buy_per_offer, free_bar, cost) = innt()
		l.append([money, has_buy_per_offer, free_bar, cost])
	for i in l:
		[money, has_buy_per_offer, free_bar, cost] = i
		willBuy = int(money / cost)
		extra = int(willBuy / has_buy_per_offer) * free_bar
		print(willBuy + extra)
main()


t = int(input())
while t > 0:
	(s, a, b, c) = [int(x) for x in input().split(' ')]
	total = s // c
	fre = total // a * b
	print(total + fre)
	t -= 1


n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	loc = s // c
	d = loc + loc // a * b
	print(d)


t = int(input())
res = []
for i in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	bought = s // c
	bonus = bought // a * b
	res.append(bought + bonus)
for i in range(t):
	print(res[i])


def main():
	n = int(input())
	for _ in range(n):
		(s, a, b, c) = [int(v) for v in input().split()]
		val = s // (c * a)
		val2 = b * val
		val3 = s % (c * a) // c
		print(val * a + val2 + val3)
main()


i = int(input())
for i in range(i):
	w = str(input())
	n = list(map(int, w.split()))
	s = n[0]
	a = n[1]
	b = n[2]
	c = n[3]
	h = s // c
	x = h // a
	add = x * b
	print(add + h)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	buy = s // c
	get = buy // a * b
	print(buy + get)


t = int(input())
for i in range(0, t):
	(s, a, b, c) = map(int, input().split())
	without = s // c
	ww = without // a
	bonus = ww * b
	print(without + bonus)


a = int(input())
for i in range(a):
	(n, b, d, p) = [int(i) for i in input().split()]
	a1 = n // p
	a2 = a1 // b * d
	a3 = a1 + a2
	print(a3)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	ini = int(s / c)
	ex = int(ini / a) * b
	print(ini + ex)


n = int(input())
for i in range(n):
	(l, a, b, c) = list(map(int, input().split()))
	m = l // c
	m += b * (m // a)
	print(m)


t = input()
for i in range(int(t)):
	(s, a, b, c) = map(int, input().split())
	ans = 0
	k = s // c
	ans = k + k // a * b
	print(ans)


t = int(input())
c = []
answer = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	if s < a * c:
		answer.append(s // c)
		continue
	elif s >= a * c:
		x = s // (a * c)
		answer.append((s - x * a * c) // c + x * a + x * b)
	else:
		answer.append(s // c)
for i in range(t):
	print(answer[i])


def free(test_case):
	[s, a, b, c] = test_case
	buy_a = s // (a * c)
	get_b = buy_a * b
	buy_c = (s - buy_a * a * c) // c
	return buy_a * a + get_b + buy_c

def main():
	n = int(input())
	results = [free([int(_) for _ in input().split()]) for i in range(n)]
	for r in results:
		print(r)
main()


n = int(input())
for i in range(n):
	(s, a, b, c) = [int(i) for i in input().split()]
	no = s // c
	m = no // a
	print(b * m + no)


t = int(input())
for i in range(t):
	q = [int(x) for x in input().split()]
	s = q[0]
	a = q[1]
	b = q[2]
	c = q[3]
	sh = s // c
	if sh >= a:
		print(sh + sh // a * b)
	else:
		print(sh)


x = int(input())
for _ in range(x):
	a = [int(i) for i in input().split()]
	s = a[0]
	f = a[1]
	h = a[2]
	j = a[3]
	l = 0
	l += s // j + s // j // f * h
	print(l)


try:
	t = int(input())
	for i in range(t):
		(s, a, b, c) = map(int, input().split())
		min_choc = s // c
		free = min_choc // a
		free_choc = free * b
		ans = min_choc + free_choc
		print(ans)
except EOFError:
	pass


t = int(input())
total = 0
for i in range(t):
	(s, a, b, c) = [int(i) for i in input().split()]
	pack = a * c
	pack_amount = s // pack
	gift = pack_amount * (b + a)
	total = s % pack // c + gift
	print(total)


t = int(input())
while t != 0:
	(s, a, b, c) = map(int, input().split())
	number_of = int(s / c)
	offer = int(int(number_of / a) * b)
	totall = int(number_of + offer)
	print(totall)
	t -= 1


n = int(input())
for x in range(0, n, +1):
	(s, a, b, c) = map(int, input().split())
	wyn = 0
	f = 0
	wyn += int(s / c)
	f = int(wyn / a)
	wyn += f * b
	print(wyn)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(s, a, b, c) = get_list()
	buy = s // c
	extra = buy // a * b
	print(buy + extra)


n = int(input())
for x in range(0, n):
	(s, a, b, c) = map(int, input().split())
	if x == n - 1:
		print(s // c + s // c // a * b, end='')
	else:
		print(s // c + s // c // a * b)


n = int(input())
for _r in range(n):
	(s, a, b, c) = map(int, input().split())
	count = s // c
	r = count // a * (a + b) + count % a
	print(r)


def max_num(money, amount_to_get, free_bars, cost):
	n = int(money / cost)
	_max = int(n / amount_to_get) * free_bars + n
	return _max
t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	print(max_num(s, a, b, c))


m = int(input())
for i in range(0, m):
	(a1, b1, c1, d1) = map(int, input().split())
	ans = a1 // d1 + a1 // d1 // b1 * c1
	print(ans)


t = int(input())
ans = [0] * t
for i in range(t):
	(s, a, b, c) = [int(j) for j in input().split()]
	s //= c
	ans[i] = s // a * (a + b) + s % a
for j in ans:
	print(j)


n = int(input())
for i in range(n):
	l = [int(i) for i in input().split()]
	print(l[0] // l[3] // l[1] * l[2] + l[0] // l[3])


n = int(input())
e = []
for i in range(n):
	(a, b, c, d) = map(int, input().split())
	p = a // d
	l = p // b
	e.append(p + l * c)
for i in range(len(e)):
	print(e[i])


import sys

def minp():
	return sys.stdin.readline().strip()
for t in range(int(minp())):
	(s, a, b, c) = map(int, minp().split())
	k = s // c
	print(k // a * (a + b) + k % a)


for _ in ' ' * int(input()):
	(a, b, c, d) = map(int, input().split())
	k = a // d
	print(k + k // b * c)


t = int(input())
while t != 0:
	(s, a, b, c) = map(int, input().split())
	ans1 = s // c
	ans2 = ans1 // a * b
	print(ans1 + ans2)
	t -= 1


t = int(input())
for i in range(t):
	res = 0
	(s, a, b, c) = [int(i) for i in input().split()]
	u = s // c
	res += u
	y = u // a
	z = b * y
	res += z
	print(res)


tests = int(input())
for i in range(tests):
	chunk = 0
	line = input().split()
	s = int(line[0])
	a = int(line[1])
	b = int(line[2])
	c = int(line[3])
	if s < c:
		print(0)
		continue
	else:
		to_buy = s // c
		chunk += to_buy
		if to_buy >= a:
			chunk += to_buy // a * b
		print(chunk)


def ans(arr):
	(s, a, b, c) = (arr[0], arr[1], arr[2], arr[3])
	return s // (c * a) * b + s // c
t = int(input())
for _ in range(t):
	sabc = list(map(int, input().strip().split()))
	print(ans(sabc))


T = int(input())
for t in range(T):
	(s, a, b, c) = list(map(int, input().split(' ')))
	Bar = s // c
	N = Bar // a * b
	print(Bar + N)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(s, a, b, c) = list(map(int, sys.stdin.readline().strip().split()))
	op = int(s / c)
	op = op + int(op / a) * b
	print(op)


t = int(input())
for i in range(t):
	[s, a, b, c] = list(map(int, input().split(' ')))
	r = s // c + s // c // a * b
	print(r)


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	n_bought = s // c
	n_free = n_bought // a * b
	print(n_bought + n_free)


ans = []
t = int(input())
for test in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	total = 0
	total += int(s / c)
	if total >= a:
		total += int(total / a) * b
	ans.append(total)
for i in range(len(ans)):
	print(ans[i])


nbTests = int(input())
for loop in range(nbTests):
	(s, a, b, c) = map(int, input().split())
	print(s // a // c * (a + b) + s % (a * c) // c)


n = int(input())
for i in range(n):
	p = list(map(int, input().split()))
	a = p[0] // p[3]
	b = a // p[1] * p[2]
	print(a + b)


pocSkup = int(input())
for i in range(pocSkup):
	(peniaze, vyhodaPotreba, vyhodaDostanes, cena) = list(map(int, input().split()))
	print(peniaze // cena + peniaze // cena // vyhodaPotreba * vyhodaDostanes)


def main():
	n = int(input())
	for i in range(n):
		(s, a, b, c) = map(int, input().split())
		specialCost = a * c
		specialCount = s // specialCost
		res = specialCount * (a + b) + (s - specialCost * specialCount) // c
		print(res)
main()


import sys

def rint():
	return map(int, sys.stdin.readline().split())
t = int(input())
for i in range(t):
	(s, a, b, c) = rint()
	print(s // c + s // c // a * b)


a = int(input())
for i in range(a):
	b = input()
	b = list(map(int, b.split()))
	coo = int(b[0] / b[3])
	x = coo // b[1] * b[2]
	print(int(x + coo))


t = int(input())
for case in range(t):
	(n, a, b, c) = map(int, input().split())
	print(n // c // a * b + n // c)


a = int(input())
for i in range(a):
	(b, c, d, f) = [int(i) for i in input().split()]
	print(b // f + b // f // c * d)


t = int(input())
while t > 0:
	t -= 1
	(s, a, b, c) = map(int, input().split())
	sa = a * c
	an = s // sa
	s = s - an * sa
	bn = s // c
	print(an * (a + b) + bn)


T = int(input())
for cs in range(T):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	res = s // c + s // c // a * b
	print(res)


n = int(input())
for i in range(0, n):
	(a, b, c, d) = map(int, input().split())
	ans = a // d + a // d // b * c
	print(ans)


from sys import stdin, stdout
import cProfile, math
from collections import Counter
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

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

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def main():
	for _ in range(get_int()):
		(s, a, b, c) = get_tuple()
		k = s // c
		print(k + k // a * b)
cProfile.run('main()') if test else main()


def test_0():
	import math
	from collections import Counter
	n = list(map(int, input().split(' ')))[0]
	for i in range(n):
		(s, a, b, c) = list(map(int, input().split(' ')))
		a_1 = s // c
		a_1 += a_1 // a * b
		print(a_1)
test_0()


a = int(input())
for i in range(a):
	(b, c, d, e) = map(int, input().split())
	f = c * e
	f1 = b // f
	f2 = f1 * (c + d)
	f3 = b - f * f1
	f4 = f3 // e
	print(f2 + f4)


for t in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	n = s // c
	ans = 0
	m = n // a
	ans += m * (a + b)
	n -= m * a
	ans += n
	print(ans)


n = int(input())

def func(a, b, c, d):
	t = a // d
	return t + t // b * c
for i in range(n):
	s = list(map(int, input().split()))
	print(func(s[0], s[1], s[2], s[3]))


numTestCase = int(input())
for i in range(numTestCase):
	(money, spReq, freeBar, oneCost) = map(int, input().split())
	barCnt = 0
	buyBar = money // oneCost // spReq * spReq
	money -= buyBar * oneCost
	barCnt += buyBar + buyBar // spReq * freeBar
	buyBar = money // oneCost
	barCnt += buyBar
	print(str(barCnt) + '\n')


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	total_ = 0
	x = s // c
	temp = x // a
	total_ += x
	total_ += temp * b
	print(total_)


def choc_count(s, a, b, c):
	buy = s // c
	return buy + buy // a * b
for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	print(choc_count(s, a, b, c))


t = int(input())
for _ in range(t):
	(bank, num_buy, num_free, bar_cost) = list(map(int, input().strip().split()))
	bulk_buys = int(bank / (num_buy * bar_cost))
	total = bulk_buys * (num_buy + num_free) + int(bank % (num_buy * bar_cost) / bar_cost)
	print(total)


t = int(input())
while t:
	t -= 1
	(s, a, b, c) = map(int, input().split())
	tot = s // c
	free = tot // a * b
	print(tot + free)


query = int(input())
for q in range(query):
	(s, a, b, c) = map(int, input().split())
	print(s // c + s // c // a * b)


import sys
count_test = int(sys.stdin.readline())
for i in range(count_test):
	(s, a, b, c) = map(int, sys.stdin.readline().split())
	number_chocolates = s // c
	free_chocolates = number_chocolates // a * b
	print(free_chocolates + number_chocolates)


t = int(input())
(s, a, b, c) = (0, 0, 0, 0)
m = 0
mas = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	m = s // c + b * (s // c // a)
	mas.append(m)
for i in mas:
	print(i)


t = int(input())
for i in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	if a * c <= s:
		n = int(s / (a * c))
		ans = n * a + b * n + int((s - n * a * c) / c)
		print(ans)
	else:
		ans = int(s / c)
		print(ans)


__author__ = 'Dilshod'
n = int(input())
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	cnt = s // c
	cnt += cnt // a * b
	print(cnt)


for x in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	e = a // d
	f = e // b
	print(f * (b + c) + (e - f * b))


q = int(input())
for i in range(0, q):
	a = list(map(int, input().split()))
	p = a[0] // a[3]
	l = p // a[1]
	p = p + l * a[2]
	print(p)


a = int(input())
m = []
for i in range(a):
	b = list(map(int, input().split()))
	p = int(b[0] / b[3])
	q = int(p / b[1]) * b[2]
	m.append(p + q)
for i in m:
	print(i)


t = int(input())
for x in range(t):
	(s, a, b, c) = map(int, input().strip().split())
	k = s // c
	print(k + k // a * b)


t = int(input(''))
testlist = list()
for i in range(t):
	dizi = list(input('').split())
	testlist.append(dizi)
tam = 0
alinan = 0
for i in range(t):
	tam = 0
	alinan = 0
	if int(testlist[i][0]) >= int(testlist[i][3]):
		alinan = int(int(testlist[i][0]) / int(testlist[i][3]))
		tam = int(alinan / int(testlist[i][1])) * int(testlist[i][2])
	print(tam + alinan)


for tc in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	buy = s // c
	offer = buy // a
	ans = buy + offer * b
	print(ans)


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	(s, a, b, c) = map(int, stdin.readline().split())
	print(s // c + s // c // a * b)


R = lambda : map(int, input().split())
n = int(input())
while n > 0:
	n -= 1
	(s, a, b, c) = R()
	ch = s // c
	print(ch // a * b + ch)


def I():
	return map(int, input().split())
for _ in range(int(input())):
	(s, a, b, c) = I()
	ans = 0
	if a * c <= s:
		ans = s // (a * c) * (a + b)
		s = s % (a * c)
	print(ans + s // c)


n = int(input())
for i in range(n):
	(a, b, c, d) = map(int, input().split())
	m = a // d
	m = m + m // b * c
	print(m)


for m in range(int(input())):
	sabc = list(map(int, input().split()))
	shocolates = sabc[0] // sabc[3]
	bonus = shocolates // sabc[1] * sabc[2]
	print(shocolates + bonus)


t = int(input())
while t > 0:
	t -= 1
	(s, a, b, c) = input().split()
	kp = int(s) // int(c)
	fp = kp // int(a) * int(b)
	print(fp + kp)


t = int(input())
r = []
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	numc = s // c
	temp = int(numc // a * (a + b) + numc % a)
	r.append(str(temp))
print('\n'.join(r))


n = int(input())
i = 0
while i < n:
	(s, a, b, c) = map(int, input().split())
	x = s // c
	x += x // a * b
	print(x)
	i += 1


n = int(input())
for i in range(n):
	z = list(map(int, input().split()))
	temp = 0
	x = z[0] // z[3]
	temp += x
	temp += x // z[1] * z[2]
	print(temp)


k = int(input())
aa = []
for i in range(k):
	(s, a, b, c) = input().split()
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	n = s // c
	m = n // a * b
	aa.append(m + n)
for i in aa:
	print(i)


t = int(input())
while t != 0:
	(s, a, b, c) = map(int, input().split())
	f = s // c
	e = f // a
	r = e * b + f
	t = t - 1
	print(r)


t = int(input())
for z in range(t):
	(s, a, b, c) = [int(x) for x in input().split()]
	k = s // c
	ans = k // a * b
	print(ans + k)


n = int(input())
for _ in range(n):
	(a, b, c, d) = map(int, input().split())
	print(a // d + a // d // b * c)


count = int(input())
for i in range(0, count):
	(s, a, b, c) = map(str, input().split())
	s = int(s)
	a = int(a)
	b = int(b)
	c = int(c)
	bars = s // c
	free = bars // a
	freebars = free * b
	totalbars = bars + freebars
	print(totalbars)


t = int(input())
sabc = [list(map(int, input().split())) for i in range(t)]
for i in range(t):
	ANS = 0
	ANS += sabc[i][0] // sabc[i][3]
	ANS += ANS // sabc[i][1] * sabc[i][2]
	print(ANS)


t = int(input())
for _ in range(t):
	s1 = input().split(' ')
	s = int(s1[0])
	a = int(s1[1])
	b = int(s1[2])
	c = int(s1[3])
	d = s // (a * c)
	e = d * b
	ans = e + s // c
	r = s % (a * c)
	f = r // c
	print(ans)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(s, a, b, c) = map(int, sys.stdin.readline().split(' '))
	ans = s // c
	ans += ans // a * b
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


t = int(input())
l = [0] * t
for i in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	amount = s // c
	l[i] += amount + amount // a * b
for i in range(t):
	print(l[i])


t = int(input())
for i in range(t):
	(s, a, b, c) = list(map(int, input().split()))
	z = 0
	x = s // (a * c)
	s = s - x * (a * c)
	z = z + x * a + x * b + s // c
	print(z)


test = list(map(int, input().split(sep=' ')))
for i in range(test[0]):
	values = list(map(int, input().split(sep=' ')))
	s = values[0]
	a = values[1]
	b = values[2]
	price = values[3]
	choco = s // price + s // price // a * b
	print(choco)


def answer():
	n = int(input())
	while n:
		z = [int(x) for x in input().split()]
		(s, a, b, c) = (z[0], z[1], z[2], z[3])
		normal = int(s / c)
		free = b * int(s / a / c)
		ans = free + normal
		print(ans)
		n -= 1
answer()


x = int(input())
for i in range(x):
	(s, a, b, c) = map(int, input().split())
	y = s // c
	z = y // a * b
	print(y + z)


t = int(input())
for i in range(t):
	(s, a, b, c) = map(int, input().split())
	count = s // c
	count_c = count // a
	count += count_c * b
	print(count)


t = int(input())
sabc = []
output = ''
for i in range(t):
	sabc.append(list(map(int, input().split())))
for i in range(t - 1):
	maximum = 0
	maximum += int(sabc[i][0] / sabc[i][3])
	maximum += int(maximum / sabc[i][1]) * sabc[i][2]
	output += str(maximum) + '\n'
maximum = 0
maximum += int(sabc[-1][0] / sabc[-1][3])
maximum += int(maximum / sabc[-1][1]) * sabc[-1][2]
output += str(maximum)
print(output)


t = int(input())
for x in range(t):
	(s, a, b, c) = [int(y) for y in input().split()]
	choccount = s // c
	add = choccount // a
	add = add * b
	ans = choccount + add
	print(ans)


t = int(input())
for i in range(t):
	ans = 0
	j = 0
	g = 0
	(s, a, b, c) = [int(i) for i in input().split()]
	if s >= c * a:
		ans += a * (s // (c * a))
		j += s // (c * a)
		ans += b * j
		if s % (c * a) >= c:
			ans += s % (c * a) // c
	else:
		ans += s // c
	print(ans)


n = int(input())
total = 0
for i in range(n):
	(s, a, b, c) = map(int, input().split())
	tot = s // c
	t = tot // a
	total += t * a
	total += t * b
	total += tot % a
	print(total)
	total = 0


t = int(input())
while t != 0:
	ans = 0
	(amount, itemtobuy, freeitem, unitprice) = map(int, input().split())
	unitbought = amount // unitprice
	ans = unitbought + amount // (itemtobuy * unitprice) * freeitem
	print(ans)
	t -= 1


for _ in range(int(input())):
	(s, a, b, c) = map(int, input().split())
	nofchoc = s // c
	canbuy = nofchoc // a
	t1 = canbuy * b + nofchoc
	print(t1)


n = int(input())
for i in range(n):
	(s, a, b, c) = tuple(map(int, input().split()))
	t = s // (a * c)
	amount = t * a + t * b
	amount += s % (a * c) // c
	print(amount, end=' ')


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
T = int(input())
for ti in range(T):
	(s, a, b, c) = map(int, input().split())
	bought = s // c
	total = bought + bought // a * b
	print(total)


n = int(input())
for i in range(n):
	bars = 0
	x = input()
	x = x.split()
	bought = int(x[0]) // int(x[3])
	bars += bought
	bars += bought // int(x[1]) * int(x[2])
	print(bars)


n = int(input())
(s, a, b, c) = ([], [], [], [])
for i in range(n):
	(si, ai, bi, ci) = map(int, input().split())
	s.append(si)
	a.append(ai)
	b.append(bi)
	c.append(ci)
for i in range(n):
	nBuy = s[i] // c[i]
	nFree = nBuy // a[i] * b[i]
	print(nFree + nBuy)


t = int(input())
lista = []
for i in range(t):
	entrada = input()
	entrada = [int(x) for x in entrada.split()]
	s = entrada[0]
	a = entrada[1]
	b = entrada[2]
	c = entrada[3]
	chocolatesComprados = int(s / c)
	paquetesChocolates = int(chocolatesComprados / a)
	total = chocolatesComprados + paquetesChocolates * b
	lista.append(total)
for elemento in lista:
	print(elemento)


from sys import stdin, stdout
from math import sin, tan, cos
T = int(stdin.readline())
for t in range(T):
	(s, a, b, c) = map(int, stdin.readline().split())
	cnt = s // c
	cnt += cnt // a * b
	stdout.write(str(cnt) + '\n')


def insertion_sort(l):
	for i in range(len(l)):
		for j in range(i):
			k = i - j
			if l[k] >= l[k - 1]:
				(l[k - 1], l[k]) = (l[k], l[k - 1])
			else:
				break
	return l

def selection_sort(l):
	for i in range(len(l)):
		min_ind = i
		min_val = l[i]
		for j in range(i, len(l)):
			if min_val > l[j]:
				min_val = l[j]
				min_ind = j
		(l[i], l[min_ind]) = (l[min_ind], l[i])
	return l

def bubble_sort(l):
	for i in range(len(l) - 1):
		for j in range(len(l) - 1 - i):
			if l[j] > l[j + 1]:
				(l[j], l[j + 1]) = (l[j + 1], l[j])
	return l

def main_function():
	t = int(input())
	output_list = []
	for i in range(t):
		(s, a, b, c) = [int(i) for i in input().split(' ')]
		chocolates_can_buy = s // c
		adds = chocolates_can_buy // a * b + chocolates_can_buy
		output_list.append(str(adds))
	return '\n'.join(output_list)
print(main_function())