A tea manufacturer decided to conduct a massive tea tasting. $n$ sorts of tea will be tasted by $n$ tasters. Both the sorts of tea and the tasters are numbered from $1$ to $n$. The manufacturer prepared $a_i$ milliliters of the $i$-th sort of tea. The $j$-th taster can drink $b_j$ milliliters of tea at once.

The tasting will be conducted in steps. During the first step, the $i$-th taster tastes the $i$-th sort of tea. The $i$-th taster drinks $\min(a_i, b_i)$ tea (how much is available of the $i$-th sort and how much the $i$-th taster can drink). $a_i$ also decreases by this amount.

Then all tasters move to the previous sort of tea. Thus, during the second step, the $i$-th taster tastes the $(i-1)$-st sort of tea. The $i$-th taster drinks $\min(a_{i-1}, b_i)$ tea. The $1$-st person ends the tasting.

During the third step, the $i$-th taster tastes the $(i-2)$-nd sort of tea. The $2$-nd taster ends the tasting. This goes on until everyone ends the tasting.

Take a look at the tasting process for $n = 3$, $a = [10, 20, 15]$, $b = [9, 8, 6]$. In the left row, there are the current amounts of each sort of tea. In the right column, there are current amounts of tea each taster has drunk in total. The arrow tells which taster each tea goes to on the current step. The number on the arrow is the amount — minimum of how much is available of the sort of tea and how much the taster can drink.

For each taster, print how many milliliters of tea he/she will drink in total.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.

The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of sorts of tea and the number of tasters.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the amount of each sort of tea.

The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$) — the amount of tea each taster can drink at once.

The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each testcase, print $n$ integers — the $i$-th value should be equal to the total amount of tea the $i$-th taster will drink.


-----Examples-----

Input
4
3
10 20 15
9 8 6
1
5
7
4
13 8 5 4
3 4 2 1
3
1000000000 1000000000 1000000000
1 1 1000000000
Output
9 9 12 
5 
3 8 6 4 
1 2 2999999997


-----Note-----

The first testcase is described in the statement. Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk:

$a = [1, 12, 9]$, $\mathit{ans} = [9, 8, 6]$

$a = [0, 6, 9]$, $\mathit{ans} = [9, 9, 12]$

$a = [0, 6, 9]$, $\mathit{ans} = [9, 9, 12]$

In the second testcase, the only taster drinks $\min(5, 7)$ milliliters of tea of the only sort.

Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk for the third testcase:

$a = [10, 4, 3, 3]$, $\mathit{ans} = [3, 4, 2, 1]$;

$a = [6, 2, 2, 3]$, $\mathit{ans} = [3, 8, 4, 2]$;

$a = [4, 1, 2, 3]$, $\mathit{ans} = [3, 8, 6, 3]$;

$a = [3, 1, 2, 3]$, $\mathit{ans} = [3, 8, 6, 4]$.

Here are the remaining amounts of each sort of tea after each step and the total amount of tea each taster has drunk for the fourth testcase:

$a = [999999999, 999999999, 0]$, $\mathit{ans} = [1, 1, 1000000000]$;

$a = [999999998, 0, 0]$, $\mathit{ans} = [1, 2, 1999999999]$;

$a = [0, 0, 0]$, $\mathit{ans} = [1, 2, 2999999997]$.

Difficulty: MEDIUM
Tags: Sorting

Data structures

Implementation
Skill types: Sorting

Data structures

Starter code:

Solutions:
from heapq import *
t = int(input())
for _ in range(t):
	N = int(input())
	tea = list(map(int, input().split()))
	tasters = list(map(int, input().split()))
	ret = []
	pre = []
	total = 0
	for i in range(N):
		count = 0
		while pre and pre[0] <= tasters[i] + total:
			count += heappop(pre) - total
		count += len(pre) * tasters[i]
		if tea[i] < tasters[i]:
			count += tea[i]
		else:
			count += tasters[i]
			heappush(pre, tea[i] + total)
		total += tasters[i]
		ret.append(count)
	print(*ret)


