Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef and Chefu are working as gold miners. There are a total of $N$ gold mines, numbered $1$ through $N$. For each valid $i$, the $i$-th gold mine contains $G_{i}$ gold in total; if only Chef worked in it, it would take him $A_{i}$ days to completely mine it, while if only Chefu worked in it, it would take him $B_{i}$ days.

Each of our miners may only work in one mine at a time, but they may decide to start working in another mine at any time (even in the middle of some day), any number of times. They also choose the mines to work in independently from each other and they may work in the same mine at the same time. Mining gold is a continuous process, i.e. if a miner works for $t$ days (where $t$ is a real number) in a mine where this miner has mining speed $g$ gold per day, then he will mine $g \cdot t$ gold. Obviously, it is impossible to work in a mine after no gold remains in it. For example, if a gold mine contains $30$ gold and Chef needs $2$ days to completely mine it, but he spends $1$ day in it, then he will mine $15$ gold; if Chefu needs $1$ day to completely mine the same gold mine, and both Chef and Chefu start working in this mine at the same time, it will be empty after $2/3$ days ― Chefu will mine $20$ gold, while Chef will mine $10$ gold.

At each point of time, both Chef and Chefu know the gold mine in which the other miner is working. Each of them wants to gather the maximum amount of gold for himself. Find the amounts of gold the miners will have if they both act optimally.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains three space-separated integers $G_{i}$, $A_{i}$ and $B_{i}$.

------  Output ------
For each test case, print a single line containing two space-separated real numbers ― the amount of gold mined by Chef and the amount of gold mined by Chefu. Your answer will be considered correct if the absolute or relative error of each amount of gold does not exceed $10^{-6}$.

------  Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ G_{i} ≤ 10^{5}$ for each valid $i$
$1 ≤ A_{i} ≤ 10^{5}$ for each valid $i$
$1 ≤ B_{i} ≤ 10^{5}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{6}$

------  Subtasks ------
Subtask #1 (50 points): $N ≤ 2$

Subtask #2 (50 points): original constraints

----- Sample Input 1 ------ 
2

1

30 2 1

3

10 1 1

20 2 2

30 3 3
----- Sample Output 1 ------ 
10.00000 20.00000

30.00000 30.00000

Source: codechef | Difficulty: HARD
Tags: Constructive algorithms

Mathematics

Ad-hoc


Solutions:
def Code():
	T = int(input())
	for i in range(T):
		N = int(input())
		sum_A = 0
		sum_B = 0
		for i in range(N):
			x = list(map(int, input().split()))
			sum_A = sum_A + x[0] * x[2] / (x[1] + x[2])
			sum_B = sum_B + x[0] * x[1] / (x[1] + x[2])
		print('{0:.10f}'.format(sum_A), '{0:.10f}'.format(sum_B))
Code()


T = int(input())
for tc in range(T):
	N = int(input())
	chef = 0.0
	chefu = 0.0
	for i in range(N):
		lst = list(map(int, input().split()))
		chef = chef + lst[0] * lst[2] / (lst[1] + lst[2])
		chefu = chefu + lst[0] * lst[1] / (lst[1] + lst[2])
	print('{0:.10f}'.format(chef), '{0:.10f}'.format(chefu))


for _ in range(int(input())):
	n = int(input())
	(g, a, b) = ([], [], [])
	chef = 0
	chefu = 0
	for i in range(n):
		(x, y, z) = map(int, input().split())
		g.append(x)
		a.append(y)
		b.append(z)
		chef += g[i] * (b[i] / (a[i] + b[i]))
		chefu += g[i] * (a[i] / (a[i] + b[i]))
	print(chef, chefu)


for i in range(int(input())):
	n = int(input())
	res1 = 0.0
	res2 = 0.0
	for j in range(0, n):
		lst = list(map(int, input().split()))
		res1 = res1 + lst[0] * lst[2] / (lst[1] + lst[2])
		res2 = res2 + lst[0] * lst[1] / (lst[1] + lst[2])
	print('{0:.10f}'.format(res1), '{0:.10f}'.format(res2))


