Chef talks a lot on his mobile phone. As a result he exhausts his talk-value (in Rokdas) very quickly. One day at a mobile recharge shop, he noticed that his service provider gives add-on plans which can lower his calling rates (Rokdas/minute). One of the plans said "Recharge for 28 Rokdas and enjoy call rates of 0.50 Rokdas/min for one month". Chef was very pleased. His normal calling rate is 1 Rokda/min. And he talked for 200 minutes in last month, which costed him 200 Rokdas. If he had this plan activated, it would have costed him: 28 + 0.5*200 = 128 Rokdas only! Chef could have saved 72 Rokdas. But if he pays for this add-on and talks for very little in the coming month, he may end up saving nothing or even wasting money. Now, Chef is a simple guy and he doesn't worry much about future. He decides to choose the plan based upon his last month’s usage.
There are numerous plans. Some for 1 month, some for 15 months. Some reduce call rate to 0.75 Rokdas/min, some reduce it to 0.60 Rokdas/min. And of course each of them differ in their activation costs. Note - If a plan is valid for M months, then we must pay for (re)activation after every M months (once in M months). Naturally, Chef is confused, and you (as always) are given the task to help him choose the best plan.

------ Input ------ 

First line contains T- the number of test cases. In each test case, first line contains D- the default rate (Rokdas/minute, real number), U- the number of minutes Chef talked in last month and N- the number of add-on plans available. Then N lines follow, each containing M- the number of months the plan is valid for, R- the calling rate for the plan (Rokdas/minute, real number) and C- the cost of the plan.

------ Output ------ 

For each test case, output one integer- the number of the best plan (from 1 to N). Output '0' if no plan is advantageous for Chef. No two plans are equally advantageous.

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

1 ≤ T ≤ 100
0.5 ≤ D ≤ 10.0 (exactly 2 digits after the decimal point)
1 ≤ U ≤ 10000
1 ≤ N ≤ 100
1 ≤ M ≤ 36
0.05 ≤ R < D (exactly 2 digits after the decimal point)
1 ≤ C ≤ 1000

----- Sample Input 1 ------ 
4
1.00 200 1
1 0.50 28
1.00 200 2
1 0.75 40
3 0.60 100
1.00 50 2
1 0.75 40
3 0.60 100
1.00 100 2
3 0.50 10
2 0.10 20
----- Sample Output 1 ------ 
1
2
0
2
----- explanation 1 ------ 
Test Case 1: This test case is same as the example in the problem statement.Test Case 2: This is for you to work out!Test Case 3: Chef's monthly usage is only 50 Rokdas and none of the 2 plans are advantageous, hence the answer is zero '0'.Test Case 4: Again solve it yourself, but NOTE - if Chef had chosen plan 1, he would have to pay 10 Rokdas (Activation cost), after every 3 months and NOT every month. Similarly had he chosen plan 2, he would have to pay 20 Rokdas (Activation cost), after every 2 months.

Source: codechef | Difficulty: MEDIUM
Tags: Mathematics

Implementation


Solutions:
a = int(input())
for i in range(a):
	(D, U, P) = list(map(float, input().split()))
	ans = 0
	cost = D * U
	temp = 1
	for k in range(int(P)):
		(M, R, C) = list(map(float, input().split()))
		if cost >= C / M + R * U:
			cost = C / M + R * U
			ans = temp
		temp += 1
	print(ans)


from math import ceil
out = []
t = int(input())
for i in range(t):
	l = input().split()
	d = float(l[0])
	u = int(l[1])
	n = int(l[2])
	a = []
	maxm = 0
	for j in range(n):
		k = input().split()
		m = int(k[0])
		r = float(k[1])
		c = int(k[2])
		if m > maxm:
			maxm = m
		a.append((j + 1, m, r, c))
	curr = d * u * maxm
	minp = curr
	pn = 0
	for j in a:
		p = j[2] * u * maxm + j[3] * maxm / j[1]
		if p < minp:
			minp = p
			pn = j[0]
	out.append(pn)
for i in out:
	print(i)


t = int(input())
while t > 0:
	(d, u, n) = map(float, input().split())
	n = int(n)
	cost = d * u
	ind = 0
	for i in range(n):
		(m, r, c) = map(float, input().split())
		if r * u + c / m < cost:
			cost = r * u + c / m
			ind = i + 1
	print(ind)
	t -= 1