import sys
from bisect import bisect_left
from collections import defaultdict
from itertools import accumulate
DEBUG = False

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b_cum = [0] + list(accumulate(b))
	last_cup_count = [0] * (n + 1)
	final_drink = [0] * (n + 1)
	for idx in range(n):
		expert = bisect_left(b_cum, a[idx] + b_cum[idx]) - 1
		if expert >= idx:
			last_cup_count[expert] += 1
			final_drink[expert] += a[idx] - (b_cum[expert] - b_cum[idx])
	full_not_last_cups = [idx + 1 - empty for (idx, empty) in enumerate(accumulate(last_cup_count))]
	res = [full_not_last_cups[idx] * b[idx] + final_drink[idx] for idx in range(n)]
	return res
if DEBUG:
	sys.stdin = open('C-test.txt')
t = int(input())
ans = []
if DEBUG:
	with open('C-ans.txt') as f:
		for _ in range(t):
			ans.append(list(map(int, f.readline().strip().split())))
for idx in range(t):
	res = solution()
	print(*res)
	if DEBUG:
		assert res == ans[idx]


from bisect import bisect_left, bisect_right
from itertools import accumulate
import sys
input = lambda : sys.stdin.readline().strip()
mod = 7 + 10 ** 9

def solve():
	n = int(input())
	tea = [int(i) for i in input().split()]
	test = [int(i) for i in input().split()]
	dptot = [0] * (n + 2)
	rem = [0] * (n + 1)
	ans = [0] * (n + 1)
	dptest = [0] + list(accumulate(test))
	for i in range(n):
		idx = bisect_right(dptest, tea[i] + dptest[i]) - 1
		if idx > n + 1:
			idx -= 1
		dptot[i + 1] += 1
		dptot[idx + 1] -= 1
		if idx < n:
			rem[idx + 1] += tea[i] - (dptest[idx] - dptest[i])
	s = list(accumulate(dptot))
	for i in range(1, n + 1):
		ans[i - 1] = s[i] * test[i - 1] + rem[i]
	print(*ans[:-1])
for i in range(int(input())):
	solve()


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve1(a, b, n):
	ans = [0] * n
	for i in range(n):
		for d in range(n - i):
			j = i + d
			v = min(a[i], b[j])
			ans[j] += v
			a[i] -= v
	return ans

def solve(a, b, n):
	count = [0] * (n + 1)
	pre = [0] * (n + 1)
	for i in range(n):
		pre[i + 1] = pre[i] + b[i]
	subtract = [0] * (n + 1)
	for i in range(1, n + 1):
		if pre[n] - pre[i - 1] <= a[i - 1]:
			count[i - 1] += 1
			count[n] -= 1
		else:
			j = bisect.bisect_left(pre, pre[i - 1] + a[i - 1])
			count[i - 1] += 1
			count[j] -= 1
			subtract[j - 1] += pre[j] - pre[i - 1] - a[i - 1]
	for i in range(1, n):
		count[i] += count[i - 1]
	ans = [0] * n
	for i in range(n):
		ans[i] = count[i] * b[i] - subtract[i]
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = solve(a, b, n)
	print(' '.join(map(str, res)))


from bisect import bisect_left

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pre = [0] * (n + 1)
	for i in range(n):
		pre[i + 1] = pre[i] + b[i]
	diff = [0] * (n + 2)
	left = [0] * (n + 2)
	for i in range(1, n + 1):
		x = a[i - 1] + pre[i - 1]
		id = bisect_left(pre, x)
		left[id] += a[i - 1] - (pre[id - 1] - pre[i - 1])
		diff[i] += 1
		diff[id] -= 1
	for i in range(1, n + 1):
		diff[i] += diff[i - 1]
	ans = [0] * (n + 1)
	for i in range(1, n + 1):
		ans[i] = diff[i] * b[i - 1] + left[i]
	print(*ans[1:])
t = int(input())
for _ in range(t):
	solve()


from bisect import *
R = lambda : [*map(int, input().split())]
for _ in [0] * R()[0]:
	(n,) = R()
	m = n + 1
	a = R()
	b = R()
	c = [0]
	d = [0] * m
	e = [0] * m
	i = 0
	for x in b:
		c += (c[-1] + x,)
	for (x, y) in zip(a, c):
		x += y
		j = bisect(c, x) - 1
		d[i] += 1
		d[j] -= 1
		e[j] += x - c[j]
		i += 1
	for i in range(n):
		d[i + 1] += d[i]
	print(*(x * y + z for (x, y, z) in zip(b, d, e)))