t = int(input())
for i in range(t):
	nn = 0
	aa = 0
	bb = 0
	y = int(input())
	for j in range(y):
		(n, a, b) = list(map(int, input().split()))
		d = a + b
		e = n / d
		suma = e * a
		aa += suma
		sumb = e * b
		bb += sumb
	print(bb, end=' ')
	print(aa)


def solve():
	gold_mines = []
	N = int(input())
	for _ in range(N):
		(amount, A, B) = map(int, input().split())
		gold_mines.append([amount, A, B])
	(ans1, ans2) = (0.0, 0.0)
	for i in range(N):
		sumRatio = gold_mines[i][1] + gold_mines[i][2]
		ans1 += gold_mines[i][0] * gold_mines[i][2] / sumRatio
		ans2 += gold_mines[i][0] * gold_mines[i][1] / sumRatio
	print('{0:.10f}'.format(ans1), '{0:.10f}'.format(ans2))
T = int(input())
for _ in range(0, T):
	solve()


a = int(input())
for i in range(a):
	b1 = 0
	c1 = 0
	n = int(input())
	for j in range(n):
		(g, b, c) = map(int, input().split())
		d = g / (b + c)
		b1 = b1 + d * c
		c1 = c1 + d * b
	print('%.5f' % b1, '%.5f' % c1)


T = int(input())
for i in range(T):
	(a1, b1) = (0, 0)
	for i in range(int(input())):
		(g, a, b) = map(int, input().split())
		p = g / (a + b)
		a1 += p * a
		b1 += p * b
	ans1 = '{0:.5f}'.format(a1)
	ans2 = '{0:.5f}'.format(b1)
	print(ans2, ans1)


def solve():
	n = int(input())
	cu = 0
	cf = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		cu = cu + a / (a + b) * g
		cf = cf + b / (a + b) * g
	print(cf, cu)
	return
try:
	t = int(input())
	for i in range(t):
		solve()
except:
	pass


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


for _ in range(int(input())):
	n = int(input())
	chef = 0
	chefu = 0
	for _ in range(n):
		(g, a, b) = map(int, input().split(' '))
		x1 = a / (a + b)
		x2 = b / (a + b)
		chef = x2 * g + chef
		chefu = x1 * g + chefu
	print(chef, chefu)


for _ in range(int(input())):
	(chef, chefu) = (0, 0)
	for i in range(int(input())):
		(gold, ai, bi) = map(int, input().split())
		chef += bi * gold / (ai + bi)
		chefu += ai * gold / (ai + bi)
	print(round(chef, 5), round(chefu, 5))


for i in range(int(input())):
	n = int(input())
	l = 0
	m = 0
	s = 0
	for j in range(n):
		(g, a, b) = map(int, input().split())
		d = 0
		if a > b:
			l += g - max(a, b) / (a + b) * g
			m += max(a, b) / (a + b) * g
		elif b > a:
			l += max(a, b) / (a + b) * g
			m += g - max(a, b) / (a + b) * g
		else:
			l += max(a, b) / (a + b) * g
			m += max(a, b) / (a + b) * g
	print('{0:.5f}'.format(l), '{0:.5f}'.format(m))


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


for _ in range(int(input())):
	n = int(input())
	chef = 0
	chefu = 0
	for _ in range(n):
		(total, x, y) = map(int, input().split())
		chef += total * y / (x + y)
		chefu += total * x / (x + y)
	print(chef, chefu)


t = int(input())
while t:
	n = int(input())
	(c1, c2) = (0, 0)
	while n:
		(g, a, b) = map(int, input().split())
		c1 += g * (a / (a + b))
		c2 += g * (b / (a + b))
		n -= 1
	c1 = '{0:.5f}'.format(c1)
	c2 = '{0:.5f}'.format(c2)
	print(c2, c1)
	t -= 1


ted = int(input())
for i in range(ted):
	n = int(input())
	chef = 0
	chefu = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		sas = g / (a + b)
		a = sas * a
		b = sas * b
		chef += a
		chefu += b
	print(round(chefu, 5), end=' ')
	print(round(chef, 5))


t = int(input())
while t != 0:
	t = t - 1
	b = int(input())
	c = 0
	d = 0
	for i in range(0, b):
		(g, a, b) = map(int, input().split())
		c += g * a / (a + b)
		d += g * b / (a + b)
	print('%.5f' % d, '%.5f' % c)


