There are $n$ segments $[l_i, r_i]$ for $1 \le i \le n$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.

To optimize testing process you will be given multitest.


-----Input-----

The first line contains one integer $T$ ($1 \le T \le 50000$) — the number of queries. Each query contains description of the set of segments. Queries are independent.

First line of each query contains single integer $n$ ($2 \le n \le 10^5$) — number of segments. It is guaranteed that $\sum{n}$ over all queries does not exceed $10^5$.

The next $n$ lines contains two integers $l_i$, $r_i$ per line ($1 \le l_i \le r_i \le 2 \cdot 10^5$) — the $i$-th segment.


-----Output-----

For each query print $n$ integers $t_1, t_2, \dots, t_n$ ($t_i \in \{1, 2\}$) — for each segment (in the same order as in the input) $t_i$ equals $1$ if the $i$-th segment will belongs to the first group and $2$ otherwise.

If there are multiple answers, you can print any of them. If there is no answer, print $-1$.


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

Output
2 1 
-1
1 1 2 



-----Note-----

In the first query the first and the second segments should be in different groups, but exact numbers don't matter.

In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $-1$.

In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $6$ possible is correct.

Difficulty: MEDIUM
Tags: Sorting
Skill types: Sorting

Starter code:

Solutions:
import sys
import math
from heapq import *
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

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

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
mod = 1000000007
f = []