out = []
for _ in range(int(input())):
	(d, u, n) = input().split()
	u = int(u)
	ans = float(d) * u
	res = 0
	for i in range(int(n)):
		(m, r, c) = input().split()
		m = int(m)
		r = float(r)
		c = int(c)
		if ans > r * u + c / m:
			res = i + 1
			ans = r * u + c / m
	out.append(res)
print(*out, sep='\n')


for _ in range(int(input())):
	(d, u, n) = input().split()
	d = float(d)
	(u, n) = (int(u), int(n))
	q = d * u
	y = q
	val = 0
	for i in range(n):
		(m, r, c) = map(float, input().split())
		e = c / m + r * u
		q = min(q, e)
		if q < y:
			val = i + 1
			y = q
	print(val)


for _ in range(int(input())):
	(D, U, N) = map(float, input().split())
	N = int(N)
	mn = D * U
	index_min = 0
	for i in range(N):
		(M, R, C) = map(float, input().split())
		monthly_price = C / M
		price = monthly_price + U * R
		if price < mn:
			mn = price
			index_min = i + 1
	print(index_min)


t = int(input())
while t != 0:
	(d, u, n) = [float(i) for i in input().split()]
	ans = []
	count = 0
	for i in range(int(n)):
		(m, r, c) = [float(i) for i in input().split()]
		original = d * u
		new = c / int(m) + r * u
		if new < original:
			ans.append([original - new, i])
		else:
			count += 1
	if count == n:
		print('0')
	else:
		ans.sort(key=lambda x: x[0], reverse=True)
		print(ans[0][-1] + 1)
	t -= 1


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	cost = d * u
	adcli = []
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		adcost = r * u + c / m
		adcli.append(adcost)
	mn = min(adcli)
	if cost > mn:
		print(adcli.index(mn) + 1)
	else:
		print(0)


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	de = d * u
	ans = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		p = u * r + c / m
		if de > p:
			ans = i + 1
			de = p
	print(ans)


for a in range(int(input())):
	(d, u, n) = map(float, input().split())
	ans = 0
	value = 0
	cheap = d * u
	n = int(n)
	for i in range(n):
		(m, r, c) = map(float, input().split())
		value = u * r + c / m
		if value < cheap:
			ans = i + 1
			cheap = value
	print(ans)


tests = int(input())
for test in range(tests):
	(D, U, N) = input().split()
	D = float(D)
	U = int(U)
	N = int(N)
	plans = []
	plans.append(D * U)
	for i in range(N):
		(M, R, C) = input().split()
		M = int(M)
		R = float(R)
		C = int(C)
		plans.append((R * (U * M) + C) / M)
	m = min(plans)
	print(plans.index(m))


T = int(input())
for _ in range(T):
	(d, u, n) = map(float, input().split())
	ans = 0
	initial = d * u
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		final = (r * u * m + c) / m
		if final < initial:
			ans = i + 1
			initial = final
	print(ans)


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	n = int(n)
	dr = d * u
	min1 = dr
	p = 0
	for i in range(1, n + 1):
		(m, r, c) = map(float, input().split())
		c = int(c)
		rc = r * u + c / m
		if rc < min1:
			min1 = rc
			p = i
	print(p)


t = int(input())
for i in range(t):
	(d, u, n) = map(float, input().split())
	s = d * u
	ans = 0
	for j in range(int(n)):
		(m, r, c) = map(float, input().split())
		p = u * r + c / m
		if s > p:
			ans = j + 1
			s = p
	print(ans)


t = int(input())
for i in range(t):
	i1 = input()
	I = i1.split()
	rate = float(I[0])
	minutes = float(I[1])
	plans = int(I[2])
	for j in range(plans):
		j1 = input()
		J = j1.split()
		planmonths = int(J[0])
		planrate = float(J[1])
		plancost = float(J[2])
		planexp = planrate * minutes + plancost / planmonths
		prevexp = rate * minutes
		if j == 0:
			a = prevexp
		if planexp < a:
			a = planexp
			b = j
	if a == prevexp:
		print(0)
	else:
		print(b + 1)