for _ in range(int(input())):
	n = int(input())
	(ch, cf) = (0, 0)
	for i in range(n):
		(g, a, b) = list(map(int, input().split()))
		t = a + b
		ch += g * b / t
		cf += g * a / t
	ch = '%.5f' % round(ch, 5)
	cf = '%.5f' % round(cf, 5)
	print(ch, cf)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	a = b = 0
	for i in range(n):
		t = iia()
		a += t[0] * (t[2] / (t[1] + t[2]))
		b += t[0] * (t[1] / (t[1] + t[2]))
	print(a, b)


for test in range(int(input())):
	n = int(input())
	(r1, r2) = (0, 0)
	for i in range(n):
		(a, x, y) = map(int, input().split())
		r1 += a * y / (x + y)
		r2 += a * x / (x + y)
	print(r1, end=' ')
	print(r2)


t = int(input())
for _ in range(t):
	n = int(input())
	q = 0
	w = 0
	for i in range(n):
		(g, a, b) = input().split()
		(g, a, b) = (int(g), int(a), int(b))
		q += g * b / (a + b)
		w += g * a / (a + b)
	print(q, w)


t = int(input())
for _ in range(t):
	n = int(input())
	(chef_gold, chefu_gold) = (0, 0)
	for i in range(n):
		[x, y, z] = list(map(int, input().split()))
		chef_gold += x * z / (y + z)
		chefu_gold += x * y / (y + z)
	print('{:.6f} {:.6f}'.format(chef_gold, chefu_gold))


t = int(input())
for i in range(t):
	n = int(input())
	chef_g = 0
	chefu_g = 0
	for j in range(n):
		(G, A, B) = map(int, input().split())
		chef_g += A / (A + B) * G
		chefu_g += B / (A + B) * G
	print(str(chefu_g) + ' ' + str(chef_g))


t = int(input())
for i in range(t):
	n = int(input())
	g = []
	a = []
	b = []
	chef_gold = 0.0
	chefu_gold = 0.0
	for j in range(n):
		(G, A, B) = map(int, input().split())
		g.append(G)
		a.append(A)
		b.append(B)
		chef_gold += a[j] / (a[j] + b[j]) * g[j]
		chefu_gold += b[j] / (a[j] + b[j]) * g[j]
	print(str(chefu_gold) + ' ' + str(chef_gold))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def func(a, b):
	if a[0] == b[0]:
		if a[1] < b[1]:
			return -1
		else:
			return 1
	if a[0] > b[0]:
		return -1
	else:
		return 1

def solve():
	for _ in range(ii()):
		(a1, a2) = (0, 0)
		n = ii()
		for i in range(n):
			(g, a, b) = mi()
			a1 += g * b / (a + b)
			a2 += g * a / (a + b)
		print(a1, a2)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
for _ in range(t):
	n = int(input())
	(res_a, res_b) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, input().split())
		x = 1 / a + 1 / b
		x = 1 / x
		res_a += g * x * 1 / a
		res_b += g * x * 1 / b
	print(res_a, res_b)


t = int(input())
while t:
	p = int(input())
	g1 = 0
	g2 = 0
	while p:
		(x, y, z) = list(map(int, input().split(' ')))
		g1 = x * (y / (y + z)) + g1
		g2 = x * (z / (y + z)) + g2
		p = p - 1
	print('%.5f' % g2, '%.5f' % g1)
	t = t - 1


for i in range(int(input())):
	(a1, b1) = (0, 0)
	num = int(input())
	for j in range(num):
		(g, a, b) = map(int, input().split())
		sum = g / (a + b)
		a1 = abs(a1 + sum * a)
		b1 = abs(b1 + sum * b)
	print(b1, a1)


test = int(input())
for _ in range(test):
	n = int(input())
	(c1, c2) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, input().split())
		c = a + b
		c1 += g * (b / c)
		c2 += g * (a / c)
	print(c1, c2)


