Recently n students from city S moved to city P to attend a programming camp.

They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.

i-th student comes to the end of the queue at the beginning of l_{i}-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of r_{i}-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. 

For each student determine the second he will use the teapot and get his tea (if he actually gets it).


-----Input-----

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000).

Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students.

Then n lines follow. Each line contains two integer l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.

It is guaranteed that for every $i \in [ 2 ; n ]$ condition l_{i} - 1 ≤ l_{i} holds.

The sum of n over all test cases doesn't exceed 1000.

Note that in hacks you have to set t = 1.


-----Output-----

For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.


-----Example-----
Input
2
2
1 3
1 4
3
1 5
1 1
2 3

Output
1 2 
1 0 2 



-----Note-----

The example contains 2 tests:

  During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.  During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	lims = [tuple((int(v) for v in input().split())) for _ in range(n)]
	ctime = 0
	ans = []
	for (l, r) in lims:
		if l >= ctime:
			ans.append(l)
			ctime = l + 1
		elif r < ctime:
			ans.append(0)
		else:
			ans.append(ctime)
			ctime += 1
	print(' '.join((str(v) for v in ans)))


import queue
q = queue.Queue()
t = int(input())
for i in range(t):
	n = int(input())
	time = 1
	for a in range(n):
		(l, r) = [int(k) for k in input().split()]
		if time < l:
			time = l
		if l <= time <= r:
			print(time, end=' ')
			time = time + 1
		else:
			print(0, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	time = 0
	ans = list()
	for i in range(n):
		(l, r) = map(int, input().split())
		time = max(time, l)
		if time <= r:
			ans.append(time)
			time += 1
		else:
			ans.append(0)
	print(' '.join(map(str, ans)))


t = int(input())
for i in range(t):
	n = int(input())
	curr = 1
	for j in range(n):
		(l, r) = map(int, input().split())
		if r >= curr:
			if l <= curr:
				print(curr, end=' ')
				curr += 1
			else:
				print(l, end=' ')
				curr = l + 1
		else:
			print(0, end=' ')
	print()


from collections import deque

def solve(X):
	waiting = deque()
	res = [None] * len(X)
	t = 0
	X.append((10000, 10000))
	for (i, (l, r)) in enumerate(X):
		while waiting and t < l:
			(j, b) = waiting.popleft()
			if t <= b:
				res[j] = t
				t += 1
			else:
				res[j] = 0
		waiting.append((i, r))
		t = l
	return res
T = int(input())
for _ in range(T):
	n = int(input())
	X = [tuple(map(int, input().split())) for _ in range(n)]
	res = solve(X)
	print(' '.join(map(str, res)))


for i in range(int(input())):
	n = int(input())
	students = sorted([list(map(int, input().split())) for j in range(n)], key=lambda x: x[0])
	secents = 0
	count = 0
	out = []
	for (l, r) in students:
		if l != secents:
			secents = l
			if count < l:
				count = l
		if r < count:
			out.append('0')
		else:
			out.append(str(count))
			count += 1
	print(' '.join(out))


for repeat in range(int(input())):
	studentsnum = int(input())
	res = ''
	laststudent = 0
	for i in range(studentsnum):
		inp = input().split(' ', 1)
		arrival = int(inp[0])
		departure = int(inp[1])
		if arrival > laststudent:
			laststudent = arrival
		if departure < laststudent:
			res = res + str(0) + ' '
		else:
			res = res + str(laststudent) + ' '
			laststudent = laststudent + 1
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	tm = 0
	ans = ''
	for j in range(n):
		(l, r) = map(int, input().split())
		if tm > r:
			ans += '0' + ' '
		else:
			if tm <= l:
				tm = l + 1
			else:
				tm += 1
			ans += str(tm - 1) + ' '
	print(ans)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	L = []
	R = []
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		L.append(l)
		R.append(r)
	time = [0 for _ in range(n)]
	flag = [0 for _ in range(n)]
	for i in range(1, max(R) + 1):
		for j in range(n):
			if L[j] == i:
				flag[j] = 1
		for j in range(n):
			if flag[j] == 1:
				flag[j] = 0
				time[j] = i
				break
		for j in range(n):
			if flag[j] == 1 and R[j] == i:
				flag[j] = 0
	ans.append(time)
for i in range(t):
	answer = list(map(str, ans[i]))
	print(' '.join(answer))


import queue
t = int(input())
for test in range(t):
	n = int(input())
	ql = queue.Queue()
	qr = queue.Queue()
	for i in range(n):
		(li, ri) = map(int, input().split())
		ql.put(li)
		qr.put(ri)
	time = 0
	resp = list()
	while ql.empty() is False:
		li = ql.get()
		ri = qr.get()
		if time < li:
			time = li
		if li <= time <= ri:
			print(time, end=' ')
			time = time + 1
		else:
			print(0, end=' ')
	print()


t = int(input())
for test in range(t):
	n = int(input())
	time = []
	ans = []
	for i in range(5001):
		time.append(0)
	for i in range(1000):
		ans.append(0)
	for i in range(n):
		buf = input().split()
		l = int(buf[0])
		r = int(buf[1])
		j = l
		while True:
			if j == r and time[j] == 0:
				time[j] = 1
				ans[i] = j
				break
			if j == r:
				break
			if time[j] == 0:
				time[j] = 1
				ans[i] = j
				break
			j += 1
	for i in range(n):
		print(ans[i], end=' ')
	print('')


for _ in range(int(input().strip())):
	n = int(input())
	t = 1
	l = []
	for __ in range(n):
		l.append(list(map(int, input().split())))
	i = 0
	ans = []
	t = 1
	while t <= 5002:
		if l[i][0] > t:
			t += 1
			continue
		if l[i][0] <= t and l[i][1] >= t:
			ans.append(t)
			t += 1
			i += 1
		else:
			ans.append(0)
			i += 1
		if i == n:
			break
	print(*ans)


from collections import defaultdict
import math
from sys import stdin
casenumber = int(stdin.readline())
mydict = defaultdict(list)
output = []
for i in range(casenumber):
	n_student = int(stdin.readline())
	outputlist = []
	l = []
	r = []
	for n in range(n_student):
		string1 = stdin.readline().strip().split()
		l_n = int(string1[0])
		r_n = int(string1[1])
		if l_n > len(l):
			for count in range(l_n - len(l)):
				l.append(0)
			l.append(r_n)
		else:
			l.append(r_n)
		if len(l) - 1 <= r_n:
			outputlist.append(len(l) - 1)
		else:
			outputlist.append(0)
			l.pop()
	output.append(outputlist)
for i in range(casenumber):
	for j in range(len(output[i])):
		print(output[i][j], end=' ')
	print('')


import math
t = int(input())
for i in range(t):
	n = int(input())
	array = []
	for i in range(n):
		(l, r) = [int(s) for s in input().split()]
		array.append((l, r))
	print(array[0][0], end=' ')
	add = 0
	pred = array[0][0]
	for i in range(1, len(array)):
		if pred + 1 <= array[i][1]:
			if pred + 1 > array[i][0]:
				print(pred + 1, end=' ')
				pred += 1
			else:
				print(array[i][0], end=' ')
				pred = array[i][0]
		else:
			print(0, end=' ')
	print()


t = int(input())
while t:
	n = int(input())
	arr = []
	out = []
	while n:
		arr.append([int(i) for i in input().split()])
		n -= 1
	queue = []
	time = 1
	while len(arr) or len(queue):
		for (index, i) in enumerate(arr):
			if i[0] == time:
				queue.append(i)
				arr[index] = [0, 0]
		for (i, j) in enumerate(arr):
			if j == [0, 0]:
				arr.pop(i)
		try:
			if queue[0][1] < time:
				out.append(0)
			else:
				out.append(time)
				time += 1
			queue.pop(0)
		except:
			time += 1
	for i in out:
		print(i, end=' ')
	print()
	t -= 1


n = int(input())
for i in range(0, n):
	students = int(input())
	tab = [0] * students
	k = 0
	for j in range(1, students + 1):
		inn = input().split()
		innInt = [int(x) for x in inn]
		if k <= innInt[1]:
			if k < innInt[0]:
				k = innInt[0]
			tab[j - 1] = str(k)
			k = k + 1
		else:
			tab[j - 1] = '0'
	for pff in range(0, len(tab) - 1):
		print(tab[pff], end=' ')
	print(tab[-1])


t = int(input())
r = []
l = []
for i in range(t):
	n = int(input())
	for j in range(n):
		(lcurr, rcurr) = map(int, input().split())
		if j == 0:
			t = lcurr + 1
			print(t - 1, end=' ')
		elif t > lcurr:
			if rcurr >= t:
				t += 1
				print(t - 1, end=' ')
			else:
				print(0, end=' ')
		else:
			t = lcurr + 1
			print(t - 1, end=' ')
	print()


for t in range(int(input())):
	(c, v) = (0, [])
	for i in range(int(input())):
		(l, r) = map(int, input().split())
		if c > r:
			v.append(0)
		else:
			c = max(c, l) + 1
			v.append(c - 1)
	print(' '.join(map(str, v)))


import sys
cases = int(sys.stdin.readline())
for x in range(0, cases):
	people = int(sys.stdin.readline())
	times = []
	for i in range(0, people):
		cur = [int(x) for x in sys.stdin.readline().strip().split(' ')]
		times.append(cur)
	time = 1
	to_print = []
	for t in times:
		if time < t[0]:
			time = t[0]
		if time > t[1]:
			to_print.append('0')
		else:
			to_print.append(str(time))
			time += 1
	print(' '.join(to_print))


def getinput():
	return [int(x) for x in input().strip().split()]
t = int(input())
for t1 in range(t):
	n = int(input())
	interval = []
	for i in range(n):
		temp = getinput()
		interval.append(temp)
	time = 1
	for i in range(n):
		if time > interval[i][1]:
			print(0, end=' ')
		elif time < interval[i][0]:
			print(interval[i][0], end=' ')
			time = interval[i][0] + 1
		else:
			print(time, end=' ')
			time += 1
	print()


t = int(input())
ans1 = []
for i in range(t):
	n = int(input())
	st = []
	for i in range(n):
		(l, r) = map(int, input().split())
		st.append((l, r, i))
	st = sorted(st, key=lambda x: (x[0], x[2]))
	ans = []
	f = -1
	for s in st:
		if s[1] < f:
			ans.append(0)
		else:
			ans.append(max(f, s[0]))
			f = ans[-1] + 1
	ans1.append(ans)
for ans2 in ans1:
	print(' '.join([str(i) for i in ans2]))


t = int(input())
for i in range(t):
	n = int(input())
	students = []
	for i in range(n):
		students.append(list(map(int, input().split())))
	time = 0
	ans = []
	for i in students:
		l = i[0]
		r = i[1]
		if r < time:
			ans.append(0)
			continue
		else:
			ans.append(max(time, l))
			time = max(time + 1, l + 1)
	print(*ans)


import sys, math, os.path
FILE_INPUT = 'b.in'
DEBUG = os.path.isfile(FILE_INPUT)
if DEBUG:
	sys.stdin = open(FILE_INPUT)

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

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

def log(x):
	if DEBUG:
		print(x)
(t,) = ni()
for _ in range(0, t):
	(n,) = ni()
	queue = []
	tea = [0] * n
	cur = 0
	for i in range(0, n):
		(li, ri) = ni()
		queue.append([i, li, ri])
		while cur <= li and len(queue) > 0:
			(ii, ll, rr) = queue.pop(0)
			if cur < ll:
				cur = ll
			if cur <= rr:
				tea[ii] = cur
				cur += 1
	for [ii, ll, rr] in queue:
		if cur <= rr:
			tea[ii] = cur
			cur += 1
	print(' '.join(map(str, tea)))


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		(x, y) = map(int, input().split())
		l.append((x, y))
	start = 0
	ans = []
	for (st, ed) in l:
		if start + 1 <= ed:
			ans.append(max(start + 1, st))
			start = max(st, start + 1)
		else:
			ans.append(0)
	print(*ans)


t = int(input())
output = []
for test in range(t):
	n = int(input())
	students = []
	for _ in range(n):
		students.append([int(_) for _ in input().split()])
	time = 1
	output.append([])
	for (l, r) in students:
		time = max(time, l)
		if time <= r:
			output[test].append(str(time))
			time += 1
		else:
			output[test].append('0')
for test_output in output:
	print(' '.join(test_output))


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

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

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = []
	ch = 1
	curr = 0
	while n:
		n -= 1
		(l, r) = map(int, input().split())
		if ch:
			curr = l
			ch = 0
			ans.append(curr)
		elif curr + 1 == r:
			ans.append(r)
			curr += 1
		elif curr + 1 > r:
			ans.append(0)
		elif curr + 1 <= l:
			curr = l
			ans.append(curr)
		elif l == r:
			ans.append(l)
			curr += 1
		else:
			ans.append(curr + 1)
			curr += 1
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [None] * n
	sec = a[0] = int(input().split()[0])
	for j in range(1, n):
		(l, r) = map(int, input().split())
		if sec < r:
			a[j] = sec = max(sec + 1, l)
		else:
			a[j] = 0
	print(' '.join(list(map(str, a))))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ss = []
		for i in range(n):
			(l, r) = [int(x) for x in input().split()]
			ss.append((l, i, r))
		ttt = []
		cc = 0
		for t in ss:
			if t[0] >= cc:
				ttt.append(t[0])
				cc = t[0] + 1
			elif cc > t[2]:
				ttt.append(0)
			else:
				ttt.append(cc)
				cc += 1
		print(' '.join((str(x) for x in ttt)))

def __starting_point():
	main()
__starting_point()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	c = 0
	for j in range(n):
		(li, ri) = map(int, input().strip().split(' '))
		if j == 0:
			if li <= ri:
				l.append(li)
				c += li
			else:
				l.append(0)
				c = 0
		elif ri <= c:
			l.append(0)
		else:
			c = max(c + 1, li)
			l.append(c)
	for j in range(n):
		print(l[j], end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		a.append([l, r])
	b = 1
	c = []
	i = 0
	while i < n:
		if a[i][0] <= b and b <= a[i][1]:
			c.append(b)
			b = b + 1
			i = i + 1
		elif a[i][0] <= b:
			c.append(0)
			i = i + 1
		else:
			b = b + 1
	print(*c)


for _ in range(int(input())):
	n = int(input())
	queue = []
	for i in range(n):
		(l, r) = map(int, input().split())
		queue.append([l, r])
	ans = []
	curr = 0
	for i in range(n):
		if curr <= queue[i][1]:
			ans.append(max(queue[i][0], curr))
			curr = max(queue[i][0], curr) + 1
		else:
			ans.append(0)
	print(*ans)


from sys import stdin, stdout
from collections import deque
t = int(stdin.readline())
queue = deque()
for i in range(t):
	n = int(stdin.readline())
	challengers = []
	for i in range(n):
		(l, r) = map(int, stdin.readline().split())
		challengers.append((l, r))
	time = 1
	for v in challengers:
		(l, r) = v
		queue.append((l, r))
		time = max(time, queue[0][0])
		while queue[0][0] < l:
			time = max(time, queue[0][0])
			if time > queue[0][1]:
				stdout.write('0 ')
				queue.popleft()
			else:
				stdout.write(str(time) + ' ')
				time += 1
				queue.popleft()
	while queue:
		time = max(time, queue[0][0])
		if time > queue[0][1]:
			stdout.write('0 ')
			queue.popleft()
		else:
			stdout.write(str(time) + ' ')
			time += 1
			queue.popleft()
	stdout.write('\n')


from collections import deque
t = int(input())

def solve():
	n = int(input())
	ans = [0] * n
	i = 0
	currentTime = 0
	while i < n:
		lr = input().split(' ')
		li = int(lr[0])
		ri = int(lr[1])
		if currentTime < li:
			currentTime = li
		if currentTime == li:
			ans[i] = currentTime
			currentTime += 1
		elif currentTime <= ri:
			ans[i] = currentTime
			currentTime += 1
		i += 1
	print(' '.join((str(ai) for ai in ans)))
count = 0
while count < t:
	solve()
	count += 1


t = int(input())
for _ in range(t):
	n = int(input())
	last = 0
	ans = []
	for i in range(n):
		(start, end) = map(int, input().split())
		if last < end:
			last = max(last + 1, start)
			ans.append(last)
		else:
			ans.append(0)
	print(*ans)


t = int(input())
for i in range(t):
	people = []
	q = []
	x = 0
	s = ''
	n = int(input())
	ans = [None] * n
	for j in range(n):
		aux = input().split()
		l = int(aux[0])
		r = int(aux[1])
		people.append((j, l, r))
	time = 0
	for k in range(0, n, 1):
		time = max(time + 1, people[k][1])
		if people[k][1] <= time:
			q.append((people[k][0], people[k][2]))
		if q:
			if q[0][1] < time:
				ans[q[0][0]] = 0
				time -= 1
			else:
				ans[q[0][0]] = time
			q.remove(q[0])
	for a in ans:
		s += str(a) + ' '
	print(s)


from collections import deque
for i in range(int(input())):
	n = int(input())
	q = deque()
	for i in range(n):
		q.append(tuple((int(x) for x in input().split())))
	time = 1
	ans = []
	while len(q) != 0:
		it = q.popleft()
		if time <= it[1]:
			if time < it[0]:
				time = it[0]
			ans.append(time)
			time += 1
		else:
			ans.append(0)
	print(*ans)


n = int(input())
for i in range(n):
	m = int(input())
	c = 0
	for i in range(m):
		(a, b) = map(int, input().split(' '))
		c += 1
		if a <= c and b >= c:
			print(c)
		elif b < c:
			print(0)
			c -= 1
		elif a > c:
			c = a
			print(c)


T = int(input())
for _ in range(T):
	n = int(input())
	stu = [(0, 0)] * n
	for z in range(n):
		stu[z] = tuple(map(int, input().split(' ')))
	stu.sort(key=lambda x: x[0])
	time = 1
	result = [0] * n
	for i in range(n):
		(a, b) = stu[i]
		if a > time:
			time = a
		if b >= time:
			result[i] = time
			time += 1
	for i in result:
		print(i, end=' ')


t = int(input())
while t:
	t -= 1
	n = int(input())
	wait = []
	time = 1
	leave = []
	for i in range(n):
		(a, b) = input().split(' ')
		wait.append((int(a), int(b)))
	for i in wait:
		if i[1] < time:
			leave.append(0)
		elif i[0] <= time:
			leave.append(time)
			time += 1
		else:
			leave.append(i[0])
			time = i[0] + 1
	for i in leave:
		print(i, end=' ')
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	a = [[int(i) for i in input().split()] for j in range(n)]
	curr = 0
	time = 1
	for i in range(n):
		if a[i][1] >= time:
			print(max(time, a[i][0]), end=' ')
			time = max(time, a[i][0])
			time += 1
		else:
			print(0, end=' ')
	print()


for j in range(int(input())):
	timeLastPour = 0
	result = []
	for i in range(int(input())):
		(l, r) = [int(f) for f in input().split(' ') if f]
		if timeLastPour <= r:
			timeLastPour = max(timeLastPour, l)
			result.append(timeLastPour)
			timeLastPour += 1
		else:
			result.append(0)
	print(*result)


t = int(input())
for rep in range(t):
	n = int(input())
	s = 1
	for i in range(n):
		(l, r) = map(int, input().split())
		if s < l:
			s = l
		if s >= l and s <= r:
			print(s, end=' ')
			s += 1
		else:
			print('0', end=' ')
	print('')


tb = int(input())
for i in range(tb):
	n = int(input())
	(l, r) = map(int, input().split())
	arr = [l]
	t = l + 1
	for j in range(n - 1):
		(l, r) = map(int, input().split())
		if t <= r:
			if t >= l:
				t += 1
			else:
				t = l + 1
			arr.append(t - 1)
		else:
			arr.append(0)
	print(*arr)


t = int(input())
for test_index in range(t):
	n = int(input())
	list_of_students = []
	for i in range(n):
		(l, r) = map(int, input().split())
		list_of_students.append((i, l, r))
	sorted_list = sorted(list_of_students, key=lambda x: (x[1], x[0]), reverse=True)
	current_time = 1
	answer = [0 for i in range(n)]
	while len(sorted_list) > 0:
		current_customer = sorted_list.pop()
		if current_time < current_customer[1]:
			current_time = current_customer[1]
		if current_time > current_customer[2]:
			continue
		answer[current_customer[0]] = current_time
		current_time += 1
	for x in answer:
		print(x, end=' ')
	print()


for wjioadnasmcxoamowaijoawnwaod in range(int(input())):
	n = int(input())
	res = [0] * n
	l = [0] * n
	r = [0] * n
	for i in range(n):
		(l[i], r[i]) = [int(x) for x in input().split()]
	t = l[0] + 1
	res[0] = l[0]
	g = 1
	while g < n:
		if t < l[g]:
			t += 1
		elif r[g] < t:
			res[g] = 0
			g += 1
		else:
			res[g] = t
			g += 1
			t += 1
	for e in res:
		print(e, end=' ')
	print()


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
t = int(input())
for _ in range(t):
	n = int(input())
	(lb, rb) = (0, 0)
	ct = 0
	ans = []
	for __ in range(n):
		(lc, rc) = rint()
		if lc >= ct:
			ans.append(lc)
			ct = lc + 1
		elif ct <= rc:
			ans.append(ct)
			ct += 1
		else:
			ans.append(0)
	print(*ans)


t = int(input())
from time import time
start_time = time()
for tt in range(t):
	n = int(input())
	stud = []
	for nn in range(n):
		s = tuple(map(lambda x: int(x), input().split()))
		stud.append(s)
	res = 0
	for i in range(n):
		(l, r) = stud[i]
		if i == 0:
			res = l + 1
			print(l, end=' ')
			continue
		newres = max(l, res)
		if newres > r:
			res = newres
			print(0, end=' ')
		else:
			print(newres, end=' ')
			res = newres + 1
	print()


a = int(input())
x = []
for i in range(a):
	n = int(input())
	z = []
	y = []
	for j in range(n):
		(l, k) = map(int, input().split())
		y = [l, k]
		z.append(y)
	x.append(z)
v = []
for i in range(a):
	t = 0
	b = x[i]
	w = []
	for j in b:
		if t <= j[0]:
			t = j[0] + 1
			w.append(j[0])
		elif j[0] < t <= j[1]:
			w.append(t)
			t = t + 1
		else:
			w.append(0)
	v.append(w)
for i in v:
	e = ''
	for j in i:
		d = str(j)
		e = e + d + ' '
	print(e)


test = int(input())
while test > 0:
	n = int(input())
	student = [list(map(int, input().split())) for _ in range(n)]
	time = 1
	t = [0] * n
	for i in range(n):
		(start, end) = student[i]
		if time < start:
			time = start
		if time > end:
			t[i] = '0'
		else:
			t[i] = str(time)
			time += 1
	print(' '.join(t))
	test -= 1


for _ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(n):
		(x, y) = map(int, input().split())
		ar.append([x, i, y])
	ar.sort()
	ans = [0 for i in range(n)]
	cur = 1
	for i in range(n):
		cur = max(cur, ar[i][0])
		if cur <= ar[i][2]:
			ans[ar[i][1]] = cur
			cur += 1
		else:
			ans[ar[i][1]] = 0
	print(*ans)


import heapq
queries = int(input())
for _ in range(queries):
	(student, results) = ([], [])
	time = 0
	index = 0
	number = int(input())
	for _ in range(number):
		(b, e) = map(int, input().split())
		student.append([b, index, e])
		index += 1
	heapq.heapify(student)
	time = student[0][0]
	heapq.heappop(student)
	results.append(time)
	while student:
		if student[0][0] > time:
			time = student[0][0]
			results.append(time)
			heapq.heappop(student)
		elif student[0][2] - time > 0:
			time += 1
			results.append(time)
			heapq.heappop(student)
		else:
			results.append(0)
			heapq.heappop(student)
	print(' '.join(map(str, results)))


t = int(input())
for i in range(t):
	n = int(input())
	ans = [0] * n
	(l, r) = list(map(int, input().split()))
	ans[0] = l
	sec = l + 1
	for i in range(1, n):
		(l, r) = list(map(int, input().split()))
		if l > sec:
			sec = l
		if r >= sec:
			ans[i] = sec
			sec += 1
		else:
			ans[i] = 0
	for i in range(n):
		print(ans[i], end=' ')


import queue
t = int(input())
for i in range(t):
	n = int(input())
	q = queue.Queue()
	time = 1
	for j in range(n):
		(li, ri) = [int(k) for k in input().split()]
		while time < li and q.qsize():
			r = q.get()
			while r > time and q.qsize():
				print(0, end=' ')
				r = q.get()
			if r > time:
				print(time, end=' ')
				time += 1
		if q.qsize():
			q.put(ri)
		elif ri < time:
			print(0, end=' ')
		else:
			time = max(li, time)
			print(time, end=' ')
			time += 1
	print()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	r = []
	for i in range(n):
		(l1, r1) = map(int, input().split())
		l.append(l1)
		r.append(r1)
	temp = 1
	m = max(r)
	for j in range(n):
		if temp > r[j]:
			print(0, end=' ')
		elif temp <= l[j]:
			print(l[j], end=' ')
			temp = l[j] + 1
		else:
			print(temp, end=' ')
			temp += 1
	print()


t = int(input())
f = 0
for o in range(0, t):
	q = int(input())
	s = []
	for oo in range(0, q):
		(l, r) = map(int, input().split())
		if f >= r:
			s.append(0)
		else:
			f = max([f + 1, l])
			s.append(f)
	f = 0
	for i in s:
		print(i, end=' ')


t = int(input())
while t > 0:
	n = int(input())
	(l, r) = map(int, input().split())
	a = []
	a.append(l)
	tmp = l + 1
	for i in range(1, n):
		(l, r) = map(int, input().split())
		if r < tmp:
			a.append(0)
		else:
			s = max(tmp, l)
			a.append(s)
			tmp = s + 1
	for i in range(n):
		print(a[i], end=' ')
	print()
	t -= 1


tc = int(input())
for tid in range(tc):
	n = int(input())
	a = []
	for i in range(n):
		a.append(tuple(map(int, input().split())))
	b = []
	p = 0
	for t in range(1, int(5000.0 + 1)):
		while p < n and a[p][1] < t:
			b.append(0)
			p += 1
		if p == n:
			break
		if a[p][0] > t:
			continue
		b.append(t)
		p += 1
	print(' '.join(map(str, b)))


t = int(input())
for y in range(t):
	n = int(input())
	data = []
	tim = 1
	ans = []
	for st in range(n):
		(l, r) = [int(x) for x in input().split()]
		if tim <= l:
			tim = l
			ans.append(tim)
			tim += 1
			continue
		if tim <= r:
			ans.append(tim)
		else:
			ans.append(0)
			continue
		tim += 1
	print(*ans)


import sys
import os
import math
import re
t = int(input())
for _ in range(t):
	n = int(input())
	stud = []
	for _ in range(n):
		(l, r) = map(int, input().split())
		stud.append((l, r))
	stud.sort(key=lambda x: x[0])
	seconds = 1
	q = []
	while len(stud) > 0:
		[q.append(kid) for kid in stud if kid[0] == seconds]
		if len(q) > 0:
			s = q[0]
			while s[1] < seconds and len(q) > 0 and (len(stud) > 0):
				print('0 ', end='')
				del q[0]
				del stud[0]
				if len(stud) <= 0 or len(q) <= 0:
					break
				s = q[0]
			if len(q) > 0 and len(stud) > 0:
				if q[0][0] <= seconds:
					print(str(seconds) + ' ', end='')
					del q[0]
					del stud[0]
		seconds += 1
	print('')


def solve(students):
	k = 1
	for s in students:
		if s[1] < k:
			print(0, end=' ')
		else:
			print(max(s[0], k), end=' ')
			if k < s[0]:
				k = s[0] + 1
			else:
				k += 1
	print()
tests = int(input())
while tests:
	tests -= 1
	n = int(input())
	st = []
	for _ in range(n):
		st.append(list(map(int, input().split())))
	solve(st)


t = int(input())
bo = []
for i in range(t):
	n = int(input())
	mr = 0
	b = [-2] * n
	l = []
	r = []
	for j in range(n):
		(x, y) = map(int, input().split())
		if y > mr:
			mr = y
		l.append(x)
		r.append(y)
	j = 1
	k = 0
	h = 0
	while j <= mr:
		if k < n and l[k] == j:
			b[k] = -1
			k += 1
			continue
		for o in range(n):
			if b[o] == -1:
				b[o] = j
				break
		for o in range(n):
			if r[o] == j and b[o] == -1:
				b[o] = 0
		j += 1
	bo.append(b)
for i in range(t):
	print(' '.join(map(str, bo[i])))


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	b = []
	for j in range(n):
		(c, d) = map(int, input().split())
		a.append(c)
		b.append(d)
	time = 0
	for j in range(n):
		time = max(time, a[j])
		if a[j] <= time <= b[j]:
			print(time, end=' ')
			try:
				time = max(time + 1, a[j + 1])
			except:
				continue
		else:
			print(0, end=' ')
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	t = 0
	for j in range(n):
		(a, b) = [int(x) for x in input().split()]
		if a > t:
			t = a
			print(t, end=' ')
		elif a <= t < b:
			t += 1
			print(t, end=' ')
		else:
			print(0, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	(a, ans) = ([], [])
	for j in range(n):
		x = list(map(int, input().split()))
		a.append(x)
	cur_sec = a[0][0]
	for p in range(n):
		if a[p][0] <= cur_sec <= a[p][1]:
			ans.append(cur_sec)
			cur_sec += 1
		elif a[p][0] >= cur_sec:
			ans.append(a[p][0])
			cur_sec = a[p][0] + 1
		else:
			ans.append(0)
	print(*ans)


import collections
a = int(input())
for x in range(a):
	b = int(input())
	s = {}
	d = {}
	j = 9999999999999
	n = 0
	h = [0 for y in range(b)]
	for y in range(b):
		(e, f) = map(int, input().split())
		j = min(j, e)
		if d.get(e) == None:
			d[e] = [f]
		else:
			d[e].append(f)
		if s.get(e) == None:
			s[e] = [n]
		else:
			s[e].append(n)
		n += 1
	od = collections.OrderedDict(sorted(d.items()))
	odm = collections.OrderedDict(sorted(s.items()))
	for y in odm:
		ll = 0
		j = max(j, y)
		for z in od[y]:
			if z >= j:
				h[odm[y][ll]] = j
				j += 1
			ll += 1
	print(*h)


n = int(input())
t = 0
for x in range(n):
	p = int(input())
	ol = []
	sl = []
	na = []
	ki = []
	pi = []
	t = 0
	for y in range(p):
		(v, c) = list(map(int, input().split()))
		ol.append(v)
		sl.append(c)
	for z in range(p):
		sam = min(ol)
		kp = ol.index(sam)
		pi.append(kp)
		if t < min(ol):
			t = min(ol) + 1
			ki.append(min(ol))
			ol[kp] = 5555555
		elif t == min(ol):
			t += 1
			ki.append(min(ol))
			ol[kp] = 55555555
		elif sl[kp] >= t:
			ki.append(t)
			t += 1
			ol[kp] = 555555555
		else:
			ki.append(0)
			ol[kp] = 55555555
	for r in range(0, p):
		oll = pi.index(r)
		na.append(ki[oll])
	print(*na)


t = int(input())
for x in range(t):
	n = int(input())
	lst = []
	d = {}
	for y in range(n):
		(l, r) = map(int, input().split())
		lst.append((l, r))
	p = 0
	for (l, r) in lst:
		if p + 1 > r:
			print(0, end=' ')
		else:
			print(max(p + 1, l), end=' ')
			p = max(p + 1, l)
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [[int(i) for i in input().split()] + [i] for i in range(n)]
	timearr = [0 for i in range(n)]
	checked = 0
	currtime = 1
	arr.sort(key=lambda a: a[0])
	while checked < n:
		if arr[checked][0] > currtime:
			currtime += 1
		elif arr[checked][1] < currtime:
			checked += 1
		else:
			timearr[arr[checked][2]] = currtime
			currtime += 1
			checked += 1
	print(' '.join((str(i) for i in timearr)))


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		(l, r) = map(int, input().split())
		a.append((l, i, r))
	a.sort()
	Q = queue.Queue()
	for ai in a:
		Q.put(ai)
	ans = [0 for i in range(n)]
	t = 1
	while not Q.empty():
		(l, i, r) = Q.get()
		if t <= r:
			ans[i] = max(l, t)
			t = max(l, t) + 1
		else:
			continue
	print(*ans)


import queue
t = int(input())
for i in range(t):
	n = int(input())
	q = queue.Queue()
	answer = []
	current_sec = 1
	for j in range(n):
		s = input().split(' ')
		l = int(s[0])
		r = int(s[1])
		while l > current_sec:
			if not q.empty():
				time = q.get()
				if time >= current_sec:
					answer.append(str(current_sec))
					current_sec += 1
				else:
					answer.append('0')
			else:
				current_sec = l
		if l == current_sec:
			q.put(r)
	while not q.empty():
		time = q.get()
		if time >= current_sec:
			answer.append(str(current_sec))
			current_sec += 1
		else:
			answer.append('0')
	res = ' '.join(answer)
	print(res)


for _ in ' ' * int(input()):
	s = 0
	for _ in ' ' * int(input()):
		(a, b) = map(int, input().split())
		if s > b:
			print(0, end=' ')
		else:
			s = a + 1 if s <= a else s + 1
			print(s - 1, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	l = [[] for _ in range(5001)]
	r = [[] for _ in range(5001)]
	a = [-1 for _ in range(n)]
	for i in range(n):
		(l0, r0) = input().split()
		l[int(l0)].append(i)
		r[int(r0)].append(i)
	q = []
	for (e, (l, r)) in enumerate(zip(l, r)):
		for h in sorted(l):
			q.insert(0, h)
		if q:
			ch = q.pop()
			a[ch] = e
		for h in r:
			if h in q:
				q.remove(h)
				a[h] = 0
	print(*a)


def solve():
	n = int(input())
	q = []
	for i in range(n):
		(l, r) = [int(x) for x in input().split(' ')]
		q.append((l, i, r))
	q.sort(reverse=True)
	u = 0
	s_time = {}
	while q:
		x = q.pop()
		if x[2] <= u:
			s_time[x[1]] = 0
		else:
			u = max(x[0], u + 1)
			s_time[x[1]] = u
	s_times = [s_time[i] for i in range(n)]
	return s_times
t = int(input())
for case in range(t):
	print(*solve())


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from sys import stdout
print = stdout.write
for _ in range(int(input())):
	ans = []
	t = 1
	for _ in range(int(input())):
		(l, r) = map(int, input().split())
		if l <= t:
			if r >= t:
				ans.append(str(t))
				t += 1
			else:
				ans.append('0')
		else:
			ans.append(str(l))
			t = l + 1
	print(' '.join(ans) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	tm = 1
	x = 0
	l1 = []
	while x < n:
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		if l > tm:
			tm = l
		elif tm > r:
			l1.append(0)
			x = x + 1
			continue
		l1.append(tm)
		tm = tm + 1
		x = x + 1
	c = 0
	while c < n:
		print(l1[c], end=' ')
		c = c + 1


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for i in range(n):
		s = input().split()
		a.append((int(s[0]), int(s[1])))
	e = 0
	q = []
	res = {}
	st = False
	tun = []
	for i in range(n):
		tun.append(-1)
	while q != tun:
		if q != []:
			for w in range(len(q)):
				if q[w] != -1:
					res.update({q[w]: e})
					q[w] = -1
					break
			for r in range(len(q)):
				if q[r] != -1:
					if a[r][1] == e:
						res.update({q[r]: 0})
						q[r] = -1
		e += 1
		for x in range(n):
			if a[x][0] == e:
				q.append(x)
	rest = ''
	for c in sorted(res.keys()):
		rest += str(res[c]) + ' '
	print(rest)


from collections import deque

def solve(ar):
	res = []
	time = 0
	for (l, r) in ar:
		if r >= time:
			if time == 0:
				time = l + 1
				res.append(l)
			else:
				if l >= time:
					time = l
				res.append(time)
				time += 1
		else:
			res.append(0)
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(deque((int(x) for x in input().split())))
	print(*solve(a))


t = int(input())
for _ in range(t):
	n = int(input())
	lst = [0] * n
	tmp = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l > tmp:
			lst[i] = l
			tmp = l + 1
		elif tmp <= r:
			lst[i] = tmp
			tmp += 1
	print(' '.join(map(str, lst)))


t = int(input())
while t:
	n = int(input())
	beg = [None] * n
	en = [None] * n
	for i in range(n):
		(beg[i], en[i]) = map(int, input().split())
	st = 1
	for i in range(n):
		if en[i] >= st:
			if beg[i] > st:
				print(beg[i], end=' ')
				st = beg[i]
			else:
				print('{}'.format(st), end=' ')
			st += 1
		else:
			print('0', end=' ')
	print('')
	t -= 1


from collections import deque

def main():
	n = int(input())
	intervals = []
	t = 1
	taken = [False] * 5003
	res = [0] * n
	for i in range(n):
		(l, r) = map(int, input().split())
		intervals.append((l, r))
		p = l
		while taken[p] and p < r:
			p += 1
		if not taken[p]:
			taken[p] = True
			res[i] = p
	print(' '.join(map(str, res)))
T = int(input())
for _ in range(T):
	main()


cin = input
t = int(cin())
while t > 0:
	n = int(cin())
	(a, cnt) = ([0] * n, 0)
	for i in range(n):
		(l, r) = map(int, cin().split())
		cnt += l - cnt if l > cnt else 1
		if r >= cnt:
			a[i] += cnt
		else:
			cnt -= 1
	print(*a)
	t -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	studs = [list(map(int, input().split())) for _ in range(n)]
	t = 0
	out = [0] * n
	cs = 0
	while len(studs) > 0:
		t += 1
		if studs[0][0] <= t and studs[0][1] >= t:
			out[cs] = t
			cs += 1
			studs.pop(0)
		elif studs[0][0] <= t:
			cs += 1
			studs.pop(0)
			t -= 1
	print(' '.join(map(str, out)))


import sys
for _ in range(int(sys.stdin.buffer.readline().decode('utf-8'))):
	n = int(sys.stdin.buffer.readline().decode('utf-8'))
	time = 1
	ans = [0] * n
	for (i, (l, r)) in enumerate((map(int, sys.stdin.buffer.readline().decode('utf-8').split()) for _ in range(n))):
		if time < l:
			time = l
		if time <= r:
			ans[i] = time
			time += 1
	print(*ans)


_ = int(input())
while _ > 0:
	A = []
	B = []
	n = int(input())
	for i in range(n):
		(p, q) = map(int, input().split())
		A.append([p, i, q])
	A = sorted(A)
	i = 0
	k = A[0][0]
	while i < len(A):
		k = max(k + 1, A[i][0]) if i > 0 else k
		while i < len(A) and max(k, A[i][0]) > A[i][2]:
			del A[i]
			B.append(0)
		if i < len(A):
			k = max(k, A[i][0])
			B.append(k)
		i += 1
	print(' '.join(map(str, B)))
	_ -= 1


for _ in range(int(input())):
	c = 0
	a = []
	for i in range(int(input())):
		(l, r) = map(int, input().split())
		if c > r:
			a += [0]
		else:
			c = l + 1 if c <= l else c + 1
			a += [c - 1]
	print(' '.join(map(str, a)))


t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	a = []
	for i in range(n):
		(l, r) = map(int, input().split())
		if s > r:
			a.append(0)
		elif s <= l:
			a.append(l)
			s = l + 1
		else:
			a.append(s)
			s += 1
	print(' '.join(map(str, a)))


t = int(input())
for i in range(t):
	n = int(input())
	L = []
	res = []
	for j in range(n):
		(l, r) = map(int, input().split())
		L.insert(0, (l, r))
	sec = L[-1][0]
	while len(L) != 0:
		tup = L.pop()
		if tup[0] <= sec:
			if tup[1] >= sec:
				res.append(sec)
				sec += 1
			else:
				res.append(0)
		else:
			sec = tup[0]
			res.append(sec)
			sec += 1
	print(*res)


reps = int(input())
for _ in range(reps):
	n = int(input())
	t = 1
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		if l > t:
			t = l
		if t <= r:
			print(t)
			t += 1
		else:
			print(0)


import collections

def solve():
	ans = []
	q = collections.deque()
	n = int(input())
	for i in range(n):
		(t1, t2) = map(int, input().split())
		q.append((t1, t2))
	t = max(0, q[0][0])
	while q:
		cur = q.popleft()
		if cur[1] < t:
			ans.append(0)
			if not q:
				continue
			t = max(t, q[0][0])
		else:
			ans.append(t)
			if not q:
				continue
			t = max(t + 1, q[0][0])
	return ans
t = int(input())
res = []
for i in range(t):
	res.append(solve())
for i in range(t):
	print(*res[i])


t = int(input())
for i in range(t):
	n = int(input())
	list_1 = []
	count = 1
	ans = ''
	for j in range(n):
		(l, r) = map(int, input().split(' '))
		if count > r:
			list_1.append(0)
		else:
			count = max(l, count)
			list_1.append(count)
			count += 1
	for k in list_1:
		ans += str(k) + ' '
	print(ans.rstrip(' '))


from queue import Queue
t = int(input())
for pp in range(t):
	n = int(input())
	(l, r) = (list(), list())
	for i in range(n):
		(x, y) = map(int, input().split())
		l.append(x)
		r.append(y)
	ans = [-1] * n
	t = 1
	i = 0
	q = Queue()
	while i < n or not q.empty():
		while i < n and l[i] <= t:
			q.put(i)
			i += 1
		f = True
		while f:
			if q.empty():
				f = False
			else:
				si = q.get()
				if t <= r[si]:
					f = False
					ans[si] = t
				else:
					ans[si] = 0
		t += 1
	print(' '.join(map(str, ans)))


import heapq

def tea_list(students):
	teatimes = [0] * len(students)
	events = []
	for (i, (a, l)) in enumerate(students):
		events.append((a, 0, (a, i, l)))
	heapq.heapify(events)
	queue_len = 0
	while events:
		(t, etype, e) = heapq.heappop(events)
		if etype == 0:
			(a, i, l) = e
			if a + queue_len <= l:
				heapq.heappush(events, (a + queue_len, 1, i))
				queue_len += 1
		elif etype == 1:
			queue_len -= 1
			teatimes[e] = t
	return teatimes

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		students = [tuple((int(x) for x in input().split())) for _ in range(N)]
		print(*tea_list(students))

def __starting_point():
	main()
__starting_point()


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

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

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	n = inp()
	data = []
	for i in range(n):
		(l, r) = inpl()
		data.append((l, r))
	res = [0] * n
	idx = 0
	q = deque()
	for t in range(1, 5010):
		while idx < n:
			if data[idx][0] <= t:
				q.append(idx)
				idx += 1
			else:
				break
		while q:
			i = q.popleft()
			if t <= data[i][1]:
				res[i] = t
				break
	print(*res)


for _ in range(int(input().strip())):
	n = int(input().strip())
	currTime = 0
	for i in range(n):
		(arrTime, wait) = map(int, input().split())
		if currTime < arrTime:
			time = arrTime
			currTime = arrTime + 1
		elif currTime <= wait:
			time = currTime
			currTime += 1
		else:
			time = 0
		print(time, end=' ')
	print()


t = int(input())
for i in range(0, t):
	n = int(input())
	(l, r) = map(int, input().split(' '))
	print(l)
	a = l
	for j in range(0, n - 1):
		(l, r) = map(int, input().split(' '))
		if r <= a:
			print(0)
		elif l <= a:
			print(a + 1)
			a += 1
		else:
			print(l)
			a = l


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	nowt = 1
	for i in range(n):
		(l, r) = map(int, input().split())
		if l > nowt:
			nowt = l
		if r >= nowt:
			print('%d ' % nowt, end='')
			nowt += 1
		else:
			print('0 ', end='')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	d = []
	for i in range(n):
		d.append(list(map(int, input().split())) + [i])
	d.sort(key=lambda x: x[1])
	d.sort(key=lambda x: x[2])
	d.sort(key=lambda x: x[0])
	res = [[d[0][0], d[0][2]]]
	c = d[0][0]
	i = 0
	while i < len(d):
		while i < len(d) and d[i][1] < c:
			res.append([0, d[i][2]])
			i += 1
		if i < len(d):
			c = max(c + 1, d[i][0] + 1)
			res.append([c - 1, d[i][2]])
		i += 1
	res.pop(0)
	res.sort(key=lambda x: x[1])
	z = [res[i][0] for i in range(len(res))]
	print(*z)


import collections
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	r = []
	for i in range(n):
		(ll, rr) = map(int, input().split())
		l.append(ll)
		r.append(rr)
	q = collections.deque()
	cur_t = 1
	cur_student = 0
	while cur_student < n or len(q):
		while cur_student < n and l[cur_student] == cur_t:
			q.append(cur_student)
			cur_student += 1
		while len(q):
			i = q.popleft()
			if cur_t > r[i]:
				print(0, end=' ')
				continue
			print(cur_t, end=' ')
			break
		cur_t += 1
	print()


n = int(input())
for i in range(n):
	m = int(input())
	t = 0
	d = []
	for i in range(m):
		(a, b) = map(int, input().split())
		t = max(t + 1, a)
		if t > b:
			d.append(0)
			t -= 1
		else:
			d.append(t)
	print(*d)


from collections import deque
t = int(input())
for i in range(t):
	k = int(input())
	a = deque(([] for i in range(k)))
	for j in range(k):
		a[j].append(j)
		a[j].append([int(x) for x in input().split()])
	t1 = a.popleft()
	d = deque([t1])
	ans = [0] * k
	s = t1[1][0]
	while d or a:
		while len(a) > 0:
			if a[0][1][0] <= s:
				d.append(a.popleft())
			else:
				break
		while d:
			t1 = d.popleft()
			if t1[1][1] >= s:
				ans[t1[0]] = s
				break
		s += 1
	print(*ans)


t = int(input())
for test in range(t):
	n = int(input())
	l = [0] * n
	r = [0] * n
	for i in range(n):
		(x, y) = map(int, input().split())
		l[i] = x
		r[i] = y
	tek = l[0]
	for i in range(n):
		if tek > r[i]:
			print(0, end=' ')
			if i != n - 1:
				tek = max(tek, l[i + 1])
			continue
		print(tek, end=' ')
		tek += 1
		if i != n - 1:
			tek = max(tek, l[i + 1])
	print()


import math
t = int(input())
while t > 0:
	stud = int(input())
	time = [0 for _ in range(stud)]
	duration = []
	for _ in range(stud):
		(l, r) = map(int, input().split())
		duration.append((l, r))
	start_t = 0
	for i in range(stud):
		start_t = max(start_t, duration[i][0])
		(l, r) = duration[i]
		if r < start_t:
			continue
		else:
			time[i] = start_t
			start_t += 1
	for i in range(stud):
		print(time[i], end=' ')
	print()
	t -= 1


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	n = ii()
	arr = []
	for i in range(n):
		(a, b) = r()
		arr.append([i, a, b])
	arr.sort(key=lambda x: x[1])
	ans = [0] * n
	time = 0
	for (i, j, k) in arr:
		if not i:
			time = j
			ans[i] = j
			time += 1
		elif j == arr[i - 1][1]:
			if time <= k:
				ans[i] = time
				time += 1
		else:
			time = max(time, j)
			if time <= k:
				ans[i] = time
				time += 1
	print(*ans)
for _ in range(ii()):
	solve()


read = lambda : map(int, input().split())
T = int(input())
for ____ in range(T):
	n = int(input())
	a = []
	for _ in range(n):
		a.append(list(read()))
	t = 0
	while a:
		b = a[0][0]
		if b >= t:
			t = b
			print('%d ' % t, end='')
		elif t > a[0][1]:
			print('0 ', end='')
			del a[0]
			continue
		else:
			print('%d ' % t, end='')
		t += 1
		del a[0]
	print()


for _ in range(int(input())):
	n = int(input())
	q = []
	time = 0
	for i in range(n):
		(s, e) = map(int, input().split())
		q.append([s, e])
	while q:
		if q[0][1] >= time:
			(x, y) = q.pop(0)
			time = max(time + 1, x)
			print(time, end=' ')
		while q and q[0][1] <= time:
			q.pop(0)
			print(0, end=' ')
	print()


R = lambda : map(int, input().split())
t = int(input())
for _ in range(t):
	n = int(input())
	s = 1
	ans = [0] * n
	for i in range(n):
		(l, r) = R()
		if l > s:
			s = l
		if s <= r:
			ans[i] = s
			s += 1
	for i in ans:
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	r = []
	for i in range(n):
		(ll, rr) = map(int, input().split())
		l.append(ll)
		r.append(rr)
	cur_t = 1
	cur_student = 0
	first_student_in_queue = 0
	while cur_student < n or first_student_in_queue < cur_student:
		while cur_student < n and l[cur_student] == cur_t:
			cur_student += 1
		while first_student_in_queue < cur_student:
			if cur_t > r[first_student_in_queue]:
				print(0, end=' ')
				first_student_in_queue += 1
				continue
			print(cur_t, end=' ')
			first_student_in_queue += 1
			break
		cur_t += 1
	print()


n = int(input())
for j in range(n):
	m = int(input())
	a = []
	t = 0
	for i in range(m):
		(x, y) = map(int, input().split())
		if t <= x:
			t = x + 1
			a.append(t - 1)
		elif t > y:
			a.append(0)
		else:
			a.append(t)
			t += 1
	print(*a)


t = int(input())
for i in range(t):
	cnt = 0
	ans = []
	n = int(input())
	for k in range(n):
		(a, b) = list(map(int, input().split()))
		if cnt < a:
			cnt = a
		if cnt <= b:
			ans.append(cnt)
			cnt += 1
		else:
			ans.append(0)
	print(' '.join(map(str, ans)))