def helper(a, b):
	from collections import Counter
	h = {i: 0 for i in range(len(b))}
	import bisect
	pref = []
	curr = 0
	for i in range(len(b)):
		curr += b[i]
		pref.append(curr)
	curr = 0
	lst = [0 for i in range(len(b) + 1)]
	og = a[:]
	for i in range(len(a)):
		a[i] += curr
		idx = bisect.bisect_right(pref, a[i])
		if 1 <= idx < len(pref) and a[i] - pref[idx - 1] >= 1 and (idx - 1 > i - 1):
			h[idx] += a[i] - pref[idx - 1]
		lst[i] += 1
		lst[idx] -= 1
		if i == idx:
			h[i] += og[i]
		curr += b[i]
	for i in range(1, len(lst)):
		if i < len(b):
			lst[i] += lst[i - 1]
		else:
			lst[i] += lst[i - 1]
	ans = []
	for i in range(len(lst) - 1):
		ans.append(b[i] * lst[i] + h[i])
	return ' '.join(list(map(str, ans)))
for i in range(int(input())):
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	print(helper(a, b))


import bisect
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum = [0] * (n + 1)
	for i in range(n):
		sum[i + 1] = sum[i] + b[i]
	cnt = [0] * (n + 1)
	add = [0] * (n + 1)
	for i in range(n):
		j = bisect.bisect_right(sum, a[i] + sum[i]) - 1
		cnt[i] += 1
		cnt[j] -= 1
		add[j] += a[i] - sum[j] + sum[i]
	cum_cnt = 0
	for i in range(n):
		cum_cnt += cnt[i]
		print(cum_cnt * b[i] + add[i], end=' ')
	print()


import bisect
t = int(input())
for _ in range(t):
	n = int(input())
	tea = list(map(int, input().split(' ')))
	tasters = list(map(int, input().split(' ')))
	diff = [0] * (n + 1)
	extra = [0] * (n + 1)
	psum = [0] * n
	psum[0] = tasters[0]
	prefixSumLt = 0
	prefixSumRt = 0
	for i in range(1, n):
		psum[i] = psum[i - 1] + tasters[i]
	for i in range(n):
		if i > 0:
			prefixSumLt = psum[i - 1]
		j = bisect.bisect_right(psum, tea[i] + prefixSumLt)
		if j > 0:
			prefixSumRt = psum[j - 1]
		diff[j] -= 1
		diff[i] += 1
		extra[j] += tea[i] - (prefixSumRt - prefixSumLt)
	for i in range(1, n):
		diff[i] += diff[i - 1]
	for i in range(0, n):
		print(extra[i] + diff[i] * tasters[i], end=' ')
	print()


from bisect import bisect_right
tc = int(input())
for case in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print(min(a[0], b[0]))
	else:
		pref = [0 for i in range(n)]
		pref[0] = b[0]
		for i in range(1, n):
			pref[i] = pref[i - 1] + b[i]
		ends = [0 for i in range(n)]
		resultados = [0 for i in range(n)]
		sumar = 0
		for i in range(n):
			pos = bisect_right(pref, a[i] + sumar)
			ends[i] = pos
			if pos < n and pos > 0:
				resultados[pos] += a[i] + sumar - pref[pos - 1]
			elif pos == 0:
				resultados[pos] += min(a[i], b[i])
			sumar = pref[i]
		part_sum = [0 for i in range(n + 1)]
		for i in range(n):
			part_sum[i] -= 1
			part_sum[ends[i]] += 1
		contador = part_sum[-1]
		for i in range(n - 1, -1, -1):
			resultados[i] += b[i] * contador
			contador += part_sum[i]
		print(*resultados)