t = int(input())
for _ in range(t):
	n = int(input())
	cg = 0
	cug = 0
	for i in range(n):
		(g, c, cu) = map(int, input().split())
		cg += g * (cu / (c + cu))
		cug += g * (c / (c + cu))
	print('{:.5f}'.format(cg), '{:.5f}'.format(cug), sep=' ')


t = int(input())
while t > 0:
	n = int(input())
	(chef, chefu) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, input().split())
		(a, b) = (g / a, g / b)
		chef += g * a / (a + b)
		chefu += g * b / (a + b)
	print('%.5f %.5f' % (chef, chefu))
	t -= 1


for t in range(int(input())):
	n = int(input())
	data = [[int(x) for x in input().split()] for _ in range(n)]
	(chef, chefu) = (0.0, 0.0)
	for ele in data:
		(g, a, b) = (ele[0], ele[0] / ele[1], ele[0] / ele[2])
		chef += g * a / (a + b)
		chefu += g * b / (a + b)
	print('%.5f %.5f' % (chef, chefu))


t = int(input())
for i in range(0, t):
	n = int(input())
	sumg = 0
	suma = 0
	sumb = 0
	for j in range(0, n):
		(g, a, b) = map(int, input().split())
		temp = 1 / a + 1 / b
		sharea = 1 / a / temp * g
		shareb = 1 / b / temp * g
		suma = suma + sharea
		sumb = sumb + shareb
	print(suma, sumb)


n = int(input())
for _ in range(n):
	t = int(input())
	(ans1, ans2) = (0, 0)
	for i in range(t):
		(g, a, b) = map(int, input().split())
		z = g / (a + b)
		ans1 += b * z
		ans2 += a * z
	print('{:.6f}'.format(ans1), '{:.6f}'.format(ans2))


for _ in range(int(input())):
	n = int(input())
	chef = 0
	chefu = 0
	for i in range(n):
		(g, a, b) = [int(x) for x in input().split()]
		chef += g * (b / (a + b))
		chefu += g * (a / (a + b))
	print('%.5f %.5f' % (chef, chefu))


import sys

def finp():
	return sys.stdin.readline()

def fop(s):
	return sys.stdout.write(str(s) + '\n')

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

def flistintinp():
	return list(map(int, finp().split()))

def op(s):
	return s

def inp():
	return input()

def intop(s):
	return int(s)

def intinp():
	return int(input())

def listintinp():
	return list(map(int, inp().split()))

def listinp():
	return list(map(str, inp().split()))
import math
primelists = []
maxprecomprimeval = 100001
from math import ceil, sqrt
mysievelists = [i for i in range(maxprecomprimeval)]

def primeprecomputer():
	for i in range(2, math.ceil(math.sqrt(maxprecomprimeval))):
		if mysievelists[i] == i:
			for j in range(i * i, maxprecomprimeval, i):
				if mysievelists[j] == j:
					mysievelists[j] = i
	for i in range(2, maxprecomprimeval):
		if mysievelists[i] == i:
			primelists.append(mysievelists[i])
	return primelists
from bisect import bisect_right, bisect_left

def bisectright(lists, nbr):
	return bisect_right(lists, nbr)

def bisectleft(lists, nbr):
	return bisect_left(lists, nbr)
MOD = 100000007
mpflists = []

def mpf(n):
	k = 0
	primeprecomputer()
	while n != 1:
		print(mysievelists[n])
		mpflists.append(mysievelists[n])
		n //= mysievelists[n]
		k += 1
	return mpflists
for __ in range(intinp()):
	n = intinp()
	(chef, chefu) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, inp().split())
		c = g / (a + b)
		chef += c * a
		chefu += c * b
	print('%.5f' % chefu, '%.5f' % chef)


t = int(input())
for _ in range(t):
	N = int(input())
	(A, B, G) = ([0] * N, [0] * N, [0] * N)
	for i in range(N):
		(G[i], A[i], B[i]) = map(int, input().split())
	(x1, x2) = (0, 0)
	for i in range(N):
		x = 1 / (A[i] + B[i])
		x1 += x * B[i] * G[i]
		x2 += x * A[i] * G[i]
	print(x1, x2)