t = int(input())
for i in range(t):
	(d, u, n) = map(float, input().split())
	default = d * u
	count = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		k = r * u + c / m
		if k < default:
			default = k
			count = i + 1
	print(count)


import sys
input = sys.stdin.readline

def rii():
	return range(int(input().strip()))

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

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())

def solve(*args):
	(d, u, n, plans) = args
	current_plan_cost = u * d
	best = (0, current_plan_cost)
	for p in enumerate(plans):
		(m, r, c) = p[1]
		this_plan_cost = (r * u * m + c) / m
		if this_plan_cost < best[1]:
			best = (p[0] + 1, this_plan_cost)
	return best[0]

def do_codechef():
	for t in rii():
		line = si()
		(d, u, n) = (fn(x) for (fn, x) in zip([float, int, int], line.split(' ')))
		plans = list()
		for _ in range(n):
			line = si()
			(a, b, c) = (fn(x) for (fn, x) in zip([int, float, int], line.split(' ')))
			plans.append((a, b, c))
		print(solve(d, u, n, plans))
do_codechef()
exit()


def fn(l):
	return l[1]
for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	l = []
	for i in range(int(n)):
		l.append(list(map(float, input().split())))
	c = d * u
	x = []
	for i in l:
		x.append(i[2] / i[0] + u * i[1])
	g = [(i, x[i]) for i in range(len(x)) if x[i] <= c]
	if not len(g):
		print(0)
		continue
	print(min(g, key=fn)[0] + 1)


for _ in range(int(input())):
	(p, m, n) = map(float, input().split())
	cost = p * m
	ans = 0
	for i in range(int(n)):
		(month, r, c) = map(float, input().split())
		newcost = (c + r * m * month) / month
		if newcost < cost:
			cost = newcost
			ans = i + 1
	print(ans)


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	n = int(n)
	cost = d * u
	ans = 0
	for i in range(n):
		(m, r, c) = map(float, input().split())
		plan = c / m + r * u
		if plan < cost:
			cost = plan
			ans = i + 1
	print(ans)


for i in range(int(input())):
	inp = list(map(float, input().split()))
	c = inp[0]
	u = inp[1]
	n = int(inp[2])
	plans = []
	ans = 0
	curr = c * u
	for j in range(n):
		plans.append(list(map(float, input().split())))
	for k in range(n):
		plans[k] = (plans[k][0] * u * plans[k][1] + plans[k][2]) / plans[k][0]
	ans = min(plans)
	an = plans.index(ans)
	if curr < ans:
		print(0)
	else:
		print(an + 1)


t = int(input())
for _ in range(t):
	ans = 0
	(d, u, n) = map(float, input().split())
	mi = d * u
	i = 1
	while i <= n:
		(m, r, c) = map(float, input().split())
		temp = c / m + r * u
		if temp < mi:
			ans = i
			mi = temp
		i += 1
	print(ans)


from math import gcd, sqrt, ceil, floor, log10, log2
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
import sys
import time
import string
import operator
RECURSION_LIMIT = int(10000000.0)
INT_MAX = float('inf')
INT_MIN = float('-inf')
MOD = int(10000000.0) + 9
NEWLINE = '\n'
SPACE = ' '
sys.setrecursionlimit(RECURSION_LIMIT)
inp = lambda fn: fn(input())
inp_vars = lambda fn, delim, convert_to=list: convert_to(map(fn, input().split(delim)))
enum = lambda itr, start: enumerate(itr, start)

def toposort(graph, n):
	degree = [0] * n
	for node in graph:
		for adj in graph[node]:
			degree[adj] += 1
	bfs_queue = [node for node in range(n) if not degree[node]]
	for node in bfs_queue:
		for adj in graph[node]:
			degree[adj] -= 1
			if not degree[adj]:
				bfs_queue.append(adj)
	return (bfs_queue, degree)

def dfs(graph, node, visited):
	visited.add(node)
	for adj in graph[node]:
		if adj in visited:
			continue
		dfs(graph, adj, visited)