import bisect
res = []
k = int(input())
while k > 0:
	cur_res = []
	_ = input()
	x = input().split(' ')
	tea = []
	for num in x:
		tea.append(int(num))
	x = input().split(' ')
	taster = []
	for num in x:
		taster.append(int(num))
	prefix = [0]
	segments = []
	inc = [0] * (len(taster) + 10)
	c = [0] * (len(taster) + 10)
	arr = [0] * (len(taster) + 10)
	for i in range(len(taster)):
		prefix.append(prefix[-1] + taster[i])
	for i in range(len(tea)):
		target = tea[i] + prefix[i]
		index = min(len(prefix) - 1, bisect.bisect_left(prefix, target, lo=i + 1))
		if target < prefix[index]:
			index -= 1
			if index < 0:
				c[i + 1] += tea[i]
				continue
		segments.append((i + 1, index))
		c[index + 1] += target - prefix[index]
	for (left, right) in segments:
		inc[left] += 1
		inc[right + 1] -= 1
	cur = 0
	for i in range(1, len(arr)):
		cur += inc[i]
		arr[i] += cur
	s = ''
	for i in range(1, len(taster) + 1):
		arr[i] = arr[i] * taster[i - 1] + c[i]
		s += str(arr[i])
		if i < len(taster):
			s += ' '
	res.append(s)
	k -= 1
for x in res:
	print(x)


import sys
input = sys.stdin.readline

def solve(n, a, b):
	pref = []
	cur = 0
	for x in b:
		cur += x
		pref.append(cur)
	pref.append(0)
	res = [0] * n
	diff = [0] * n
	for i in range(n):
		y = a[i] + pref[i - 1]
		(l, r) = (i, n - 1)
		temp = -1
		left = y - pref[i - 1]
		while l <= r:
			m = (l + r) // 2
			if pref[m] <= y:
				temp = m
				left = y - pref[m]
				l = m + 1
			else:
				r = m - 1
		if temp == -1:
			res[i] += left
		elif temp == n - 1:
			diff[i] += 1
		else:
			diff[i] += 1
			diff[temp + 1] -= 1
			res[temp + 1] += left
	cur = 0
	for i in range(n):
		cur += diff[i]
		res[i] += cur * b[i]
	print(*res)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, a, b)


import sys
input = sys.stdin.readline

def sol(n, a, b):
	b = b[::-1]
	a = a[::-1]
	pre = [0]
	res = [0] * n
	plus = [0] * (n + 2)
	for i in b:
		pre.append(pre[-1] + i)
	for i in range(n):
		l = 0
		r = i + 1
		while l <= r:
			mid = l + r >> 1
			if pre[i + 1] - pre[mid] <= a[i]:
				r = mid - 1
			else:
				l = mid + 1
		plus[i + 1] -= 1
		plus[l] += 1
		if l:
			res[l - 1] += a[i] - (pre[i + 1] - pre[l])
	pre2 = [0]
	for i in plus:
		pre2.append(pre2[-1] + i)
	for i in range(n):
		res[i] += b[i] * pre2[i + 1]
	for i in res[::-1]:
		print(i, end=' ')
	print()
t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sol(n, a, b)


class solution(object):

	def solve(n):
		a = input().split()
		for i in range(n):
			a[i] = int(a[i])
		b = input().split()
		for i in range(n):
			b[i] = int(b[i])
		Sum = [b[i] for i in range(n)]
		for i in range(1, n):
			Sum[i] = Sum[i - 1] + b[i]
		ans = [0] * n
		tag = [0] * n
		lpos = 0
		rpos = 0
		mid = 0
		Base = 0
		res = 0
		for i in range(n):
			lpos = i
			rpos = n - 1
			mid = i
			res = 0
			pos = i - 1
			while lpos <= rpos:
				mid = (lpos + rpos) // 2
				if Sum[mid] - Base < a[i]:
					lpos = mid + 1
					pos = mid
				else:
					rpos = mid - 1
			if pos >= 0:
				res = a[i] - (Sum[pos] - Base)
			else:
				res = a[i]
			if pos < n - 1:
				ans[pos + 1] += res
				tag[pos + 1] += 1
			Base = Sum[i]
		nw = 0
		for i in range(n):
			nw += 1 - tag[i]
			ans[i] += nw * b[i]
		for i in range(n):
			print(ans[i], end=' ')
		print('')
		return
T = int(input())
for t in range(T):
	solution.solve(int(input()))