for _ in range(int(input())):
	(c1, c2) = (0, 0)
	for _ in range(int(input())):
		(g, a, b) = [int(x) for x in input().split()]
		c1 += g * a / (a + b)
		c2 += g * b / (a + b)
	print('%.6f' % c2, '%.6f' % c1, sep=' ')


t = int(input())
for x in range(t):
	n = int(input())
	(i, j) = (0, 0)
	for k in range(n):
		(g, a, b) = map(int, input().split())
		(p, q) = (g / a, g / b)
		s = g / (p + q)
		i += s * p
		j += s * q
	print(str(i) + ' ' + str(j))


t = int(input())
while t > 0:
	n = int(input())
	sum1 = 0
	sum2 = 0
	for i in range(n):
		(g, a, b) = list(map(int, input().split()))
		sum1 += g * (b / (a + b))
		sum2 += g * (a / (a + b))
	print('%.6f' % sum1, end=' ')
	print('%.6f' % sum2)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	ag = 0
	bg = 0
	for i in range(n):
		[g, a, b] = [int(x) for x in input().split()]
		ag += g * b / (a + b)
		bg += g * a / (a + b)
	print(ag, bg)


t = int(input())
for i in range(t):
	n = int(input())
	share_a = 0
	share_b = 0
	for j in range(n):
		(tot, a, b) = map(int, input().split())
		share_a += b / (b + a) * tot
		share_b += a / (b + a) * tot
	share_a = format(share_a, '.5f')
	share_b = format(share_b, '.5f')
	print(str(share_a) + ' ' + str(share_b))


for i in range(int(input())):
	n = int(input())
	c = ch = 0
	for i in range(n):
		a = list(map(int, input().split()))
		s = a[1] + a[2]
		c += a[1] * (a[0] / (a[2] + a[1]))
		ch += a[2] * (a[0] / (a[2] + a[1]))
	print('%.5f %.5f' % (ch, c))


def gold(n, g, d1, d2):
	g1 = 0
	g2 = 0
	for i in range(n):
		g1 += g[i] * d2[i] / (d1[i] + d2[i])
		g2 += g[i] * d1[i] / (d1[i] + d2[i])
	l = list()
	l.append(g1)
	l.append(g2)
	return l
t = int(input())
for i in range(t):
	n = int(input())
	g = list()
	d1 = list()
	d2 = list()
	w = list()
	for j in range(n):
		l = list(map(int, input().strip().split()))
		g.append(l[0])
		d1.append(l[1])
		d2.append(l[2])
	w = gold(n, g, d1, d2)
	for k in w:
		print('%.5f' % k, ' ', end='')
	print('')


class GOLD:

	def __init__(self, G, A, B):
		self.ga = G / A
		self.gb = G / B
		self.res = G / (self.ga + self.gb)

	def amgA(self):
		return self.ga * self.res

	def amgB(self):
		return self.gb * self.res
T = int(input())
for i in range(T):
	N = int(input())
	L = []
	for i in range(N):
		res = list(map(int, input().split()))
		L.append(res)
	sga = 0
	sgb = 0
	for i in range(N):
		amntofgold = GOLD(L[i][0], L[i][1], L[i][2])
		sga += amntofgold.amgA()
		sgb += amntofgold.amgB()
	print('{:.5f}'.format(sga), end=' ')
	print('{:.5f}'.format(sgb))


for _ in range(int(input())):
	N = int(input())
	chef = 0
	chefu = 0
	for i in range(0, N):
		(G, A, B) = map(int, input().split())
		chef += G * A / (A + B)
		chefu += G * B / (A + B)
	print('{0:.5f}'.format(chefu), '{0:.5f}'.format(chef))


import sys
read = sys.stdin.readline
for i in range(int(read())):
	resa = resb = 0
	for j in range(int(read())):
		(g, a, b) = list(map(int, read().split()))
		k = g / (a + b)
		resa += k * b
		resb += a * k
	print('{0:8f}'.format(resa), end=' ')
	print('{0:8f}'.format(resb))


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	suma = 0
	sumb = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		suma = suma + g * (b / (a + b))
		sumb = sumb + g * (a / (a + b))
	print(suma, sumb)