def seive(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = is_prime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if is_prime[i]:
			for j in range(i * i, n + 1, i):
				is_prime[j] = False
	return is_prime[n]

def solve(*args, **kwargs):
	(d, u, n, arr) = args
	(curr, plan) = (d * u, 0)
	for (idx, (validity, rate, cost)) in enum(arr, 1):
		new = cost / validity + rate * u
		if new < curr:
			plan = idx
			curr = new
	return plan

def main(*args, **kwargs):
	for _ in range(int(input())):
		arg1 = inp_vars(float, SPACE)
		arg3 = [inp_vars(float, SPACE) for _ in range(int(arg1[2]))]
		res = solve(*(*arg1, arg3))
		if type(res) in {list, tuple, set}:
			print(*res, sep='\n')
		else:
			print(res)
main()


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	cost = d * u
	ind = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		adcost = u * r + c / m
		if adcost < cost:
			ind = i + 1
			cost = adcost
	print(ind)


import os, sys, io, math
from re import *
from math import *
from array import *
from heapq import *
from bisect import *
from functools import *
from itertools import *
from statistics import *
from collections import *
I = lambda : [*map(int, sys.stdin.readline().split())]
IP = lambda : map(float, input().split())
IS = lambda : input()
IN = lambda : int(input())
IF = lambda : float(input())
for _ in range(IN()):
	(d, m, n) = IP()
	a = d * m
	idx = 0
	mn = a
	for i in range(int(n)):
		(mt, c, p) = IP()
		s = c * m + p / mt
		if s < mn:
			idx = i + 1
			mn = s
	print(idx)


t = int(input())
for z in range(t):
	(d, u, n) = map(float, input().split())
	default = u * d
	l = []
	for g in range(int(n)):
		(m, p, c) = map(float, input().split())
		l.append((p * u * m + c) / m)
	if default < min(l):
		print(0)
	else:
		print(l.index(min(l)) + 1)


t = int(input())
while t != 0:
	(d, u, n) = map(float, input().split())
	eco = d * u
	choice = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		if c / m + u * r < eco:
			eco = c / m + u * r
			choice = i + 1
	print(choice)
	t = t - 1


for j in range(int(input())):
	(d, u, n) = map(str, input().split())
	d = float(d)
	u = int(u)
	n = int(n)
	a = d * u
	x = []
	y = []
	for i in range(n):
		(m, r, c) = map(str, input().split())
		r = float(r)
		m = int(m)
		c = int(c)
		b = r * u + c / m
		x.append(b)
		y.append(a)
	c = min(x)
	d = 0
	for i in range(len(x)):
		if x[i] >= y[i]:
			d += 1
	if d == len(x):
		print(0)
	else:
		print(x.index(c) + 1)


t = int(input())
for _ in range(t):
	(d, u, n) = map(float, input().split())
	index = 0
	mini = d * u
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		m_c = c / m
		r_u = u * r
		if m_c + r_u <= mini:
			mini = m_c + r_u
			index = i + 1
	print(index)


for _ in range(int(input())):
	(a, b, c) = map(float, input().split())
	i = 0
	k = a * b
	for mm in range(1, int(c) + 1):
		(a1, a2, a3) = map(float, input().split())
		cc = a2 * b
		if k > cc + a3 / a1:
			i = mm
			k = cc + a3 / a1
	print(i)


test = int(input())
for _ in range(test):
	line1 = input()
	(d, u, n) = line1.split()
	d = float(d)
	u = int(u)
	n = int(n)
	present = d * u
	index = 0
	for i in range(1, n + 1):
		line2 = input()
		(m, r, c) = line2.split()
		m = int(m)
		r = float(r)
		c = int(c)
		new = (c + r * m * u) / m
		if new < present:
			present = new
			index = i
	print(index)


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	s = 0
	a = u * d
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		t = c / m + r * u
		if t < a:
			a = t
			s = 1 + i
	print(s)


for _ in range(int(input())):
	(a, b, c) = map(float, input().split())
	ans = 0
	tam = a * b
	for i in range(int(c)):
		(x, y, z) = map(float, input().split())
		if tam > z / x + b * y:
			ans = i + 1
			tam = z / x + b * y
	print(ans)


for _ in range(int(input())):
	(D, U, N) = map(float, input().split())
	cost = D * U
	cost_array = []
	for i in range(round(N)):
		(M, R, C) = map(float, input().split())
		cost_array.append(C / M + R * U)
	best_cost = min(cost_array)
	if best_cost > cost:
		print(0)
	else:
		print(cost_array.index(best_cost) + 1)


t = int(input())
for tc in range(t):
	(d, u, n) = map(float, input().split())
	s = d * u
	count = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		total = c / m + r * u
		if total < s:
			s = total
			count = i + 1
	print(count)


for _ in range(int(input())):
	(D, U, N) = map(float, input().split())
	x = D * U
	y = 0
	for i in range(int(N)):
		(M, R, C) = map(float, input().split())
		a = M * U * R + C
		b = M * x
		if a < b:
			x = a / M
			y = i + 1
	print(y)


t = int(input())
while t:
	t -= 1
	str = input()
	(i_rate, min_call, n) = map(float, str.split())
	bst = 0
	ind = 0
	for i in range(int(n)):
		str = input()
		(mon, n_rate, prc) = map(float, str.split())
		sav = min_call * i_rate - (min_call * n_rate + prc / mon)
		if sav > bst:
			bst = sav
			ind = i + 1
	print(ind)


for _ in range(int(input())):
	(s, sa, d) = map(float, input().split())
	co = s * sa
	cod = []
	for i in range(round(d)):
		(f, g, c) = map(float, input().split())
		cod.append(c / f + g * sa)
	bed = min(cod)
	if bed > co:
		print(0)
	else:
		print(cod.index(bed) + 1)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
for _ in range(int(input())):
	(chgpermin, minutes, nb_plans) = [float(x) for x in input().split()]
	present_cost = chgpermin * minutes
	maybe = 0
	for i in range(int(nb_plans)):
		(months, calling_rate, activation_cost) = [float(x) for x in input().split()]
		act_cost = activation_cost / months
		call_chg = minutes * calling_rate
		total_cost = call_chg + act_cost
		if total_cost < present_cost:
			present_cost = total_cost
			maybe = i + 1
	print(maybe)


for i in range(int(input())):
	(og_rate, time, plans) = map(float, input().split())
	og_amt = og_rate * time
	bestplan = 0
	savings = 0
	for j in range(int(plans)):
		(months, rate, act_price) = map(float, input().split())
		monthly_act = act_price / months
		plan_tamt = time * rate + monthly_act
		diff = og_amt - plan_tamt
		if diff > savings:
			savings = diff
			bestplan = j + 1
	print(bestplan)


T = int(input())
for x in range(T):
	(d, u, n) = map(float, input().split())
	ans = 0
	mc = u * d
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		cc = u * r + c / m
		if mc > cc:
			ans = i + 1
			mc = cc
	print(ans)


out = []
for _ in range(int(input())):
	lst = input().split()
	u = int(lst[1])
	ans = float(lst[0]) * u
	res = 0
	for i in range(int(lst[2])):
		lst = input().split()
		temp = float(lst[1]) * u + int(lst[2]) / int(lst[0])
		if ans > temp:
			res = i + 1
			ans = temp
	out.append(res)
print(*out, sep='\n')


t = int(input())
for i in range(t):
	(a, b, c) = map(float, input().split())
	minimum = a * b
	result = 0
	for j in range(int(c)):
		(x, y, z) = map(float, input().split())
		if y * b + z / x < minimum:
			minimum = y * b + z / x
			result = j + 1
	print(result)


for _ in range(int(input())):
	array = []
	(d, u, n) = map(float, input().split())
	for _ in range(int(n)):
		(m, r, c) = map(float, input().split())
		temp = c / m + r * u
		array.append(c / m + r * u)
	m = min(array)
	if m < d * u:
		print(array.index(m) + 1)
	else:
		print(0)


tests = int(input())
for i in range(tests):
	(original_price, minutes, plans) = map(float, input().split())
	original_paid = original_price * minutes
	plan = 0
	savings = 0
	for j in range(int(plans)):
		(months, per_minute, plan_price) = map(float, input().split())
		price_per_month = plan_price / months
		paid_price_with_plan = minutes * per_minute + price_per_month
		diff = original_paid - paid_price_with_plan
		if diff > savings:
			savings = diff
			plan = j + 1
	print(plan)


for i in range(int(input())):
	(d, u, n) = input().split()
	d = float(d)
	(u, n) = (int(u), int(n))
	total = d * u
	count = 0
	for i in range(n):
		(m, r, c) = map(float, input().split())
		if r >= d:
			continue
		else:
			val = r * u + c / m
			if val < total:
				count = i + 1
				total = val
	print(count)


t = int(input())
while t > 0:
	t -= 1
	l = []
	(d, u, n) = map(float, input().split())
	x = d * u
	for i in range(0, int(n)):
		(m, r, c) = map(float, input().split())
		l.append(r * u + c / m)
	count = 0
	for i in range(0, int(n)):
		if l[i] < x:
			x = l[i]
			count = i + 1
	print(count)


for x in range(int(input())):
	(d, u, n) = map(float, input().split())
	u = int(u)
	n = int(n)
	pl = [d * u]
	for xx in range(n):
		(m, r, c) = map(float, input().split())
		m = int(m)
		c = int(c)
		pl += [r * u + c / m]
	print(pl.index(min(pl)))


from collections import Counter
for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	n = int(n)
	m = d * u
	a = []
	a.append(m)
	while n:
		n -= 1
		(mn, r, c) = map(float, input().split())
		x = (r * mn * u + c) / mn
		a.append(x)
	mn = min(a)
	for i in range(len(a)):
		if a[i] == mn:
			print(i)
			break


for _ in range(int(input())):
	(default_rate, last_min, n_plans) = map(float, input().split())
	flag = 0
	old_expense = default_rate * last_min
	ind = -12
	for i in range(int(n_plans)):
		(monthref, call_rate, cost) = map(float, input().split())
		expense = last_min * call_rate + cost / monthref
		if expense < old_expense:
			ind = i
			flag = 1
			old_expense = expense
	if flag == 0:
		print('0')
	else:
		print(ind + 1)


t = int(input())
for i in range(t):
	(D, U, N) = map(float, input().split())
	max = D * U
	N = int(N)
	index = 0
	for i in range(N):
		(M, R, C) = map(float, input().split())
		price = C / M
		price1 = U * R + price
		if price1 < max:
			max = price1
			index = i + 1
	print(index)


for _ in range(int(input())):
	(d, u, n) = map(float, input().split())
	val = d * u
	ans = 0
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		total = r * u + c / m
		if total < val:
			val = total
			ans = i + 1
	print(ans)


import sys
T = int(input())
for i in range(T):
	testInput = input().split(' ')
	D = float(testInput[0])
	U = int(testInput[1])
	N = int(testInput[2])
	minAmount = D * U
	minPlan = 0
	for i in range(N):
		testInput = input().split(' ')
		m = int(testInput[0])
		r = float(testInput[1])
		c = int(testInput[2])
		amount = r * U + c / m
		if amount < minAmount:
			minAmount = amount
			minPlan = i + 1
	print(minPlan)


a = int(input())
for i in range(a):
	(d, u, n) = map(float, input().split())
	b = d * u
	f = 0
	for j in range(int(n)):
		(m, r, c) = map(float, input().split())
		e = c / m + r * u
		if e < b:
			b = e
			f = 1 + j
	print(f)


for _ in range(int(input())):
	lst = []
	choice = 0
	(d, u, n) = map(float, input().split())
	check = d * u
	for i in range(int(n)):
		(m, r, c) = map(float, input().split())
		check1 = c / m + r * u
		if check > check1:
			check = check1
			choice = i + 1
	print(choice)


for i in range(int(input())):
	(d, u, n) = map(float, input().split())
	cost = u * d
	flag = 0
	for j in range(int(n)):
		(m, r, c) = map(float, input().split())
		c = c / m
		cost1 = c + r * u
		if cost1 < cost:
			cost = cost1
			flag = 1
			p = j + 1
	if flag == 1:
		print(p)
	else:
		print(0)


def solve():
	(d, u, n) = map(float, input().split())
	ans = 0
	expense = d * u
	for i in range(1, int(n) + 1):
		(m, r, c) = map(float, input().split())
		plan_expense = u * r + c / m
		if plan_expense < expense:
			expense = plan_expense
			ans = i
	print(ans)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(d, u, n) = map(float, input().split())
	min = d * u
	ans = 0
	l = []
	for j in range(int(n)):
		(m, r, c) = map(float, input().split())
		l.append([m, r, c])
	for j in range(len(l)):
		(m, r, c) = (l[j][0], l[j][1], l[j][2])
		cost = u * r + c / m
		if cost < min:
			ans = j + 1
			min = cost
	print(ans)