def fact(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncr(n, r, m):
	if n < 0 or r < 0 or r > n:
		return 0
	if r == 0:
		return 1
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def main():
	DivisionAndUnion()

def cmp(a, b):
	if a[1] > b[1]:
		return 1
	if a[1] < b[1]:
		return -1
	return 0
ans = [0 for i in range(100005)]

def DivisionAndUnion():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = []
		for i in range(n):
			[x, y] = ti()
			a.append([x, y, i])
		a.sort(key=cmp_to_key(cmp))
		index = -1
		mn = a[n - 1][0]
		for i in range(n - 2, -1, -1):
			if a[i][1] >= mn:
				mn = min(mn, a[i][0])
				continue
			else:
				index = i
				break
		if index == -1:
			print(-1)
			continue
		for i in range(n):
			if i <= index:
				ans[a[i][2]] = 1
			else:
				ans[a[i][2]] = 2
		res = ''
		for i in range(n):
			res += str(ans[i]) + ' '
		print(res.strip())
main()


t = int(input())
for _ in range(t):
	n = int(input())
	dp = [2 for i in range(n)]
	lst = [0 for i in range(2 * n)]
	count = 0
	for i in range(n):
		(u, v) = map(int, input().split())
		lst[count] = [u, -1, i]
		lst[count + 1] = [v, 1, i]
		count += 2
	lst.sort()
	total = 0
	for i in lst:
		total = total - i[1]
		if total > 0:
			dp[int(i[-1])] = 1
		else:
			break
	if dp.count(1) == n:
		print(-1)
	else:
		print(*dp)


T = int(input())
for _ in range(T):
	n = int(input())
	snts = []
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		snts.append([l, r, i])
	snts = sorted(snts, key=lambda x: x[0])
	res = [1]
	(rs, v, ids) = ([snts[0][1], -1], 0, [snts[0][2]])
	for i in range(1, n):
		(l, r, id) = snts[i]
		ids.append(id)
		if l <= rs[v]:
			res.append(v + 1)
			rs[v] = max(rs[v], r)
		else:
			res.append(2)
	if len(set(res)) == 1:
		print('-1')
	else:
		res = sorted(zip(ids, res), key=lambda x: x[0])
		res = [item[1] for item in res]
		print(' '.join(map(str, res)))


t = int(input())
for tc in range(t):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append([i, a, b])
	l = sorted(l, key=lambda x: x[1])
	last = l[0][1]
	i = 0
	while i < n:
		if l[i][1] > last:
			break
		last = max(last, l[i][2])
		i += 1
	if i == n:
		print(-1)
	else:
		ind = [2] * n
		for j in range(i):
			ind[l[j][0]] = 1
		for i in ind:
			print(i, end=' ')
		print('')


import operator
from operator import itemgetter
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		(l, r) = map(int, input().split())
		a.append([l, r, i])
	a.sort(key=itemgetter(1))
	p = -1
	mn = a[n - 1][1]
	for i in range(n - 1, -1, -1):
		if mn > a[i][1]:
			p = i
		mn = min(mn, a[i][0])
	if p == -1:
		print(-1)
	else:
		ans = [-1] * n
		for i in range(n):
			ans[a[i][2]] = 1 + (i <= p)
		print(*ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = sorted((list(map(int, input().split())) + [i] for i in range(n)))
	ans = [0] * n
	group = 1
	maxx = a[0][1]
	for (l, r, i) in a:
		if group == 1 and maxx < l:
			group = 2
		if r > maxx:
			maxx = r
		ans[i] = group
	if group == 2:
		print(*ans)
	else:
		print(-1)


q = int(input())
while q > 0:
	q = q - 1
	L = []
	n = int(input())
	for i in range(n):
		L.append(tuple(map(int, input().split())))
	d = {}
	ind = 0
	for i in L:
		if i not in d:
			d[i] = []
		d[i].append(ind)
		ind += 1
	S = sorted(L)
	r = S[0][1]
	i = 1
	while i < n:
		if S[i][0] > r:
			break
		r = max(r, S[i][1])
		i += 1
	if i == n:
		print(-1)
	else:
		while i < n:
			d[S[i]].append(-2)
			i += 1
		for i in L:
			if d[i][-1] == -2:
				print(2, end=' ')
			else:
				print(1, end=' ')
		print()


n = int(input())
for i in range(n):
	li = []
	origli = []
	q = int(input())
	for j in range(q):
		(a, b) = input().split(' ')
		(a, b) = (int(a), int(b))
		li.append([a, b])
		origli.append([a, b])
	li.sort()
	newli = [li[0]]
	i = 1
	s1 = set()
	s2 = set()
	s1.add(tuple(li[0]))
	while i < len(li):
		if li[i][0] <= newli[-1][1]:
			if tuple(li[i - 1]) in s1:
				s1.add(tuple(li[i]))
			else:
				s2.add(tuple(li[i]))
			if newli[-1][1] < li[i][1]:
				newli[-1][1] = li[i][1]
			i += 1
		else:
			if tuple(li[i - 1]) in s1:
				s2.add(tuple(li[i]))
			else:
				s1.add(tuple(li[i]))
			newli.append([li[i][0], li[i][1]])
			i += 1
	ans = []
	if len(newli) == 1:
		print(-1)
		continue
	for i in range(len(origli)):
		if tuple(origli[i]) in s1:
			ans.append(1)
		elif tuple(origli[i]) in s2:
			ans.append(2)
	joined_string = ' '.join([str(v) for v in ans])
	print(joined_string)


from collections import namedtuple
Segment = namedtuple('Segment', 'left right originalindex')
T = int(input())
for testcase in range(T):
	n = int(input())
	segs = [Segment(*map(int, input().split()), _) for _ in range(n)]
	segs.sort()
	edge = segs[0].right
	start2grp = 1
	while start2grp < n and segs[start2grp].left <= edge:
		edge = max(edge, segs[start2grp].right)
		start2grp += 1
	if start2grp == n:
		print(-1)
	else:
		grouplist = [(seg.originalindex, '1' if i < start2grp else '2') for (i, seg) in enumerate(segs)]
		grouplist.sort()
		print(' '.join([g[1] for g in grouplist]))


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(rint()):
		n = rint()
		a = sorted(rints_enu(n))
		(g1, g2) = ([a[0][1]], [])
		(mi, ma) = a[0][0]
		for (i, j) in a[1:]:
			if overlap(i, (mi, ma)):
				g1.append(j)
				ma = max(ma, i[1])
			else:
				g2.append(j)
		if g2:
			ans = [0] * n
			for i in g1:
				ans[i] = 1
			for i in g2:
				ans[i] = 2
			print(*ans)
		else:
			print(-1)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [tuple(rints()) for _ in range(n)]
rints_enu = lambda n: [(tuple(rints()), i) for i in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
overlap = lambda a, b: min(a[1], b[1]) - max(a[0], b[0]) >= 0
main()


for _ in [0] * int(input()):
	n = int(input())
	t = [0] * n
	g = c = k = 0
	a = sorted(sum(zip(*(((l, 1, i), (r + 1, 0, i)) for ((l, r), i) in ((map(int, input().split()), i) for i in range(n)))), ()))
	for (x, m, i) in a:
		if m:
			if c == 0:
				k += 1
				g ^= 1
			t[i] = g + 1
			c += 1
		else:
			c -= 1
	if k < 2:
		print(-1)
	else:
		print(*t)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		segments = []
		for i in range(n):
			(l, r) = map(int, input().split())
			segments.append((l, r, i))
		segments.sort(key=lambda x: (x[0], -x[1]))
		flag = False
		ret = [0] * n
		ret[segments[0][2]] = 1
		max_y = segments[0][1]
		for i in range(1, n):
			if flag:
				ret[segments[i][2]] = 2
			else:
				cur_seg = segments[i]
				if cur_seg[0] > max_y:
					ret[cur_seg[2]] = 2
					flag = True
				else:
					ret[cur_seg[2]] = 1
					max_y = max(max_y, cur_seg[1])
		if not flag:
			print(-1)
		else:
			for i in range(n):
				print(ret[i], end=' ')
			print('')
main()


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

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

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

def nu():
	return int(input())
mm = 1000000007
t = nu()
cc = 0
for it in range(t):
	n = nu()
	a = []
	for i in range(n):
		(l, r) = num()
		a.append((l, r, i))
	a.sort()
	zp = [0] * n
	cc += 1
	if n == 1:
		print(-1)
		continue
	if n == 2:
		if a[0][1] < a[1][0]:
			print(1, 2)
		else:
			print(-1)
		continue
	mx = a[0][1]
	ff = False
	z = 0
	for i in range(1, n):
		if a[i][0] > mx:
			z = i
			ff = True
			break
		mx = max(a[i][1], mx)
	if ff == True:
		for i in range(n):
			if i < z:
				zp[a[i][2]] = 1
			else:
				zp[a[i][2]] = 2
		print(*zp)
	else:
		print(-1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = []
	for i in range(n):
		a.append(value())
	a = [(a[i], i) for i in range(n)]
	a.sort()
	ans = [2] * n
	l = a[0][0][1]
	for i in range(n - 1):
		ans[a[i][1]] = 1
		l = max(l, a[i][0][1])
		r = a[i + 1][0][0]
		if l < r:
			break
	if l < r:
		print(*ans)
	else:
		print(-1)


def do_intersect(a, b):
	return min(a[1], b[1]) >= max(a[0], b[0])
for _ in range(int(input())):
	n = int(input())
	inps = [tuple(map(int, input().split())) for _ in range(n)]
	org = [pair for pair in inps]
	inps.sort()
	seta = inps[0]
	setb = (float('inf'), float('-inf'))
	for i in range(1, n):
		if do_intersect(seta, inps[i]):
			seta = (min(inps[i][0], seta[0]), max(inps[i][1], seta[1]))
		else:
			setb = (min(inps[i][0], setb[0]), max(inps[i][1], setb[1]))
			break
	if setb == (float('inf'), float('-inf')):
		print(-1)
	else:
		ans = []
		for inp in org:
			if do_intersect(inp, seta):
				ans.append(1)
			else:
				ans.append(2)
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = sorted((list(map(int, input().split())) + [i] for i in range(n)))
	ans = [0] * n
	group = 1
	maxx = a[0][1]
	for (l, r, i) in a:
		if group == 1 and maxx < l:
			group = 2
		if r > maxx:
			maxx = r
		ans[i] = group
	if group == 2:
		print(*ans)
	else:
		print(-1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
kk = lambda : map(int, input().split())
for _ in range(int(input())):
	ls = [None] * int(input())
	for i in range(len(ls)):
		(l, r) = kk()
		ls[i] = (l, r, i)
	ids = [-1] * len(ls)
	ls.sort()
	r = {0: -1, 1: -1}
	curr = 0
	both = 0
	for seg in ls:
		if seg[0] > r[curr]:
			curr ^= 1
			r[curr] = seg[1]
			both += 1
		else:
			r[curr] = max(seg[1], r[curr])
		ids[seg[2]] = curr + 1
	if both < 2:
		print(-1)
	else:
		print(*ids)


from collections import deque
import pdb

def rI():
	return [int(i) for i in input().split()]
t = rI()[0]
for j in range(t):
	n = rI()[0]
	dat = []
	rMax = 0
	for i in range(n):
		(l, r) = rI()
		dat.append((l, r, i))
		rMax = max(rMax, r)
	stat = [0 for i in range(n + 1)]
	bilo = False
	relax = True
	dat.sort()
	rg = dat[0][0] - 1
	ss = 0
	for (l, r, i) in dat:
		l -= 1
		r -= 1
		if l > rg:
			break
		else:
			rg = max(rg, r)
			ss += 1
			bilo = True
			stat[i] = 1
	if bilo == False or ss == n:
		print(-1)
	else:
		for i in range(n):
			print(stat[i] + 1, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = []
	ans = [0] * n
	for i in range(n):
		(q, w) = map(int, input().split())
		a.append([q, w, i])
	a.sort()
	ans[a[0][2]] = 1
	m = a[0][1]
	for i in range(1, n):
		m = max(a[i - 1][1], m)
		if a[i][0] <= m:
			ans[a[i][2]] = ans[a[i - 1][2]]
		else:
			ans[a[i][2]] = int(not ans[a[i - 1][2]])
	g = 0
	for i in range(n):
		if ans[i] == 0:
			g = 1
			ans[i] = 2
	if g == 0:
		print(-1)
	else:
		print(*ans)


import operator
q = int(input())
for i in range(q):
	listt = []
	n = int(input())
	dic = {}
	for j in range(n):
		(l, r) = map(int, input().split())
		listt.append([l, r, 0, j])
	listt.sort(key=lambda x: x[0])
	listt[0][2] = 1
	key1 = listt[0][0]
	key2 = listt[0][1]
	ind = 0
	for i in range(1, n):
		if listt[i][0] <= key2:
			listt[i][2] = 1
			if listt[i][1] > key2:
				key2 = listt[i][1]
		else:
			ind = i
			break
	if ind != 0:
		for i in range(ind, n):
			listt[i][2] = 2
			if listt[i][1] > key2:
				key2 = listt[i][1]
		ans = [0] * n
		for i in range(n):
			ans[listt[i][3]] = listt[i][2]
		for i in ans:
			print(i, end=' ')
		print()
	else:
		print(-1)


from collections import defaultdict as dd
dic = dd(int)
t = int(input())
for i in range(t):
	n = int(input())
	(seg, suff) = ([], [0] * n)
	(till, flag) = (0, 0)
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		seg.append([l, r])
	arr = seg[:]
	seg.sort(key=lambda x: x[1])
	cur = 100000000
	suff[n - 1] = seg[n - 1][0]
	for i in range(n - 2, -1, -1):
		suff[i] = min(seg[i][0], suff[i + 1])
	for i in range(n - 1):
		if seg[i][1] < suff[i + 1]:
			flag = 1
			till = i
			break
	if not flag:
		print(-1)
	else:
		for i in range(till + 1):
			dic[tuple(seg[i])] = 1
		for i in range(till + 1, n):
			dic[tuple(seg[i])] = 2
		for i in arr:
			print(dic[tuple(i)], end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		(b, r) = map(int, input().split())
		l.append([b, r, j, 0])
	l.sort(key=lambda x: x[0])
	k = 0
	m = l[0][1]
	while k < n - 1 and m >= l[k + 1][0]:
		if l[k + 1][1] > m:
			m = l[k + 1][1]
		k += 1
	if k == n - 1:
		print(-1)
	else:
		for j in range(k + 1):
			l[j][3] = 1
		for j in range(k + 1, n):
			l[j][3] = 2
		l.sort(key=lambda x: x[2])
		for j in range(n):
			print(l[j][3], end=' ')
	print()


ansarr = []
t = int(input())
for l in range(t):
	n = int(input())
	arr1 = []
	for i in range(n):
		(a, b) = map(int, input().split())
		arr1.append((a, b, i))
	arr1.sort()
	max1 = arr1[0][1]
	flag = 0
	arr2 = [0] * n
	arr2[arr1[0][2]] = 1
	for i in range(1, n):
		if flag == 0 and arr1[i][0] <= max1:
			max1 = max(max1, arr1[i][1])
			arr2[arr1[i][2]] = 1
		else:
			flag = 1
			arr2[arr1[i][2]] = 2
	if flag == 0:
		print(-1)
	else:
		print(*arr2)


N = int(input())
for i in range(N):
	T = int(input())
	newtable = []
	for i in range(T):
		(a, b) = map(int, input().split())
		newtable.append((a, b, i))
	newtable.sort()
	sta = 0
	ans = [-1] * T
	flag = 0
	t = 0
	i = 0
	while i < T:
		(s, t, k) = newtable[i]
		if t > sta:
			sta = t
			ans[k] = flag % 2 + 1
			i += 1
			while i < T and newtable[i][0] <= sta:
				(x, y, j) = newtable[i]
				ans[j] = flag % 2 + 1
				if y > sta:
					sta = y
				i += 1
		flag += 1
	if flag == 1:
		print(-1)
	else:
		print(' '.join(map(str, ans)))


L = 0
R = 1

def main():
	buf = input()
	T = int(buf)
	n = []
	lr = []
	for i in range(T):
		buf = input()
		n.append(int(buf))
		lr.append([])
		for j in range(n[i]):
			buf = input()
			buflist = buf.split()
			lr[i].append([int(buflist[0]), int(buflist[1])])
	for i in range(T):
		lr_s = list(sorted(lr[i]))
		threshold = lr_s[0][R]
		threshold_final = None
		for j in range(1, n[i]):
			if threshold < lr_s[j][L]:
				threshold_final = threshold
				break
			elif threshold < lr_s[j][R]:
				threshold = lr_s[j][R]
		if threshold_final == None:
			print(-1)
			continue
		answer = ''
		for j in range(n[i]):
			if lr[i][j][L] <= threshold_final:
				answer += '1'
			else:
				answer += '2'
			if j < n[i] - 1:
				answer += ' '
		print(answer)
main()


t = int(input())
for i in range(t):
	n = int(input())
	x = []
	for j in range(n):
		(l, r) = map(int, input().split(' '))
		x.append((l, r))
	y = sorted(x, key=lambda x: x[0])
	j = 1
	f = 0
	max = y[0][1]
	while j < len(y):
		if y[j][0] > max:
			q = y[j][0]
			f = 1
			break
		elif y[j][1] > max:
			max = y[j][1]
		j = j + 1
	if f == 1:
		j = 0
		w = []
		while j < len(x):
			if x[j][0] >= q:
				w.append(2)
			else:
				w.append(1)
			j = j + 1
		for k in w:
			print(k, end=' ')
		print()
	else:
		print(-1)


import sys
inf = float('inf')

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

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

def input():
	return sys.stdin.readline()
for _ in range(int(input())):
	n = int(input())
	l = sorted((get_array() + [i] for i in range(n)))
	right = l[0][1]
	count = 0
	for i in range(n):
		if l[i][0] > right:
			break
		right = max(right, l[i][1])
		count += 1
	if count == n:
		print(-1)
	else:
		ans = [1] * n
		for j in l:
			ans[j[2]] = 2
			count -= 1
			if not count:
				break
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append([list(map(int, input().split())), i])
	ans = [-1] * n
	a.sort()
	f = -1
	maxr = -1
	for i in range(n - 1):
		maxr = max(a[i][0][1], maxr)
		if maxr < a[i + 1][0][0]:
			f = i
			break
	if f == -1:
		print(-1)
	else:
		for i in range(f + 1):
			ans[a[i][1]] = 1
		for i in range(f + 1, n):
			ans[a[i][1]] = 2
		for i in ans:
			print(i, end=' ')
		print('')


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	n = int(sys.stdin.readline())
	a = []
	for i in range(n):
		(l, r) = map(int, sys.stdin.readline().split())
		a.append([l, r, i])
	a.sort()
	ans = [2] * n
	maxx = a[0][1]
	ans[a[0][2]] = 1
	for i in range(1, n):
		maxx = max(maxx, a[i - 1][1])
		if a[i][0] <= maxx:
			ans[a[i][2]] = ans[a[i - 1][2]]
	if ans.count(1) != 0 and ans.count(2) != 0:
		print(*ans)
	else:
		print(-1)


t = int(input())
for ti in range(t):
	n = int(input())
	lri = [None for _ in range(n)]
	for _ in range(n):
		(li, ri) = map(int, input().split())
		lri[_] = (li, ri, _)
	lri.sort()
	t = [None for _ in range(n)]
	(ct, t[lri[0][2]], eg) = (1, 1, lri[0][1])
	for i in range(1, n):
		if lri[i][0] <= eg:
			t[lri[i][2]] = ct
			eg = max(eg, lri[i][1])
		else:
			ct = 3 - ct
			t[lri[i][2]] = ct
			eg = lri[i][1]
	if all((ti == 1 for ti in t)):
		print(-1)
	else:
		print(*t)


T = int(input())
for t in range(T):
	N = int(input())
	segs = []
	for (i, n) in enumerate(range(N)):
		seg = [int(x) for x in input().split()] + [i]
		segs.append(seg)
	segs.sort(key=lambda x: x[0])
	clas = 1
	nots = [2] * len(segs)
	(A, B, _) = segs[0]
	for seg in segs:
		(C, D, idx) = seg
		if D >= A and C <= B:
			nots[idx] = clas
			B = max(B, D)
		else:
			clas += 1
			break
	if clas == 1:
		print(-1)
	else:
		print(*nots)


for _ in range(int(input())):
	n = int(input())
	a = sorted((list(map(int, input().split())) + [i] for i in range(n)))
	cut = a[0][1]
	ans = [2] * n
	ok = False
	for i in range(n):
		if cut < a[i][0]:
			for k in range(i):
				ans[a[k][2]] = 1
			ok = True
			break
		cut = max(cut, a[i][1])
	if ok == True:
		print(*ans)
	else:
		print(-1)


T = int(input())
for i in range(T):
	n = int(input())
	inp = []
	temp = []
	for j in range(n):
		(a, b) = [int(u) for u in input().split()]
		inp.append([a, b])
		temp.append([a, b])
	inp.sort()
	check = 0
	begin = inp[0][0]
	end = inp[0][1]
	for j in range(n):
		if inp[j][0] > end:
			check = 1
			break
		if inp[j][1] > end:
			end = inp[j][1]
	ans = []
	if check == 0:
		print(-1)
	else:
		for j in range(n):
			if temp[j][0] >= begin and temp[j][1] <= end:
				ans.append('1')
			else:
				ans.append('2')
		print(' '.join(ans))


import collections as cc
for tc in range(int(input())):
	n = int(input())
	a = []
	ch = [1] * n
	f = cc.defaultdict(int)
	for t in range(n):
		tt = list(map(int, input().split()))
		a.append(tt + [t])
	a.sort()
	sx = a[0][0]
	sy = a[0][1]
	for i in range(n):
		if a[i][0] > sy:
			break
		sy = max(sy, a[i][1])
		ch[a[i][2]] = 2
	if min(ch) == max(ch):
		print(-1)
	else:
		print(*ch)


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
from io import BytesIO, FileIO, StringIO
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip
INP_FILE = 0
OUT_FILE = 1
if sys.version_info[0] < 3:
	sys.stdin = BytesIO(FileIO(INP_FILE).read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = BytesIO()
	register(lambda : FileIO(OUT_FILE, 'w').write(sys.stdout.getvalue()))
else:
	sys.stdin = BytesIO(FileIO(INP_FILE).read())
	input = lambda : sys.stdin.readline().decode().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : FileIO(OUT_FILE, 'w').write(sys.stdout.getvalue().encode()))

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		points = sorted((list(map(int, input().split(' '))) + [i] for i in range(n)))
		r_max = points[0][1]
		i = 0
		while i < n and points[i][0] <= r_max:
			r_max = max(r_max, points[i][1])
			i += 1
		if i == n:
			print(-1)
		else:
			res = [2] * n
			for point in points:
				res[point[2]] = 1
				i -= 1
				if i == 0:
					break
			print(*res)
main()


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		input = iter(sys.stdin.buffer.readlines()).__next__

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	score = []
	for _ in range(int(input())):
		n = int(input())
		q = sorted([list(map(int, input().split())) + [i] for i in range(n)])
		t = [2] * n
		le = q[0][1]
		for (s, e, i) in q:
			if s > le:
				break
			t[i] = 1
			le = max(le, e)
		if t[q[-1][2]] == 1:
			score.append(str(-1))
			continue
		score.append(' '.join(map(str, t)))
	print('\n'.join(score))
sync_with_stdio(False)
main()


n = int(input())
for t in range(n):
	k = int(input())
	samples = []
	for i in range(k):
		samples.append(tuple(map(int, input().split())))
	samples = sorted(enumerate(samples), key=lambda x: x[1])
	tick = 1
	ans = [1]
	group_end = samples[0][1][1]
	for si in range(1, len(samples)):
		now = samples[si][1]
		if now[0] > group_end:
			tick = 2
		else:
			group_end = max(now[1], group_end)
			ans.append(1)
		if tick == 2:
			ans.extend([2] * (len(samples) - si))
			break
	ans = sorted(zip(samples, ans))
	ans = list([x[1] for x in ans])
	if 2 not in ans:
		print(-1)
	else:
		print(' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	lis = []
	for i in range(n):
		(a, b) = map(int, input().split())
		lis.append([a, b, i + 1])
	lis.sort()
	ans = [2] * (n + 1)
	ans[0] = 0
	j = lis[0][1]
	ans[lis[0][2]] = 1
	for i in range(1, n):
		(a, b, c) = lis[i]
		if j >= a:
			ans[c] = 1
			j = max(j, b)
	if sum(ans) == n:
		print(-1)
	else:
		print(*ans[1:])


def solve():
	n = int(input())
	points = []
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		points.append((l, r, i))
	points.sort()
	border = -1
	cnt_sets = 1
	cur_set = 0
	ans = [0 for _ in range(n)]
	for (l, r, pos) in points:
		if (l > border and border < r) and border != -1:
			cnt_sets += 1
			cur_set ^= 1
			border = max(l, r)
		else:
			border = max(border, r, l)
		ans[pos] = cur_set
	if cnt_sets == 1:
		print(-1)
		return
	ans = [x + 1 for x in ans]
	print(*ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
import math
from collections import *
from queue import *
from bisect import *
MOD = int(1000000000.0 + 7)
inf = float('inf')
ninf = float('-inf')
input = sys.stdin.readline

def ii():
	return list(map(int, input().strip().split()))
for _ in range(int(input())):
	(n,) = ii()
	arr = []
	for k in range(n):
		(a, b) = ii()
		arr.append([a, b, k])
	arr.sort()
	l = arr[0][1]
	res = [0] * n
	fl = 1
	for k in range(n):
		if arr[k][0] > l:
			fl = 2
		l = max(l, arr[k][1])
		res[arr[k][2]] = fl
	if fl == 1:
		print(-1)
	else:
		print(*res)


from sys import stdin
t = int(input())
while t > 0:
	n = int(input())
	li = []
	for i in range(n):
		(l, r) = [int(x) for x in stdin.readline().split()]
		li.append((l, r, i))
	li2 = sorted(li)
	ans = [2] * n
	ans[li2[0][2]] = 1
	d = li2[0][1]
	count = 0
	for i in range(1, len(li2)):
		c = li2[i][0]
		if c > d:
			count += 1
			ans[li2[i][2]] = 2
			break
		else:
			ans[li2[i][2]] = 1
		d = max(d, li2[i][1])
	if count == 0:
		print(-1)
	else:
		print(*ans)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		(li, ri) = map(int, input().split())
		l.append([li, ri, i, 1])
	l.sort(key=lambda x: x[0])
	r = l[0][1]
	for i in range(1, n):
		if l[i][0] <= r:
			l[i][3] = 1
			r = max(r, l[i][1])
		else:
			l[i][3] = 2
	b = False
	for i in range(1, n):
		if l[i][3] != l[i - 1][3]:
			b = True
	if not b:
		print(-1)
	else:
		l.sort(key=lambda x: x[2])
		for i in range(n):
			print(l[i][3], end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	pnt = []
	for i in range(n):
		(L, R) = map(int, input().split())
		pnt += ((L, 0, i), (R, 1, i))
	pnt.sort()
	(kol, t, ans) = (0, 0, [2] * n)
	for (x, z, i) in pnt:
		if z == 1:
			kol -= 1
		else:
			kol += 1
			if kol == 1:
				t += 1
			ans[i] -= t % 2
	if t < 2:
		print(-1)
	else:
		print(*ans)


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
from io import BytesIO, FileIO, StringIO
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip
INP_FILE = 0
OUT_FILE = 1
if sys.version_info[0] < 3:
	sys.stdin = BytesIO(FileIO(INP_FILE).read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = BytesIO()
	register(lambda : FileIO(OUT_FILE, 'w').write(sys.stdout.getvalue()))
else:
	sys.stdin = StringIO(FileIO(INP_FILE).read().decode())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : FileIO(OUT_FILE, 'w').write(sys.stdout.getvalue().encode()))

def main():
	out = []
	for _ in range(int(input())):
		n = int(input())
		q = sorted([list(map(int, input().split())) + [i] for i in range(n)])
		t = ['2'] * n
		le = q[0][1]
		for (s, e, i) in q:
			if s > le:
				break
			t[i] = '1'
			le = max(le, e)
		if t[q[-1][2]] == '1':
			out.append('-1')
			continue
		out.append(' '.join(t))
	print('\n'.join(out))
main()


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br
cases = int(stdin.readline().strip())
for case in range(cases):
	n = int(stdin.readline().strip())
	s = []
	s1 = []
	s2 = []
	st = set()
	for i in range(n):
		(a, b) = map(int, stdin.readline().strip().split())
		s.append(a)
		s1.append(a)
		s2.append(b)
		st.add(b)
	s1.sort()
	s2.sort()
	t = False
	q = -1
	for i in st:
		x = br(s2, i)
		y = n - bl(s1, i + 1)
		if x != 0 and y != 0 and (x + y == n):
			t = True
			q = i + 1
			break
	ans = []
	if t:
		for i in range(n):
			if s[i] >= q:
				ans.append(1)
			else:
				ans.append(2)
		print(*ans)
	else:
		print(-1)


import sys
input = sys.stdin.readline
from itertools import accumulate
t = int(input())
for _ in range(t):
	n = int(input())
	lr = [list(map(int, input().split())) + [i] for i in range(n)]
	lr.sort()
	mx = [lr[0][1]]
	for i in range(1, n):
		mx.append(max(mx[-1], lr[i][1]))
	flg = 0
	ans = [1 for i in range(n)]
	for i in range(n):
		(l, r, idx) = lr[i]
		if i > 0:
			if flg or l > mx[i - 1]:
				ans[idx] = 2
				flg = 1
	if flg == 0:
		print(-1)
		continue
	else:
		print(*ans)


for _ in range(int(input())):
	n = int(input())
	segs = []
	for i in range(n):
		(l, r) = map(int, input().split())
		segs.append((l, r, i))
	segs.sort(key=lambda x: x[1])
	suffixMinX = [-1] * n
	suffixMinX[n - 1] = segs[n - 1][0]
	for i in range(n - 2, -1, -1):
		suffixMinX[i] = min(suffixMinX[i + 1], segs[i][0])
	ret = [None] * n
	for i in range(n - 1):
		if segs[i][1] < suffixMinX[i + 1]:
			for j in range(i + 1):
				ret[segs[j][2]] = '1'
			for j in range(i + 1, n):
				ret[segs[j][2]] = '2'
			print(' '.join(ret))
			break
	else:
		print(-1)


t = int(input())
for _ in range(t):
	q = int(input())
	d = dict()
	main = []
	rese = []
	for i in range(q):
		(l, r) = map(int, input().split())
		d[hash((l, r))] = -1
		main.append([l, r])
		rese.append([l, r])
	main.sort()
	new_l = main[0][0]
	new_r = main[0][1]
	d[hash((new_l, new_r))] = 1
	flag = False
	for i in range(1, q):
		if i != 0:
			if new_l <= main[i][0] and new_r >= main[i][0]:
				new_r = max(main[i][1], new_r)
				d[hash((main[i][0], main[i][1]))] = 1
			else:
				flag = True
				d[hash((main[i][0], main[i][1]))] = 2
			if flag:
				break
	if flag:
		for i in range(q):
			if d[hash((rese[i][0], rese[i][1]))] in [1, 2]:
				print(d[hash((rese[i][0], rese[i][1]))], end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		print('-1')


for i in range(int(input())):
	l = []
	n = int(input())
	for j in range(n):
		(x, y) = map(int, input().split())
		l.append((min(x, y), max(x, y), j))
	ans = []
	group = ' 1'
	prev = int(0)
	j = int(0)
	l.sort()
	for (cur, b, c) in l:
		if group == ' 2':
			ans.append((c, 2))
		elif cur > prev and j != 0:
			ans.append((c, 2))
			group = ' 2'
		else:
			ans.append((c, 1))
		prev = max(prev, b)
		j += 1
	if group == ' 1':
		print('-1')
	else:
		ans.sort()
		for (a, b) in ans:
			print(b, end=' ')
		print()


q = int(input())
for i in range(q):
	n = int(input())
	ilist = []
	for j in range(n):
		ilist.append(list(map(int, input().rstrip().split())))
		ilist[j].append(j)
	ilist.sort()
	seglist = [2] * n
	seglist[ilist[0][2]] = 1
	goodvalue = -1
	currentmax = ilist[0][1]
	for k in range(n - 1):
		if currentmax >= ilist[k + 1][0]:
			seglist[ilist[k + 1][2]] = 1
			currentmax = max([currentmax, ilist[k + 1][1]])
		if currentmax < ilist[k + 1][0]:
			break
	if sum(seglist) == n:
		print(-1)
	else:
		print(*seglist)


for _ in [0] * int(input()):
	n = int(input())
	a = []
	for i in range(n):
		(l, r) = map(int, input().split())
		a += ((l, 0, i), (r, 1, i))
	a.sort()
	(g, c, t) = (2, 0, [0] * n)
	for (x, m, i) in a:
		if m:
			c -= 1
		else:
			if c == 0:
				g ^= 3
			t[i] = g
			c += 1
	if 2 in t:
		print(*t)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z
for i in range(int(input())):
	n = int(input())
	a = [0] * n
	b = [0] * n
	c = [0] * n
	for j in range(n):
		(a[j], b[j]) = map(int, input().split())
		c[j] = j
	b = sort_list(b, a)
	c = sort_list(c, a)
	a.sort()
	l = [0] * n
	d = 0
	k = 0
	for j in range(n):
		if d == 0:
			if a[j] > k:
				if j != 0:
					l[c[j]] = 2
					d = 1
					k = max(k, b[j])
				else:
					l[c[j]] = 1
					k = max(k, b[j])
			else:
				l[c[j]] = 1
				k = max(k, b[j])
		else:
			l[c[j]] = 2
			k = max(k, b[j])
	if d == 0:
		print(-1)
	else:
		print(*l, sep=' ')


for j in range(int(input())):
	n = int(input())
	s = []
	ind = [int(0)] * n
	for i in range(n):
		s.append(tuple(list(map(int, input().split())) + [i]))
	s.sort()
	mx = max(s[0][0], s[0][1])
	ind[s[0][2]] = 1
	for i in range(1, len(s)):
		if mx < min(s[i][0], s[i][1]):
			break
		mx = max(s[i][0], s[i][1], mx)
		ind[s[i][2]] = 1
	if sum(ind) == n:
		print(-1, end=' ')
	else:
		for i in ind:
			print(i + 1, end=' ')
	print()


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
from io import FileIO, BytesIO
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdout = stream()
		if sys.version_info[0] < 3:
			sys.stdin = stream(sys.stdin.read())
			input = lambda : sys.stdin.readline().rstrip('\r\n')
			register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
		else:
			sys.stdin = BytesIO(FileIO(0).read())
			input = lambda : sys.stdin.readline().rstrip(b'\r\n')
			register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	for _ in range(int(input())):
		n = int(input())
		q = sorted([list(map(int, input().split())) + [i] for i in range(n)])
		t = [2] * n
		le = q[0][1]
		for (s, e, i) in q:
			if s > le:
				break
			t[i] = 1
			le = max(le, e)
		if t[q[-1][2]] == 1:
			print(-1)
			continue
		print(*t)
sync_with_stdio(False)
main()


import sys
T = int(input())
for _ in [0] * T:
	N = int(input())
	a = sorted((list(map(int, sys.stdin.readline().split())) + [i] for i in range(N)))
	ans = [0] * N
	group = 1
	first_max = a[0][1]
	for (l1, r1, i) in a:
		if group == 1 and first_max < l1:
			group = 2
		if first_max < r1:
			first_max = r1
		ans[i] = group
	if group == 2:
		print(*ans)
	else:
		print(-1)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	points = []
	for i in range(n):
		points.append((zzz(), i))
	points.sort()
	left = points[0][0][0]
	right = points[0][0][1]
	ok = 1
	ans = [0] * n
	for i in range(n):
		if points[i][0][0] > right:
			ok = 2
		ans[points[i][1]] = ok
		right = max(right, points[i][0][1])
	print(*(ans if ok - 1 else [-1]))


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for j in range(n):
		arr.append(tuple(map(int, (input() + ' ' + str(j)).split())))
	arr.sort()
	grp = [1 for j in range(n)]
	grp[n - 1] = 2
	pos = False
	highest = -1
	for j in range(n - 1):
		highest = max(highest, arr[j][1])
		if highest < arr[j + 1][0]:
			for k in range(j + 1, n):
				grp[k] = 2
			pos = True
	if not pos:
		print(-1)
	else:
		ans = [0 for j in range(n)]
		for j in range(n):
			ans[arr[j][2]] = grp[j]
		print(' '.join((str(i) for i in ans)))


def solve(n, lrs):
	elements = enumerate(lrs)
	elements = list(sorted(elements, key=lambda x: x[1][1]))
	(i, j) = (0, n - 1)
	g_1 = elements[i][1]
	g_2 = elements[j][1]
	a_group_index = [elements[i][0]]
	b_group_index = [elements[j][0]]
	while len(a_group_index) + len(b_group_index) < n:
		while i + 1 != j and g_1[1] >= elements[i + 1][1][0]:
			i += 1
			a_group_index.append(elements[i][0])
			g_1[1] = max(g_1[1], elements[i][1][1])
		while j - 1 != i and g_2[0] <= elements[j - 1][1][1]:
			j -= 1
			b_group_index.append(elements[j][0])
			g_2[0] = min(g_2[0], elements[j][1][0])
		if len(a_group_index) + len(b_group_index) == n:
			break
		i += 1
		a_group_index.append(elements[i][0])
		g_1[1] = max(g_1[1], elements[i][1][1])
	if g_1[1] >= g_2[0]:
		return '-1'
	r = [0] * n
	for e in a_group_index:
		r[e] = 1
	for e in b_group_index:
		r[e] = 2
	return ' '.join(map(str, r))
for _ in range(int(input())):
	n = int(input())
	lrs = [list(map(int, input().split())) for _ in range(n)]
	print(solve(n, lrs))


def intersect(seg, e):
	X1 = seg[0]
	X2 = seg[1]
	X3 = e[0]
	X4 = e[1]
	if max(X1, X2) < min(X3, X4):
		return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	l = [0] * n
	group = ['0'] * n
	for i in range(n):
		l[i] = list(map(int, input().split()))
		l[i].append(i)
	l.sort()
	seg1 = []
	seg2 = []
	for e in l:
		if not seg1:
			seg1 = [e[0], e[1]]
			group[e[2]] = '1'
		elif intersect(seg1, e):
			seg1 = [min(seg1[0], seg1[1], e[0], e[1]), max(seg1[0], seg1[1], e[0], e[1])]
			group[e[2]] = '1'
		elif not seg2:
			seg2 = [e[0], e[1]]
			group[e[2]] = '2'
		elif intersect(seg2, e):
			seg2 = [min(seg2[0], seg2[1], e[0], e[1]), max(seg2[0], seg2[1], e[0], e[1])]
			group[e[2]] = '2'
		elif not intersect(seg1, e) and (not intersect(seg2, e)):
			group[e[2]] = '2'
	if len(set(group)) == 1:
		print(-1)
	else:
		print(' '.join(group))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	lr = [(i,) + tuple(map(int, input().split())) for i in range(n)]
	lr.sort(key=lambda k: k[2])
	l_min = 10 ** 6
	for i in range(n - 1, 0, -1):
		l_min = min(l_min, lr[i][1])
		div = lr[i - 1][2]
		if div < l_min:
			ans = [0] * n
			for j in range(n):
				if j < i:
					ans[lr[j][0]] = 1
				else:
					ans[lr[j][0]] = 2
			print(*ans)
			break
	else:
		print(-1)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

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

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		matrix = []
		for i in range(n):
			take = inar()
			take.append(i)
			matrix.append(take)
		matrix.sort()
		res = [-1] * n
		count = 1
		res[matrix[0][2]] = 1
		low = matrix[0][0]
		high = matrix[0][1]
		for i in range(1, n):
			if low <= matrix[i][0] <= high or low <= matrix[i][1] <= high:
				res[matrix[i][2]] = 1
				low = min(low, matrix[i][0])
				high = max(high, matrix[i][1])
			else:
				res[matrix[i][2]] = 2
		if 1 in res and 2 in res:
			print(*res)
		else:
			print(-1)
main()


from operator import itemgetter
for t in range(int(input())):
	n = int(input())
	inpt = [0] * n
	arr = [0] * (2 * n)
	for i in range(0, 2 * n, 2):
		arr[i] = [0] * 2
		arr[i + 1] = [0] * 2
		inpt[i // 2] = [0] * 2
		(a, b) = map(int, input().split())
		inpt[i // 2][0] = a
		inpt[i // 2][1] = b
		arr[i][0] = a
		arr[i + 1][0] = b
		arr[i][1] = 1
		arr[i + 1][1] = 2
	arr = sorted(arr, key=itemgetter(0))
	i = 0
	end = -1
	ct = 0
	while i < 2 * n:
		if i != 0 and ct == 0:
			i = -1
			break
		if arr[i][1] == 1:
			ct += 1
		if arr[i][1] == 2:
			end = arr[i][0]
			ct -= 1
		while i < 2 * n - 1 and arr[i][0] == arr[i + 1][0]:
			if arr[i + 1][1] == 1:
				ct += 1
			if arr[i + 1][1] == 2:
				end = arr[i][0]
				ct -= 1
			i += 1
		i += 1
	if i != -1:
		print(-1)
	else:
		for i in range(n):
			if inpt[i][1] <= end:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()


def do_intersect(a, b):
	return min(a[1], b[1]) >= max(a[0], b[0])
for _ in range(int(input())):
	n = int(input())
	inps = [tuple(map(int, input().split())) for _ in range(n)]
	org = [pair for pair in inps]
	inps.sort()
	sets = [inps[0]]
	for i in range(1, n):
		merged = False
		for j in range(len(sets)):
			if do_intersect(sets[j], inps[i]):
				new_set = (min(inps[i][0], sets[j][0]), max(inps[i][1], sets[j][1]))
				sets[j] = new_set
				merged = True
				break
		if not merged:
			sets.append(inps[i])
	if len(sets) == 1:
		print(-1)
	else:
		ans = []
		for inp in org:
			if do_intersect(inp, sets[0]):
				ans.append(1)
			else:
				ans.append(2)
		print(*ans)


class Pair:

	def __init__(self, s, i):
		b = s.split(' ')
		self.left = int(b[0])
		self.right = int(b[1])
		self.num = i
		self.group = 0
t = int(input())
for j in range(0, t):
	n = int(input())
	arr = []
	for i in range(0, n):
		arr.append(Pair(input(), i))
	arr1 = arr.copy()
	arr.sort(key=lambda c: c.right)
	minSuf = [None] * n
	for (i, e) in reversed(list(enumerate(arr))):
		arr[i].group = 2
		if i < n - 1:
			minSuf[i] = min(e.left, minSuf[i + 1])
		else:
			minSuf[i] = e.left
		if i > 0 and arr[i - 1].right < minSuf[i]:
			for k in range(0, i):
				arr[k].group = 1
			break
	if arr[0].group == 2:
		print(-1, end=' ')
	else:
		for p in arr1:
			print(p.group, end=' ')
	print()


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

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

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

def S():
	return list(map(str, input().strip()))

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby
from itertools import permutations as comb

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a):
	print('? {}'.format(a), flush=True)
	n = I()
	return n

def dfs(i, p):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	if n > 2:
		l.append(n)
	return l
t = I()
for _ in range(t):
	s = []
	n = I()
	d = defaultdict(lambda : 0)
	d2 = defaultdict(lambda : 0)
	for q in range(n):
		s.append(lint())
	c = s.copy()
	s.sort()
	end = 0
	cnt = 0
	for tmp in s:
		(x, y) = tmp
		if x > end:
			cnt += 1
			end = y
		else:
			end = max(y, end)
		d[x, y] = cnt % 2 + 1
		d2[d[x, y]] = 1
	if d2[1] and d2[2]:
		for tmp in c:
			(x, y) = tmp
			print(d[x, y], end=' ')
		print()
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	ra = []
	mn = [1] * n
	for i in range(n):
		(x, y) = map(int, input().split())
		ra.append((x, y, i))
	ra.sort()
	l = ra[0][0]
	r = ra[0][1]
	g = 1
	for i in ra:
		if i[0] > r:
			g = 2
		mn[i[2]] = g
		r = max(i[1], r)
	print(*mn) if len(set(mn)) > 1 else print(-1)


for _ in range(int(input())):
	n = int(input())
	data = []
	for q in range(n):
		(x, y) = map(int, input().split())
		data.append([x, y, q])
	data.sort()
	ans = [-1] * n
	ans[data[0][2]] = 0
	pivot = 0
	prev = data[0][1]
	for q in range(1, n):
		if data[q][0] <= prev:
			ans[data[q][2]] = ans[data[q - 1][2]]
			prev = max(prev, data[q][1])
		else:
			pivot = (pivot + 1) % 2
			ans[data[q][2]] = pivot
			prev = data[q][1]
	minus_cnt = ans.count(-1)
	if minus_cnt != 0:
		print(-1)
	elif len(set(ans)) == 1:
		print(-1)
	else:
		for q in ans:
			print(q + 1, end=' ')
		print()


import sys
import bisect
input = sys.stdin.readline
t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		x = list(map(int, input().split()))
		x.append(i)
		l.append(x)
	l.sort()
	maxi = l[0][1]
	ind = -1
	for i in range(1, n):
		if maxi < l[i][0]:
			ind = i
			break
		maxi = max(maxi, l[i][1])
	if ind == -1:
		print(-1)
	else:
		g = [0] * (n + 1)
		for i in range(ind):
			g[l[i][2] + 1] = 1
		for i in range(ind, n):
			g[l[i][2] + 1] = 2
		print(*g[1:])


import sys
t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		(l, r) = map(int, sys.stdin.readline().split())
		a.append([l, r, j])
	c = [2] * n
	a.sort()
	j = 0
	m1 = a[0][1]
	while j < n:
		p = a[j][0]
		q = a[j][1]
		if p <= m1:
			m1 = max(m1, q)
			c[a[j][2]] = 1
		else:
			break
		j = j + 1
	if 2 not in c:
		print(-1)
	else:
		print(' '.join(map(str, c)))


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

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

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if testingMode:
		print(args)

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

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

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

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

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

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = True
testingMode = False
optimiseForReccursion = False

def is_Valid(a, b):
	x = min(a, b)
	y = max(a, b)
	diff = y - x
	y = y - 2 * diff
	x = x - 1 * diff
	if x >= 0 and y >= 0 and (x % 3 == 0) and (y % 3 == 0):
		return True
	return False

def main():
	n = get_int()
	mat = [list(map(int, input().split())) for _ in range(n)]
	org_indexes = [i[0] for i in sorted(enumerate(mat), key=lambda x: x[1])]
	mat.sort()
	res = [2 for _ in range(n)]
	end = mat[0][1]
	x = 0
	for li in mat:
		if end < li[0]:
			for i in org_indexes[0:x]:
				res[i] = 1
			display_list(res)
			return
		end = max(end, li[1])
		x += 1
	print(-1)
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

class segm:

	def __init__(self, l, r, index):
		self.l = l
		self.r = r
		self.id = index
		self.g = None

	def set_group(self, g):
		self.g = g

def main():
	q = int(stdin.readline())
	for _ in range(q):
		n = int(stdin.readline())
		res = [1] * n
		a = []
		for i in range(n):
			(l, r) = [int(x) for x in stdin.readline().split()]
			a.append(segm(l, r, i))
		a.sort(key=lambda seg: seg.l * 10000000 + seg.r)
		a[0].set_group(1)
		res[a[0].id] = 1
		for i in range(1, n):
			seg = a[i]
			if seg.l <= a[i - 1].r:
				seg.set_group(a[i - 1].g)
			else:
				seg.set_group(2)
			res[seg.id] = seg.g
			seg.r = max(seg.r, a[i - 1].r)
		if a[n - 1].g == 1:
			res = [-1]
		stdout.write(' '.join([str(x) for x in res]) + '\n')
	return 0
main()


T = int(input())
for i in range(T):
	n = int(input())
	X = []
	for j in range(n):
		(l, r) = map(int, input().split())
		X.append([j, l, r])
	X = sorted(X, key=lambda x: x[1])
	Y = ['2'] * n
	s = -1
	rmax = X[0][2]
	Y[X[0][0]] = '1'
	for i in range(1, n):
		if X[i][1] > rmax:
			s = i
			break
		rmax = max(rmax, X[i][2])
		Y[X[i][0]] = '1'
	if s < 0:
		print(-1)
	else:
		print(' '.join(Y))


import sys
q = int(input())
for i in range(0, q):
	n = int(input())
	l = []
	r = []
	for j in range(0, n):
		(l1, r1) = map(int, input().split())
		l += [l1]
		r += [(l1, r1)]
	r.sort()
	l1 = -1
	rm = -1
	for j in range(0, n - 1):
		if r[j][1] > rm:
			rm = r[j][1]
		if rm < r[j + 1][0]:
			l1 = r[j + 1][0]
			break
	if l1 == -1:
		print(-1, end='')
	else:
		for j in range(0, n):
			if l[j] < l1:
				print(1, end=' ')
			else:
				print(2, end=' ')
	print()


t = int(input())
for test in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		(l, r) = map(int, input().split())
		arr.append([l, r, i])
	arr = sorted(arr, key=lambda item: item[0])
	i = 1
	ans = [0] * n
	ans[arr[0][2]] = 1
	mm = arr[0][1]
	f = 0
	while i < n:
		mm = max(arr[i - 1][1], mm)
		if arr[i][0] <= mm and f != 1:
			ans[arr[i][2]] = 1
		else:
			f = 1
			ans[arr[i][2]] = 2
		i += 1
	if f == 0:
		print(-1)
	else:
		for i in ans:
			print(i, end=' ')
		print()


q = int(input())
for i in range(q):
	n = int(input())
	arr = [0 for i in range(n)]
	for i in range(n):
		temp = list(map(int, input().split()))
		temp.append(i)
		arr[i] = temp
	arr = sorted(arr, key=lambda l: l[0])
	ans = [1 for i in range(n)]
	yoyo = -1
	maxa = arr[0][1]
	for i in range(1, n):
		if arr[i][0] > maxa:
			yoyo = i
			break
		if arr[i][1] > maxa:
			maxa = arr[i][1]
	if yoyo == -1:
		print(-1)
		continue
	else:
		for i in range(yoyo, n):
			ans[arr[i][2]] = 2
	for i in range(n):
		print(ans[i], end=' ')
	print()


t = int(input())
for i in range(t):
	(n, intersections, curr_group) = (int(input()), 0, 1)
	l = [[[int(x) for x in input().split()], i, curr_group] for i in range(n)]
	l.sort(key=lambda x: x[0])
	current_group_max = l[0][0][1]
	for i in range(1, n):
		if current_group_max >= l[i][0][0]:
			intersections += 1
		else:
			curr_group = curr_group % 2 + 1
		l[i][2] = curr_group
		current_group_max = max(current_group_max, l[i][0][1])
	if intersections == n - 1:
		print(-1)
	else:
		l.sort(key=lambda x: x[1])
		print(' '.join([str(i[2]) for i in l]))


for _ in range(int(input())):
	q = int(input())
	lst = []
	for c in range(q):
		(a, b) = map(int, input().split())
		lst.append([a, b, c])
	lst.sort()
	p = -1
	m = lst[0][1]
	for c in range(len(lst) - 1):
		m = max(m, lst[c][1])
		if m < lst[c + 1][0]:
			p = c
			break
	if p == -1:
		print('-1')
	else:
		lst2 = [2 for r in range(len(lst))]
		for r in range(p + 1):
			lst2[lst[r][2]] = 1
		print(*lst2)


t = int(input())
for _ in range(t):
	n = int(input())
	segments = []
	for i in range(n):
		(l, r) = map(int, input().split())
		segments.append([l, r, i])
	segments.sort()
	ans = [1 for i in range(n)]
	prev = 1
	maxR = 0
	ansOfMaxR = 1
	for i in range(n):
		(cl, cr, ci) = segments[i]
		if i == 0:
			maxR = cr
			ans[ci] = 1
			prev = 1
			ansOfMaxR = 1
		else:
			if cl > maxR:
				if ansOfMaxR == 1:
					ans[ci] = 2
					prev = 2
				elif ansOfMaxR == 2:
					ans[ci] = 1
					prev = 1
			else:
				ans[ci] = ansOfMaxR
				prev = ansOfMaxR
			if cr > maxR:
				maxR = cr
				ansOfMaxR = ans[ci]
	if len(set(ans)) == 2:
		print(*ans)
	else:
		print(-1)


query = int(input())
for _ in range(query):
	n = int(input())
	array = []
	for i in range(n):
		(a, b) = map(int, input().split())
		array.append([a, b, i])
	array.sort()
	max1 = array[0][1]
	flag = False
	answer = [0] * n
	answer[array[0][2]] = 1
	for i in range(1, n):
		if not flag and array[i][0] <= max1:
			max1 = max(max1, array[i][1])
			answer[array[i][2]] = 1
		else:
			flag = True
			answer[array[i][2]] = 2
	if not flag:
		print(-1)
	else:
		print(*answer)


def C():
	q = int(input())
	for _ in range(q):
		n = int(input())
		tuples = []
		for i in range(n):
			ab = [int(x) for x in input().split()]
			tuples.append((ab[0], ab[1], i))
		tuples.sort()
		sol = ['-1'] * n
		r_act = tuples[0][1]
		flag = 0
		for (l, r, i) in tuples:
			if flag == 0:
				if l <= r_act:
					r_act = max(r, r_act)
					sol[i] = '1'
				else:
					r_act = r
					sol[i] = '2'
					flag = 1
			if flag == 1:
				if l <= r_act:
					r_act = max(r, r_act)
					sol[i] = '2'
				else:
					r_act = r
					sol[i] = '1'
					flag = 0
		if '-1' in sol or '1' not in sol or '2' not in sol:
			print(-1)
			continue
		print(' '.join(sol))
C()


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(mapi()) + [i])
	a.sort()
	r1 = 0
	r2 = 0
	r1 += 1
	pre1 = a[0][1]
	res = [2] * n
	res[a[0][2]] = 1
	f = 0
	for (st, ed, i) in a[1:]:
		if pre1 < st:
			f = 1
			break
		else:
			pre1 = max(pre1, ed)
			res[i] = 1
	if f:
		print(*res)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	lrs = sorted((list(map(int, input().split())) + [__] for __ in range(n)))
	ans = [0] * n
	group = 1
	up_lim = lrs[0][1]
	for (l, r, i) in lrs:
		if group == 1:
			group = 2 if l > up_lim else group
			up_lim = r if r > up_lim else up_lim
		ans[i] = group
	if group != 2:
		print(-1)
	else:
		print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	sobs = []
	for j in range(n):
		(a, b) = map(int, input().split())
		sobs.append([[a, -1], j])
		sobs.append([[b, 1], j])
	sobs.sort()
	counts = 0
	passed = []
	success = []
	alls = [0 for q in range(n)]
	succeed = False
	for sob in sobs:
		if succeed:
			if sob[0][1] == -1:
				pass
			else:
				success.append(sob[1])
			continue
		if sob[0][1] == -1:
			counts += 1
		else:
			counts -= 1
			passed.append(sob[1])
			if counts == 0:
				succeed = True
	if succeed and success:
		for a in passed:
			alls[a] = 1
		for b in success:
			alls[b] = 2
		print(*alls)
	else:
		print(-1)


for _ in [0] * int(input()):
	n = int(input())
	t = [2] * n
	m = g = 0
	for (l, r, i) in sorted(([*map(int, input().split()), i] for i in range(n))):
		g += l > m
		m = max(m, r)
		t[i] -= g & 1
	print(*(t, [-1])[g < 2])


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

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

def li():
	return list(mi())
for _ in range(ii()):
	n = ii()
	a = [li() + [i] for i in range(n)]
	a.sort()
	ans = [2] * n
	pr = a[0][0]
	for (l, r, i) in a:
		if l > pr:
			break
		ans[i] = 1
		pr = max(pr, r)
	if 2 in ans:
		print(*ans)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	n = int(input())
	seg = []
	for s in range(n):
		(l, r) = [int(x) for x in input().split()]
		seg.append((l, r))
	pos = {}
	for i in range(n):
		if seg[i] in pos:
			pos[seg[i]].append(i)
		else:
			pos[seg[i]] = [i]
	seg.sort()
	right = seg[0][1]
	goodindex = -1
	for j in range(1, n):
		if seg[j][0] > right:
			goodindex = j
			break
		right = max(right, seg[j][1])
	if goodindex == -1:
		print(-1)
	else:
		ans = ['2'] * n
		for i in range(goodindex):
			ans[pos[seg[i]][-1]] = '1'
			pos[seg[i]].pop()
		print(' '.join(ans))


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = dict()
	for i in range(n):
		r = [int(x) for x in stdin.readline().split()]
		arr[i] = r
	keys = list(arr.keys())
	keys.sort(key=lambda x: arr[x][0])
	ans = [0 for i in range(n)]
	ma = arr[keys[0]][1]
	end = -1
	for i in range(1, n):
		j = keys[i]
		k = keys[i - 1]
		if arr[j][0] > ma:
			end = i
			break
		elif arr[j][1] > ma:
			ma = arr[j][1]
	if end == -1:
		stdout.write('-1 \n')
	else:
		for i in range(n):
			if i < end:
				ans[keys[i]] = '1'
			else:
				ans[keys[i]] = '2'
		stdout.write(' '.join(ans) + '\n')


t = int(input())
final = []
for k in range(t):
	n = int(input())
	skl = []
	for i in range(n):
		(a, b) = map(int, input().split())
		skl.append((a, -1, i))
		skl.append((b, 1, i))
	skl.sort()
	m = 0
	ans = ['0'] * n
	for (i, p) in enumerate(skl):
		if m == 0 and i != 0:
			for j in range(i, 2 * n):
				ans[skl[j][2]] = '2'
			break
		m -= p[1]
		if p[1] == -1:
			ans[skl[i][2]] = '1'
	if not '2' in ans:
		final.append('-1')
	else:
		final.append(' '.join(ans))
print('\n'.join(final))


import sys
from atexit import register
from io import FileIO, StringIO
input = iter(FileIO(0).read().decode().splitlines()).__next__
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	for _ in range(int(input())):
		n = int(input())
		q = sorted([list(map(int, input().split())) + [i] for i in range(n)])
		t = [2] * n
		le = q[0][1]
		for (s, e, i) in q:
			if s > le:
				break
			t[i] = 1
			le = max(le, e)
		if t[q[-1][2]] == 1:
			print(-1)
			continue
		print(*t)
main()


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

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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	N = ii()
	ar = [li() + [i] for i in range(N)]
	ar.sort()
	last = ar[0][0]
	ans = [2] * N
	for (l, r, i) in ar:
		if l > last:
			break
		ans[i] = 1
		last = max(last, r)
	if 2 in ans:
		print(*ans)
	else:
		print(-1)


from sys import stdin
t = int(input())
for _ in range(t):
	n = int(input())
	l = [list(map(int, stdin.readline().split())) + [i] for i in range(n)]
	l.sort()
	rb = l[0][1]
	res = [1] * n
	res[l[0][2]] = 2
	flag = False
	for v in l[1:]:
		if v[0] > rb:
			flag = True
			break
		else:
			rb = max(rb, v[1])
			res[v[2]] = 2
	if not flag:
		print(-1)
	else:
		print(*res)


t = int(input())
for _ in range(t):
	n = int(input())
	x = []
	for i in range(n):
		(l, r) = map(int, input().split())
		x.append((l, r, i))
	x.sort()
	e = x[0][0]
	g = ['2'] * n
	done = False
	res = ''
	for y in x:
		if e < y[0]:
			done = True
			break
		e = max(e, y[1])
		g[y[2]] = '1'
	if not done:
		print(-1)
	else:
		print(' '.join(g))


t = int(input())
while t:
	d = []
	lol = 0
	lo = 0
	prev = 0
	ind = -1
	cou = 0
	n = int(input())
	for i in range(n):
		(l, r) = map(int, input().split())
		d.append((l, r))
	d1 = sorted(d)
	for i in d1:
		(l, r) = (i[0], i[1])
		cou += 1
		if cou == 1:
			l1 = l
			r1 = r
		elif r < l1 or (l > r1 and ind == -1):
			if r < l1:
				ind = l1
			else:
				ind = l
		else:
			l1 = min(l, l1)
			r1 = max(r, r1)
	cou = 0
	if ind == -1:
		print(-1, end=' ')
	else:
		for i in d:
			if i[0] <= ind - 1 and i[1] <= ind - 1:
				print(1, end=' ')
			else:
				print(2, end=' ')
	print()
	t -= 1


t = int(input())
for test in range(t):
	n = int(input())
	ans = ['1' for i in range(n)]
	(start, end) = (dict(), dict())
	for i in range(n):
		(a, b) = list(map(int, input().split()))
		if a in start:
			start[a].append(i + 1)
		else:
			start[a] = [i + 1]
		if i + 1 in end:
			end[i + 1].append(b)
		else:
			end[i + 1] = [b]
	st_sorted = sorted(list(start.keys()))
	m = 0
	ok = False
	ans_pos = -1
	for pos in range(len(st_sorted) - 1):
		for i in start[st_sorted[pos]]:
			m = max(m, max(end[i]))
		if m < st_sorted[pos + 1]:
			ok = True
			ans_pos = pos
			break
	if ok:
		for i in range(pos + 1, len(st_sorted)):
			for pos in start[st_sorted[i]]:
				ans[pos - 1] = '2'
		print(' '.join(ans))
	else:
		print(-1)


import sys
test = int(input())
for irene in range(test):
	a = []
	n = int(input())
	ans = ['1'] * n
	for i in range(n):
		a.append((*map(int, input().split()), i))
	a.sort()
	(tnt, mn) = (-1, 0)
	for (l, r, i) in a:
		if l > mn:
			tnt += 1
		mn = max(mn, r)
		if tnt % 2:
			ans[i] = '2'
	if tnt == 0:
		print(-1)
	else:
		print(' '.join(ans))


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append([x, y, i])
	a.sort()
	g1 = a[0][0]
	g11 = a[0][1]
	g2 = a[1][0]
	g22 = a[1][1]
	b = [0] * n
	z = a[-1][2]
	b[z] = 2
	maxr = -1
	f = False
	for i in range(n - 1):
		(x, y, z) = (a[i][0], a[i][1], a[i][2])
		b[z] = 1
		maxr = max(maxr, y)
		if maxr < a[i + 1][0]:
			f = True
			break
	if not f:
		print(-1)
	else:
		for j in range(i + 1, n):
			z = a[j][2]
			b[z] = 2
		print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append((a, 0, i))
		l.append((b, 1, i))
	g = sorted(range(n))
	l.sort(key=lambda x: x[0])
	t = [2 for i in range(n)]
	k = 0
	test = 0
	count = 0
	indice = i
	start = 0
	h = 0
	for i in range(2 * n):
		if l[i][1] == 0:
			k += 1
		else:
			k -= 1
		if k == 0 and i < 2 * n - 1:
			if l[i + 1] == l[i]:
				start += 1
			else:
				start == 0
		if start == 2:
			test == 0
			break
	for i in range(2 * n):
		if l[i][1] == 0:
			k += 1
		else:
			k -= 1
		if k == 0 and i < 2 * n - 1 and (l[i + 1] > l[i]):
			test = 1
			indice = i
			break
		if count == 2:
			test = 0
			break
	if test == 0:
		print(-1)
	else:
		for j in range(indice):
			t[l[j][2]] = 1
		print(*t, sep=' ')


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	pts = []
	for i in range(n):
		(a, b) = map(int, input().split())
		pts.append((a, b, i))
	pts = sorted(pts)
	mark = [1 for i in range(n)]
	ok = 0
	mi = pts[0][0]
	ma = pts[0][1]
	for i in range(n - 1):
		if ok:
			mark[pts[i + 1][2]] = 2
			continue
		seg1 = pts[i + 1]
		if max(seg1[0], mi) > min(seg1[1], ma):
			mark[seg1[2]] = 2
			ok = 1
		else:
			mi = min(mi, seg1[0])
			ma = max(ma, seg1[1])
	if not ok:
		print(-1)
	else:
		print(*mark)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	segs = []
	for n in range(N):
		(L, R) = getInts()
		segs.append((L, R, n))
	segs.sort()
	ans = [0] * N
	curr_max = -10 ** 9
	curr = 1
	flag = False
	for (L, R, n) in segs:
		if L > curr_max and flag:
			curr = 2
		flag = True
		curr_max = max(curr_max, R)
		ans[n] = curr
	if sum(ans) == N:
		print(-1)
		return
	print(*ans)
	return
for _ in range(getInt()):
	solve()


def solution(x):
	distrib = [-1] * len(x)
	distrib[x[0][2]] = 1
	maxR = x[0][1]
	k = 1
	while k < len(x) and x[k][0] <= maxR:
		distrib[x[k][2]] = 1
		maxR = max(maxR, x[k][1])
		k += 1
	if k == len(x):
		return [-1]
	for i in range(k, len(x)):
		distrib[x[i][2]] = 2
	return distrib
T = int(input())
for _ in range(T):
	N = int(input())
	x = []
	for i in range(N):
		(L, R) = map(int, input().split())
		x.append((L, R, i))
	x.sort()
	d = solution(x)
	print(*d)


import sys
input = sys.stdin.readline
Q = int(input())
for test in range(Q):
	n = int(input())
	LR = [list(map(int, input().split())) + [i] for i in range(n)]
	LR.sort()
	GR1 = [LR[0][0], LR[0][1]]
	for i in range(1, n):
		(l, r, _) = LR[i]
		if r < GR1[0] or l > GR1[1]:
			ANS = i
			break
		else:
			GR1 = [min(GR1[0], l), max(GR1[1], r)]
	else:
		print(-1)
		continue
	ANSLIST = [1] * n
	for j in range(ANS, n):
		ANSLIST[LR[j][2]] = 2
	for a in ANSLIST:
		print(a, end=' ')
	print()


for l00p in range(int(input())):
	a = []
	ans = []
	for i in range(int(input())):
		ans.append(1)
		a.append(tuple(list((int(x) for x in input().split())) + [i]))
	a.sort(key=lambda tup: tup[0])
	flag = 0
	NO = 1
	right = a[0][1]
	for (l, r, pos) in a:
		if flag:
			ans[pos] = 2
			continue
		if l > right:
			ans[pos] = 2
			flag = 1
			NO = 0
		right = max(right, r)
	if NO:
		print(-1)
	else:
		for i in ans:
			print(i, end=' ')
		print()


import math
sa = lambda : input()
sb = lambda : int(input())
sc = lambda : input().split()
sd = lambda : list(map(int, input().split()))
se = lambda : float(input())
sf = lambda : list(input())

def hnbhai():
	n = sb()
	a = []
	for i in range(n):
		(x, y) = sd()
		a.append([x, y, i])
	a.sort()
	i = 0
	max_ = a[i][1]
	ans = ['1'] * n
	while i < n and max_ >= a[i][0]:
		max_ = max(max_, a[i][1])
		ans[a[i][2]] = '2'
		i += 1
	if ans.count('1'):
		print(*ans)
	else:
		print(-1)
for _ in range(sb()):
	hnbhai()


from sys import stdin
inp = lambda : stdin.readline().split()
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	mas = [tuple(map(int, inp())) for i in range(n)]
	d = {}
	for (i, x) in enumerate(mas):
		if d.get(x) == None:
			d[x] = []
		d[x].append(i)
	lst = sorted(mas)
	(res, k) = ([1] * n, 0)
	res[d[lst[0]].pop()] = 2
	(k, last) = (0, lst[0][1])
	for (i, x) in enumerate(lst[1:]):
		if last < x[0]:
			k = 1
			break
		last = max(last, x[1])
		res[d[x].pop()] = 2
	if k == 0:
		print(-1)
	else:
		print(*res)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = [2] * n
	l = []
	for i in range(n):
		l.append(I() + [i])
	l.sort()
	mn = l[0][0]
	mx = l[0][1]
	i = 0
	while i < n and l[i][0] <= mx:
		mx = max(mx, l[i][1])
		a[l[i][2]] = 1
		i += 1
	if all([i == 1 for i in a]) or all([i == 2 for i in a]):
		print(-1)
	else:
		print(*a)


T = int(input())
for _ in range(T):
	N = int(input())
	ls = sorted([list(map(int, input().split())) + [i] for i in range(N)])
	group = 1
	ans = [0] * N
	mx = ls[0][1]
	for (l, r, i) in ls:
		if group == 1 and l > mx:
			group = 2
		else:
			mx = max(r, mx)
		ans[i] = group
	if group == 1:
		print(-1)
	else:
		print(*ans)


from itertools import *
for _ in [0] * int(input()):
	n = int(input())
	a = sorted(chain(*(zip(map(int, input().split()), (i, n)) for i in range(n))))
	g = c = 0
	t = [2] * n
	for (x, i) in a:
		if i < n:
			c += 1
			g += c == 1
			t[i] -= g % 2
		else:
			c -= 1
	if g < 2:
		t = (-1,)
	print(*t)


from sys import stdin
t = int(input())
res = []
for _ in range(t):
	n = int(input())
	xs = [list(map(int, stdin.readline().strip().split())) + [i] for i in range(n)]
	xs.sort()
	rs = [1] * n
	q = 1
	(ml, mr) = (0, xs[0][1])
	for (l, r, i) in xs:
		if q == 1 and l <= mr:
			mr = max(mr, r)
		elif q == 1:
			q = 2
		rs[i] = q
	if q == 1:
		rs = [-1]
	res.append(' '.join(map(str, rs)))
print('\n'.join(res))


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	x = int(input())
	a = [list(map(int, input().split())) + [j] for j in range(x)]
	a.sort()
	g1 = 0
	ans = [0] * x
	g1 = a[0][1]
	ans[a[0][2]] = 1
	for j in range(1, x):
		if g1 < a[j][0]:
			ans[a[j][2]] = 2
			break
		else:
			g1 = max(a[j][1], g1)
			ans[a[j][2]] = 1
	else:
		print(-1)
		continue
	for k in range(j, x):
		ans[a[k][2]] = 2
	print(*ans)


T = int(input())
for t in range(T):
	l = []
	N = int(input())
	ans = [0] * N
	for n in range(N):
		(a, b) = map(int, input().split())
		l.append((a, b, n))
	l.sort()
	ans[l[0][2]] = 1
	MAX = l[0][1]
	for i in range(1, N):
		if l[i][0] > MAX:
			break
		ans[l[i][2]] = 1
		MAX = max(MAX, l[i][1])
	else:
		print(-1)
		continue
	for i in range(i, N):
		ans[l[i][2]] = 2
	for i in ans:
		print(i, end=' ')
	print('')


T = int(input())
for i in range(T):
	a = []
	n = int(input())
	ans = [1] * n
	for j in range(n):
		(x, y) = map(int, input().split())
		a.append((x, y, j))
	a.sort()
	(l, r) = (a[0][0], a[0][1])
	seg = 1
	put = 1
	for j in range(1, n):
		if a[j][0] <= r:
			r = max(r, a[j][1])
			ans[a[j][2]] = put
		else:
			if put == 1:
				put = 2
			ans[a[j][2]] = put
			seg += 1
	if seg < 2:
		print(-1)
	else:
		print(*ans)


for _ in range(int(input())):
	a = []
	n = int(input())
	g = ['1'] * n
	for i in range(n):
		a.append((*map(int, input().split()), i))
	a.sort()
	gr = -1
	mm = 0
	for (l, r, i) in a:
		if l > mm:
			gr += 1
		mm = max(mm, r)
		if gr % 2:
			g[i] = '2'
	if gr == 0:
		print(-1)
	else:
		print(' '.join(g))


def solve(coords, ans):
	n = len(coords)
	coords1 = coords[:]
	coords1.sort()
	groups = []
	(min_val, max_val) = (coords1[0][0], coords1[0][1])
	for i in range(1, n):
		(x, y) = (coords1[i][0], coords1[i][1])
		if x <= max_val:
			max_val = max(max_val, y)
		elif len(groups) == 0:
			groups.append((min_val, max_val))
			min_val = x
			max_val = y
		else:
			max_val = max(max_val, y)
	groups.append((min_val, max_val))
	if len(groups) != 2:
		ans.append([-1])
		return
	ans1 = []
	for i in coords:
		(x, y) = (i[0], i[1])
		for j in range(2):
			(l, r) = (groups[j][0], groups[j][1])
			if x >= l and y <= r:
				ans1.append(j + 1)
				break
	ans.append(ans1)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		coords = []
		for j in range(n):
			(x, y) = map(int, input().split())
			coords.append((x, y))
		solve(coords, ans)
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()
main()


T = int(input())
for i in range(0, T):
	n = int(input())
	L = []
	dp = [0] * n
	for j in range(0, n):
		(l, r) = map(int, input().split())
		L.append((l, r, j))
	L = sorted(L)
	temp = -1
	ed = L[0][1]
	for j in range(1, len(L)):
		if L[j][0] > ed:
			temp = j
			break
		ed = max(ed, L[j][1])
	if temp == -1 or n == 1:
		print(-1)
	else:
		for j in range(0, len(L)):
			if j < temp:
				dp[L[j][2]] = 1
			else:
				dp[L[j][2]] = 2
		for j in range(0, n):
			print(dp[j], end=' ')
		print(' ')


def answer(n, p):
	p.sort(key=lambda x: x[0])
	l = [[p[0][0], p[0][1]]]
	ans = [2] * n
	ans[p[0][2]] = 1
	for i in range(1, n):
		if p[i][0] <= l[-1][1]:
			l[-1][1] = max(l[-1][1], p[i][1])
			if len(l) == 1:
				ans[p[i][2]] = 1
		else:
			l.append([p[i][0], p[i][1]])
	if len(l) == 1:
		return [-1]
	else:
		return ans
t = int(input())
for i in range(t):
	n = int(input())
	A = []
	for j in range(n):
		(s, e) = map(int, input().split())
		A.append([s, e, j])
	print(*answer(n, A))


T = int(input())
for _ in range(T):
	n = int(input())
	s = []
	for k in range(n):
		(l, r) = [int(i) for i in input().split()]
		s.append([l, 1, k])
		s.append([r, 2, k])
	s.sort()
	u = [2] * n
	o = set()
	for i in s:
		u[i[2]] = 1
		if i[2] not in o:
			o.add(i[2])
		else:
			o.remove(i[2])
		if not o:
			if i != s[-1]:
				print(*u)
				break
	else:
		print(-1)


for _ in [0] * int(input()):
	n = int(input())
	a = []
	for i in range(n):
		a += zip(map(int, input().split()), (i, n))
	a.sort()
	g = c = 0
	t = [2] * n
	for (x, i) in a:
		if i < n:
			c += 1
			g += c == 1
			t[i] -= g % 2
		else:
			c -= 1
	if g < 2:
		t = (-1,)
	print(*t)


import collections
import time
import os
import sys
import bisect
import heapq

def solve(N, A):
	A.sort()
	i = 0
	(l, r) = (A[0][0], A[0][1])
	while i + 1 < N:
		if A[i + 1][0] <= r:
			r = max(r, A[i + 1][1])
		else:
			ans = [0] * N
			for j in range(i + 1):
				ans[A[j][2]] = 1
			for j in range(i + 1, N):
				ans[A[j][2]] = 2
			return ' '.join(map(str, ans))
		i += 1
	return '-1'
T = int(input())
ans = []
for ti in range(T):
	N = int(input())
	segs = []
	for i in range(N):
		(l, r) = map(int, input().split())
		segs.append((l, r, i))
	ans.append(solve(N, segs))
print('\n'.join(ans))


T = int(input())
for i in range(T):
	n = int(input())
	seg = []
	for i in range(n):
		seg.append([int(i) for i in input().split()] + [i])
	seg.sort()
	gp = [1] * n
	ans = [-1] * n
	end = seg[0][1]
	for i in range(n):
		if seg[i][0] <= end:
			gp[i] = gp[i - 1]
		else:
			gp[i] = gp[i - 1] + 1
		end = max(seg[i][1], end)
		ans[seg[i][2]] = gp[i]
	if gp[-1] == 1:
		print(-1)
	else:
		for x in ans:
			if x == 1:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()


import sys
input = sys.stdin.readline
from math import *
t = int(input())
y = t
while t > 0:
	t -= 1
	p = {}
	s1 = 0
	s2 = 0
	q = []
	n = int(input())
	flag = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		q.append([l, r, i])
	q.sort()
	f1 = [q[0][0], q[0][1]]
	p[q[0][2]] = 1
	for i in range(1, n):
		l = q[i][0]
		r = q[i][1]
		if f1[0] <= l <= f1[1] or f1[0] <= r <= f1[1] or (l < f1[0] and r > f1[1]):
			f1[0] = min(f1[0], l)
			f1[1] = max(r, f1[1])
			p[q[i][2]] = 1
			s1 += 1
		else:
			p[q[i][2]] = 2
			s2 += 1
	if s2 == 0:
		print(-1)
		continue
	for i in range(n):
		print(p[i], end=' ')
	print()


q = int(input())
qarr = []
for i in range(0, q):
	intnum = int(input())
	intnumarr = []
	for j in range(0, intnum):
		size = input()
		size = size.split()
		for k in range(0, 2):
			size[k] = int(size[k])
		size.append(j)
		intnumarr.append(size)
	qarr.append(intnumarr)
for i in range(0, q):
	workarr = qarr[i]
	workarr.sort()
	workarr[0].append(1)
	x = 0
	end = workarr[0][1]
	for j in range(1, len(workarr)):
		if workarr[j][0] <= end:
			workarr[j].append(x % 2 + 1)
		else:
			x += 1
			workarr[j].append(x % 2 + 1)
		if workarr[j][3] == workarr[j - 1][3]:
			end = max(workarr[j][1], end)
		else:
			end = workarr[j][1]
	y = 0
	for j in range(0, len(workarr)):
		if workarr[j][3] == 1:
			y += 1
		else:
			pass
	if y == len(workarr):
		print('-1')
	else:
		for j in range(0, len(workarr)):
			workarr[j][0] = workarr[j][2]
		workarr.sort()
		for j in range(0, len(workarr)):
			print(workarr[j][3], end=' ')
print('')


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	f = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		a.append([l, r, i])
	a.sort(key=lambda x: x[0])
	rm = a[0][1]
	for i in range(n):
		if a[i][0] > rm:
			b = a[i]
			f = 1
			break
		if a[i][1] > rm:
			rm = a[i][1]
	if f == 0:
		print(-1)
	else:
		a.sort(key=lambda x: x[2])
		for i in range(n):
			if a[i][0] < b[0]:
				print(1, end=' ')
			else:
				print(2, end=' ')
	print()


import bisect
for _ in range(int(input())):
	n = int(input())
	arr = []
	seg = [0] * n
	cs = 1
	for i in range(n):
		a = list(map(int, input().split()))
		a.append(i)
		bisect.insort(arr, a)
	seg[arr[0][2]] = 1
	pm = arr[0][1]
	for i in range(1, n):
		if arr[i][0] <= pm:
			pm = max(pm, arr[i][1])
			seg[arr[i][2]] = cs
		else:
			cs = 2
			seg[arr[i][2]] = cs
	if len(set(seg)) != 2:
		print('-1')
	else:
		print(*seg)


def add(Dict, key, value):
	if key in Dict:
		Dict[key].append(value)
	else:
		Dict[key] = [value]

def Coloring(n, data):
	assert n == len(data), 'Error parsing data and its length'
	allCord = set()
	opening = dict()
	closing = dict()
	reference = dict()
	for i in range(n):
		allCord.add(data[i][0])
		allCord.add(data[i][1])
		reference[data[i][0]] = i
		reference[data[i][1]] = i
		add(opening, data[i][0], i)
		add(closing, data[i][1], i)
	cord = list(allCord)
	cord.sort()
	groups = []
	curGroup = []
	active = set()
	for i in range(len(cord)):
		curCord = cord[i]
		op = []
		if curCord in opening:
			op = opening[curCord]
		for elem in op:
			active.add(elem)
			curGroup.append(elem)
		cl = []
		if curCord in closing:
			cl = closing[curCord]
		for elem in cl:
			active.remove(elem)
		if not bool(active):
			groups.append(curGroup)
			curGroup = []
	if len(groups) <= 1:
		print('-1')
	else:
		colors = [None] * n
		for elem in groups[0]:
			colors[elem] = 1
		for i in range(1, len(groups)):
			for elem in groups[i]:
				colors[elem] = 2
		for i in range(n):
			print(colors[i], end=' ')
		print()

def SolveProblemC():
	T = int(input())
	for queries in range(T):
		n = int(input())
		segment_data = []
		for segment in range(n):
			(l, r) = map(int, input().split())
			segment_data.append([l, r])
		Coloring(n, segment_data)
SolveProblemC()


t = int(input())
for _ in range(t):
	(a, d, f) = ([], dict(), 0)
	n = int(input())
	a = [list(map(int, input().split())) for _ in range(n)]
	b = sorted(a)
	cur = b[0][1]
	for (l, r) in b:
		if l > cur:
			f = 1
			break
		else:
			d[l, r] = 1
			if r > cur:
				cur = r
	if not f:
		print(-1)
	else:
		for (l, r) in a:
			if (l, r) in d:
				print('1 ', end='')
			else:
				print('2 ', end='')
		print()


for c in range(int(input())):
	N = int(input())
	counter = 0
	segments = []
	for n in range(N):
		(l, r) = map(int, input().split())
		segments.append([[l, r], counter])
		counter += 1
	segments.sort()
	ans = [-1] * N
	rightBound = segments[0][0][1]
	valid = -1
	for i in range(1, len(segments)):
		if segments[i][0][0] > rightBound:
			valid = i
			break
		else:
			rightBound = max(rightBound, segments[i][0][1])
	if valid == -1:
		print(-1)
	else:
		for i in range(valid):
			ans[segments[i][1]] = 1
		for i in range(valid, len(segments)):
			ans[segments[i][1]] = 2
		for a in ans:
			print(a, end=' ')
	print()


T = int(input())
for t in range(T):
	n = int(input())
	l = [0] * n
	r = [0] * n
	for i in range(n):
		(l[i], r[i]) = [int(x) for x in input().split()]
	gr = [0] * n
	sl = [*range(n)]
	sl.sort(key=lambda x: l[x])
	tr = r[sl[0]]
	g = 1
	for i in range(n):
		tl = l[sl[i]]
		if tl > tr:
			g = 2
			for j in range(i, n):
				gr[sl[j]] = 2
			break
		else:
			gr[sl[i]] = 1
		tr = max([tr, r[sl[i]]])
	if g == 1:
		print(-1)
	else:
		print(*gr)


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr = []
	for i in range(n):
		(l, r) = list(map(int, stdin.readline().split()))
		arr.append([l, r, i])
	arr = sorted(arr, key=lambda x: (x[0], x[1], x[2]))
	mydict = dict()
	mydict[arr[0][2]] = 1
	mn = arr[0][0]
	mx = arr[0][1]
	group = 1
	for i in range(1, n):
		if arr[i][0] <= mx:
			mx = max(mx, arr[i][1])
			mydict[arr[i][2]] = group
		else:
			group += 1
			mn = arr[i][0]
			mx = max(mx, arr[i][1])
			mydict[arr[i][2]] = group
	if group >= 2:
		for i in range(n):
			if mydict[i] > 1:
				print(2, end=' ')
			else:
				print(1, end=' ')
	else:
		print(-1, end=' ')
	print()


import sys
inf = float('inf')
mod = 1000000007

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

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

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

def main():
	from operator import itemgetter
	for tc in range(int(input())):
		n = int(input())
		arr = [0] * n
		for i in range(n):
			(l, r) = get_ints()
			arr[i] = [l, r]
		arr = list(enumerate(arr))
		arr.sort(key=itemgetter(1))
		r_max = arr[0][1][1]
		i = 0
		while i < n and arr[i][1][0] <= r_max:
			r_max = max(r_max, arr[i][1][1])
			i += 1
		if i == n:
			print(-1)
			continue
		ans = [2] * n
		for point in arr:
			ans[point[0]] = 1
			i -= 1
			if i == 0:
				break
		print(*ans)
main()


q = int(input())
for i in range(q):
	rec = []
	n = int(input())
	flag = False
	ans = [1] * n
	for j in range(n):
		(l, r) = map(int, input().split())
		rec.append((l, r, j))
	rec = sorted(rec)
	k = rec[0][1]
	for a in range(n):
		if k < rec[a][0]:
			flag = True
			for b in range(a):
				ans[rec[b][2]] = 2
			break
		k = max(k, rec[a][1])
	if flag:
		print(' '.join(map(str, ans)))
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
	for _ in range(int(input())):
		n = int(input())
		D = []
		ans = [-1] * n
		for i in range(n):
			(l, r) = map(int, input().split())
			D.append([l, r, i])
		D.sort(key=lambda a: [a[0], -a[1]])
		(x1, y1, x2, y2) = (-1, -1, -1, -1)
		for i in range(len(D)):
			if x1 == -1:
				(x1, y1) = (D[i][0], D[i][1])
				ans[D[i][2]] = 1
			elif D[i][0] > y1 or x2 > y1:
				if x2 == -1:
					(x2, y2) = (D[i][0], D[i][1])
				ans[D[i][2]] = 2
			else:
				y1 = max(y1, D[i][1])
				ans[D[i][2]] = 1
		if x2 == -1:
			print(-1)
		else:
			print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for j in range(t):
	n = int(input())
	data = []
	for i in range(n):
		(l, r) = map(int, input().split())
		data.append((l, r, i))
	data.sort(key=lambda x: x[0])
	rmax = data[0][1]
	ok = -1
	for i in range(n):
		if data[i][0] > rmax:
			ok = rmax
			break
		rmax = max(rmax, data[i][1])
	if ok == -1:
		print('-1')
	else:
		data.sort(key=lambda x: x[2])
		for i in range(n):
			if data[i][1] <= ok:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		a.append([l, r, i])
	a.sort()
	ma = a[0][1]
	b = -1
	for i in range(n):
		if ma < a[i][0]:
			b = i
			break
		else:
			ma = max(a[i][1], ma)
	if b == -1:
		print(b)
	else:
		v = [2] * n
		for i in range(i):
			v[a[i][2]] = 1
		print(*v)


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		(x, y) = map(int, input().split())
		l.append((x, y, i))
	l.sort()
	l1 = l[0][0]
	r1 = l[0][1]
	g = 1
	groups = [0] * n
	for i in range(n):
		if l[i][0] > r1:
			g = 2
		groups[l[i][2]] = g
		r1 = max(r1, l[i][1])
	if g == 1:
		print(-1)
	else:
		print(*groups)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		(x, y) = list(map(int, input().split()))
		a.append([x, y, i])
	a.sort()
	i = 0
	m = a[i][1]
	b = ['2'] * n
	while i < n and m >= a[i][0]:
		b[a[i][2]] = '1'
		m = max(m, a[i][1])
		i += 1
	if '2' in b:
		print(' '.join(b))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	ans = [0] * n
	cc = 0
	l = []
	for xx in range(n):
		(a, b) = map(int, input().split())
		qqq = [a, b, xx]
		l.append(qqq)
	l4 = sorted(l, key=lambda x: x[0])
	c = 1
	x = 2
	zz = 0
	kk = 0
	f = 0
	for i in range(n - 1):
		if l4[f][1] >= l4[i + 1][0]:
			kk += 1
			if zz == 0:
				l4[i].append(1)
				l4[i + 1].append(1)
				zz = 1
			else:
				l4[i + 1].append(1)
				zz = 1
		else:
			if zz == 0:
				l4[i].append(c)
				l4[i + 1].append(x)
				zz = 1
			else:
				l4[i + 1].append(x)
				zz = 1
			break
		if l4[f][1] < l4[i + 1][1]:
			f = i + 1
	if kk == n - 1:
		print(-1)
		continue
	for j in range(i + 1, n):
		l4[j].append(2)
	l4.sort(key=lambda x: x[2])
	for i in range(n):
		print(l4[i][3], end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	otr = []
	for item in range(n):
		otr.append(tuple((int(x) for x in input().split())))
	sortr = [(0, 0)] * 2 + sorted(otr)
	dic = {}
	dic[0, 0] = 1
	c1 = 0
	c2 = 0
	maxy = 0
	for item in range(2, len(sortr)):
		if maxy >= sortr[item][0]:
			if dic[sortr[item - 1]] == 1:
				dic[sortr[item]] = 1
				c1 += 1
			else:
				dic[sortr[item]] = 2
				c2 += 1
		elif c1 == 0:
			dic[sortr[item]] = 1
			c1 += 1
		else:
			dic[sortr[item]] = 2
			c2 += 1
		if sortr[item][1] > maxy:
			maxy = sortr[item][1]
	if c1 == 0 or c2 == 0:
		print(-1)
	else:
		ans = ''
		for item in otr:
			ans += str(dic[item]) + ' '
		print(ans[:-1])


import math

def is_intersect(l1, r1, l2, r2):
	return l1 < l2 and r1 >= l2 or (l1 >= l2 and l1 <= r2)

def get_groups(ranges):
	ranges.sort(key=lambda x: x[1])
	ranges.sort(key=lambda x: x[0])
	ranges[0][3] = 1
	group1 = ranges[0][:2]
	group2 = None
	for (i, rng) in enumerate(ranges[1:]):
		(l, r) = rng[:2]
		if is_intersect(l, r, *group1) and (group2 is None or not is_intersect(l, r, group2)):
			rng[3] = 1
			group1[0] = min(group1[0], l)
			group1[1] = max(group1[1], r)
		elif not is_intersect(l, r, *group1):
			if group2 is None:
				group2 = [l, r]
			else:
				group2[0] = min(group2[0], l)
				group2[1] = max(group2[1], r)
			rng[3] = 2
		else:
			return -1
	if group2 is None:
		return -1
	ranges.sort(key=lambda x: x[2])
	return ' '.join(list(map(str, (rng[3] for rng in ranges))))
n = int(input())
for i in range(n):
	k = int(input())
	arr = [None] * k
	for j in range(k):
		arr[j] = list(map(int, input().split())) + [j, -1]
	print(get_groups(arr))


class Interval:

	def __init__(self, le, ri):
		self.le = le
		self.ri = ri
		self.group = -1

	def __repr__(self):
		return f'({self.le}, {self.ri})'
T = int(input())
for t in range(T):
	N = int(input())
	a = [None] * N
	for i in range(N):
		a[i] = Interval(*map(int, input().split()))
	b = sorted(a, key=lambda _i: _i.ri)
	curr = 0
	for i in range(1, N):
		if b[i].le <= b[curr].ri:
			curr = i
	for i in range(N):
		b[i].group = '1' if i <= curr else '2'
	if curr == N - 1:
		print(-1)
	else:
		print(' '.join((str(a[i].group) for i in range(N))))


from sys import stdin, stdout
Q = int(input())
for i in range(Q):
	N = int(input())
	pair = []
	for j in range(N):
		arr = [int(x) for x in stdin.readline().split()]
		pair.append(arr)
	data = sorted(pair, key=lambda e: (e[0], e[1]))
	cur = 0
	flag = 0
	ans = {}
	j = 0
	ans[data[j][0], data[j][1]] = cur + 1
	max_num = data[j][1]
	for j in range(1, N):
		if data[j][0] <= max_num:
			ans[data[j][0], data[j][1]] = cur + 1
		else:
			cur = (cur + 1) % 2
			ans[data[j][0], data[j][1]] = cur + 1
		if cur == 1:
			flag = 1
		max_num = max(max_num, data[j][1])
	if flag == 0:
		print(-1)
	else:
		for j in range(N):
			p = pair[j]
			if j != N - 1:
				print(ans[p[0], p[1]], end=' ')
			else:
				print(ans[p[0], p[1]], end='\n')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = []
	for i in range(n):
		ar.append(list(map(int, input().split())) + [i])
	ar.sort(key=lambda x: x[0])
	su = 0
	flag = False
	ma = ar[0][1]
	for i in range(1, n):
		if ar[i][0] > ma:
			flag = True
			break
		else:
			ma = max(ma, ar[i][1])
	if flag:
		ans = [0] * n
		for j in range(i):
			ans[ar[j][2]] = 1
		for j in range(i, n):
			ans[ar[j][2]] = 2
		print(*ans)
	else:
		print(-1)


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import *
from math import *
import bisect
for _ in range(int(read())):
	n = int(read())
	alle = list()
	for _ in range(n):
		(x, y) = readi()
		alle.append((x, y, _))
	alle.sort(key=lambda x: (x[0], x[1]))
	notPossible = False
	bkt1 = [alle[0]]
	bkt2 = list()
	last = 1
	ypMax = alle[0][1]
	for i in range(1, n):
		(xp, yp, _) = alle[i - 1]
		(x, y, _) = alle[i]
		ypMax = max(ypMax, yp)
		if ypMax >= x or x == xp:
			if last == 1:
				bkt1.append(alle[i])
			else:
				bkt2.append(alle[i])
		elif last == 1:
			bkt2.append(alle[i])
			last = 2
		else:
			bkt1.append(alle[i])
			last = 1
	if len(bkt2) == 0:
		print(-1)
	else:
		ans = [0] * n
		for t in bkt1:
			ans[t[2]] = '1'
		for t in bkt2:
			ans[t[2]] = '2'
		print(' '.join(ans))


T = int(input())
for t in range(T):
	n = int(input())
	arr = [[None for x in range(3)] for y in range(n)]
	for i in range(n):
		user_in = input()
		(a, b) = user_in.split(' ')
		a = int(a)
		b = int(b)
		arr[i] = [a, b, i]
	arr.sort()
	val = 0
	d = [None for x in range(n)]
	d[arr[0][2]] = 1
	length = arr[0][1]
	for i in range(1, n):
		if arr[i][0] > length:
			if d[arr[i - 1][2]] == 1:
				d[arr[i][2]] = 2
				val = 1
			else:
				d[arr[i][2]] = 1
		else:
			d[arr[i][2]] = d[arr[i - 1][2]]
		length = max(length, arr[i][1])
	if val == 0:
		print(-1)
	else:
		sarr = [str(a) for a in d]
		print(' '.join(sarr))


def check(data):
	n = len(data)
	s = sorted(zip(data, range(n)))
	m = s[0][0][1]
	left = set()
	for (i, r) in enumerate(s):
		left.add(r[1])
		if i == len(s) - 1:
			return '-1'
		m = max(m, r[0][1])
		if s[i + 1][0][0] > m:
			break
	res = ['1' if j in left else '2' for j in range(n)]
	return ' '.join(res)
T = int(input())
for i in range(T):
	n = int(input())
	data = []
	for j in range(n):
		(l, r) = map(int, input().split())
		data.append((l, r))
	print(check(data))


from sys import stdin
t = int(input())
for _ in range(t):
	n = int(input())
	l = [list(map(int, stdin.readline().split())) + [i] for i in range(n)]
	l.sort()
	rb = l[0][1]
	res = [1] * n
	res[l[0][2]] = 2
	for v in l[1:]:
		if v[0] > rb:
			break
		else:
			rb = max(rb, v[1])
			res[v[2]] = 2
	if len(set(res)) == 1:
		print(-1)
	else:
		print(*res)


import re, math, decimal, bisect, collections

def read():
	return input().strip()

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

def viread():
	return [int(_) for _ in input().strip().split()]
for _ in range(iread()):
	segs = []
	for i in range(iread()):
		(a, b) = viread()
		segs.append([a, 0, i, -1])
		segs.append([b, 1, i, -1])
	sortsegs = sorted(segs)
	o = 0
	g = 0
	for s in sortsegs:
		if s[1] == 1:
			segs[s[2] * 2][3] = g
			o -= 1
			if o == 0:
				g += 1
		else:
			o += 1
	if g == 1:
		print(-1)
	else:
		print(*[x[3] % 2 + 1 for x in segs if x[1] == 0])


def sol():

	def f(el):
		return el[0]
	am = int(input())
	arr = [0] * am
	out = [0] * am
	for i in range(am):
		arr[i] = list(map(int, input().split())) + [i]
	arr.sort(key=f)
	lType = 0
	endAt = arr[0][1]
	count = [1, 0]
	out[arr[0][2]] = 1
	for i in range(1, am):
		if arr[i][0] > endAt:
			lType = lType + 1 & 1
		count[lType] += 1
		out[arr[i][2]] = lType + 1
		endAt = max(endAt, arr[i][1])
	if count[0] == 0 or count[1] == 0:
		print(-1)
		return 0
	print(*out)
for i in range(int(input())):
	sol()


t = int(input())
for i in range(t):
	n = int(input())
	llist = []
	rlist = []
	index = []
	groups = []
	for j in range(n):
		(l, r) = map(int, input().split())
		llist.append(l)
		rlist.append(r)
		index.append(j)
		groups.append(0)
	(llist, rlist, index) = zip(*sorted(zip(llist, rlist, index)))
	groups[index[0]] = 1
	now = 1
	maxx = rlist[0]
	for k in range(1, n):
		if now == 1:
			maxx = max(maxx, rlist[k - 1])
		if llist[k] <= maxx:
			groups[index[k]] = now
		else:
			if now == 1:
				now += 1
			groups[index[k]] = now
	if now == 1:
		print(-1)
	else:
		print(*groups)


import sys
from atexit import register
from io import FileIO, StringIO
input = iter(FileIO(0).read().decode().splitlines()).__next__
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		points = sorted((list(map(int, input().split(' '))) + [i] for i in range(n)))
		r_max = points[0][1]
		i = 0
		while i < n and points[i][0] <= r_max:
			r_max = max(r_max, points[i][1])
			i += 1
		if i == n:
			print(-1)
		else:
			res = [2] * n
			for point in points:
				res[point[2]] = 1
				i -= 1
				if i == 0:
					break
			print(*res)
main()


T = int(input())
for _ in range(T):
	n = int(input())
	events = []
	results = [0 for i in range(n)]
	fail = False
	for i in range(n):
		(l, r) = map(int, input().split())
		events.append((l, 0, i))
		events.append((r, 1, i))
	events.sort()
	cnt = 0
	cur_seg = 1
	for (_, t, i) in events:
		if t == 0:
			cnt += 1
			results[i] = cur_seg
		else:
			cnt -= 1
		if cnt == 0:
			cur_seg = 1 + cur_seg % 2
	if len(set(results)) == 2:
		print(*results)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(0, n):
		(a, b) = map(int, input().split())
		l.append((min(a, b), max(a, b), i))
	l.sort()
	grp = 1
	prev = int(0)
	j = int(0)
	ans = []
	for (curr, r, i) in l:
		if grp == 2:
			ans.append((i, 2))
		elif curr > prev and j != 0:
			ans.append((i, 2))
			grp = 2
		else:
			ans.append((i, 1))
		prev = max(prev, r)
		j += 1
	if grp == 1:
		print(-1)
	else:
		ans.sort()
		for i in range(0, n):
			print(ans[i][1], end=' ')
		print()


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

def d():
	n = int(input())
	t = []
	for i in range(n):
		t.append(get() + [i])
	t.sort()
	i = 0
	r = t[0][1]
	ans = ['2'] * n
	while i < n and t[i][0] <= r:
		ans[t[i][2]] = '1'
		r = max(r, t[i][1])
		i += 1
	if '2' in ans:
		print(' '.join(ans))
	else:
		print(-1)
for i in range(int(input())):
	d()