t = int(input())
for i in range(t):
	n = int(input())
	a = 0
	b = 0
	for j in range(n):
		l = list(input().split())
		l[0] = int(l[0])
		l[1] = int(l[1])
		l[2] = int(l[2])
		su = l[1] + l[2]
		r = l[0] / float(su)
		a = a + r * l[2]
		b = b + r * l[1]
	print(str(a) + ' ' + str(b))


t = int(input())
for _ in range(t):
	n = int(input())
	l = 0
	m = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		z = min(a, b)
		x = max(g / a, g / b)
		y = g / (g / a + g / b)
		l += y * (g / a)
		m += y * (g / b)
	print('%6f' % l, '%6f' % m)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		(chef, chefu) = (0, 0)
		for _ in range(N):
			(Gi, Ai, Bi) = map(int, input().split())
			chef += Bi * Gi / (Ai + Bi)
			chefu += Ai * Gi / (Ai + Bi)
		print('%.6f' % chef, '%.6f' % chefu)
main()


for _ in range(int(input())):
	N = int(input())
	(ans1, ans2) = (0, 0)
	for x in range(N):
		(G, A, B) = map(int, input().split())
		ans2 += A / (A + B) * G
		ans1 += B / (A + B) * G
	print(ans1, ans2)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	a = 0
	b = 0
	for i in range(n):
		(g, aw, bw) = map(int, input().split())
		a += g * (aw / (aw + bw))
		b += g * (bw / (aw + bw))
	print(b, a)


for _ in range(int(input())):
	n = int(input())
	g = [0] * n
	a = [0] * n
	b = [0] * n
	for i in range(n):
		(g[i], a[i], b[i]) = map(int, input().split())
	count1 = 0
	count2 = 0
	for i in range(n):
		x = g[i] / (a[i] + b[i])
		count1 += x * b[i]
		count2 += x * a[i]
	print(format(count1, '.8f'), format(count2, '.8f'))


t = int(input())
for _ in range(t):
	n = int(input())
	(s1, s2) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, input().split())
		total = a + b
		av = g / total
		s1 += av * b
		s2 += av * a
	print('%.6f' % s1, '%.6f' % s2)


for _ in range(int(input())):
	n = int(input())
	ans1 = 0
	ans2 = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		ans1 += g * a / (a + b)
		ans2 += g * b / (a + b)
	print('{0:.5f}'.format(ans2), '{0:.5f}'.format(ans1))


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		ans_a = 0
		ans_b = 0
		for _ in range(n):
			(g, a, b) = map(int, input().split())
			ans_a += g * b / (a + b)
			ans_b += g * a / (a + b)
		print(f'{ans_a:.5f}', end=' ')
		print(f'{ans_b:.5f}')
except:
	pass


for _ in range(int(input())):
	n = int(input())
	(x, y) = (0, 0)
	for i in range(n):
		(g, a, b) = map(int, input().split())
		t = a + b
		t = g / t
		(x, y) = (x + b * t, y + a * t)
	print('{:.5f}'.format(x), '{:.5f}'.format(y))


t = int(input())
for _ in range(t):
	n = int(input())
	resa = 0.0
	resb = 0.0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		resa += b * g / (a + b)
		resb += a * g / (a + b)
	print(resa, resb)


for _ in range(int(input())):
	(x, y) = (0, 0)
	for _ in range(int(input())):
		(g, a, b) = map(int, input().split())
		x += g / (a + b) * a
		y += g / (a + b) * b
	print(y, x)


for _ in range(int(input())):
	n = int(input())
	s1 = 0.0
	s2 = 0.0
	for i in range(0, n):
		(g, a, b) = map(int, input().split())
		s1 += g * a / (a + b)
		s2 += g * b / (a + b)
	print(s2, s1)


for _ in range(int(input())):
	n = int(input())
	data = []
	for _ in range(n):
		(g, a, b) = map(int, input().split())
		data.append([g, a, b, b / (a + b), a / (a + b)])
	chef = 0
	chefu = 0
	for d in data:
		chef += d[0] * d[3]
		chefu += d[0] * d[4]
	print(chef, chefu)


for _ in range(int(input())):
	n = int(input())
	data = []
	for _ in range(n):
		(g, a, b) = map(int, input().split())
		data.append([g, a, b, b / (a + b), a / (a + b)])
	data.sort(key=lambda x: x[0], reverse=True)
	chef = 0
	chefu = 0
	for d in data:
		chef += d[0] * d[3]
		chefu += d[0] * d[4]
	print(chef, chefu)


for _ in range(int(input())):
	n = int(input())
	a = 0
	b = 0
	for inp in range(n):
		(g, x, y) = map(int, input().split())
		a += g * x / (x + y)
		b += g * y / (x + y)
	(a, b) = (str(round(a, 8)), str(round(b, 8)))
	adot = len(a.split('.')[1])
	bdot = len(b.split('.')[1])
	if adot < 8:
		a += '0' * (8 - adot)
	if bdot < 8:
		b += '0' * (8 - bdot)
	print(b, a)


for i in range(int(input())):
	A = 0
	B = 0
	for j in range(int(input())):
		x = input().split()
		for k in range(int(len(x))):
			x[k] = int(x[k])
		c = x[1] + x[2]
		d = x[0] / c
		A += float('%.9f' % d) * x[2]
		B += float('%.9f' % d) * x[1]
	H = ['%.5f' % A, '%.5f' % B]
	print(*H)


for _ in range(int(input())):
	n = int(input())
	c1 = 0
	c2 = 0
	for i in range(n):
		(g, a, b) = map(int, input().split())
		p = g / a
		q = g / b
		c1 += p * g / (p + q)
		c2 += q * g / (p + q)
	print(c1, c2)


T = int(input())
for i in range(T):
	N = int(input())
	G = 0
	A = 0
	b = 0
	ratio = 0
	collectedA = 0
	collectedB = 0
	for j in range(N):
		(G, A, B) = map(int, input().split())
		ratio = A + B
		temp = A
		A = B
		B = temp
		collectedA += G / ratio * A
		collectedB += G / ratio * B
	print(str(collectedA) + ' ' + str(collectedB))


for _ in range(int(input())):
	n = int(input())
	g = []
	a = []
	b = []
	for i in range(n):
		(x, y, z) = map(int, input().split())
		g.append(x)
		a.append(y)
		b.append(z)
	ans1 = float(0)
	ans2 = float(0)
	for i in range(n):
		ans1 = ans1 + float(g[i] * b[i] / (a[i] + b[i]))
		ans2 = ans2 + float(g[i] * a[i] / (a[i] + b[i]))
	print(ans1, ans2)


t = int(input())
for _ in range(t):
	n = int(input())
	res = [0, 0]
	for i in range(n):
		arr = list(map(int, input().split()))
		days = arr[1] * arr[2] / (arr[1] + arr[2])
		res[0] += days * (arr[0] / arr[1])
		res[1] += days * (arr[0] / arr[2])
	print(res[0], res[1])


t = int(input())
while t:
	n = int(input())
	chef = 0
	chefu = 0
	for i in range(n):
		(g, c1, c2) = map(int, input().split())
		chef += float(c2 / (c1 + c2) * g)
		chefu += float(c1 / (c1 + c2) * g)
	print('{0:4f}'.format(chef), '{0:4f}'.format(chefu))
	t -= 1


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	p = n
	f1 = 0
	f2 = 0
	while p > 0:
		p = p - 1
		(g, a, b) = map(int, input().split())
		f1 = f1 + g * b / (a + b)
		f2 = f2 + g * a / (a + b)
	print(f1, end=' ')
	print(f2)


try:
	for _ in range(int(input())):
		n = int(input())
		x = y = 0
		while n:
			(m, a, b) = map(int, input().split())
			x = x + a * m / (a + b)
			y = y + b * m / (a + b)
			n = n - 1
		x = '{0:.5f}'.format(x)
		y = '{0:.5f}'.format(y)
		print(y, x)
except Exception as e:
	pass


for _ in range(int(input())):
	n = int(input())
	(agold, bgold) = (0, 0)
	for _ in range(n):
		(g, a, b) = map(int, input().split())
		agold += b * (g / (a + b))
		bgold += a * (g / (a + b))
	print(round(agold, 7), round(bgold, 7))