Alice and Bob play the following game. Alice has a set $S$ of disjoint ranges of integers, initially containing only one range $[1, n]$. In one turn, Alice picks a range $[l, r]$ from the set $S$ and asks Bob to pick a number in the range. Bob chooses a number $d$ ($l \le d \le r$). Then Alice removes $[l, r]$ from $S$ and puts into the set $S$ the range $[l, d - 1]$ (if $l \le d - 1$) and the range $[d + 1, r]$ (if $d + 1 \le r$). The game ends when the set $S$ is empty. We can show that the number of turns in each game is exactly $n$.

After playing the game, Alice remembers all the ranges $[l, r]$ she picked from the set $S$, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers $d$ from Alice's ranges, and so he asks you for help with your programming skill.

Given the list of ranges that Alice has picked ($[l, r]$), for each range, help Bob find the number $d$ that Bob has picked.

We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 1000$).

Each of the next $n$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le n$), denoting the range $[l, r]$ that Alice picked at some point.

Note that the ranges are given in no particular order.

It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$, and the ranges for each test case are from a valid game.


-----Output-----

For each test case print $n$ lines. Each line should contain three integers $l$, $r$, and $d$, denoting that for Alice's range $[l, r]$ Bob picked the number $d$.

You can print the lines in any order. We can show that the answer is unique.

It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.


-----Examples-----

Input
4
1
1 1
3
1 3
2 3
2 2
6
1 1
3 5
4 4
3 6
4 5
1 6
5
1 5
1 2
4 5
2 2
4 4
Output
1 1 1

1 3 1
2 2 2
2 3 3

1 1 1
3 5 3
4 4 4
3 6 6
4 5 5
1 6 2

1 5 3
1 2 1
4 5 5
2 2 2
4 4 4


-----Note-----

In the first test case, there is only 1 range $[1, 1]$. There was only one range $[1, 1]$ for Alice to pick, and there was only one number $1$ for Bob to pick.

In the second test case, $n = 3$. Initially, the set contains only one range $[1, 3]$.

Alice picked the range $[1, 3]$. Bob picked the number $1$. Then Alice put the range $[2, 3]$ back to the set, which after this turn is the only range in the set.

Alice picked the range $[2, 3]$. Bob picked the number $3$. Then Alice put the range $[2, 2]$ back to the set.

Alice picked the range $[2, 2]$. Bob picked the number $2$. The game ended.

In the fourth test case, the game was played with $n = 5$. Initially, the set contains only one range $[1, 5]$. The game's turn is described in the following table.

Game turn

Alice's picked range

Bob's picked number

The range set after

Before the game start

$ \{ [1, 5] \} $

1

$[1, 5]$

$3$

$ \{ [1, 2], [4, 5] \}$

2

$[1, 2]$

$1$

$ \{ [2, 2], [4, 5] \} $

3

$[4, 5]$

$5$

$ \{ [2, 2], [4, 4] \} $

4

$[2, 2]$

$2$

$ \{ [4, 4] \} $

5

$[4, 4]$

$4$

$ \{ \} $ (empty set)

Difficulty: EASY
Tags: Sorting

Graph traversal

Implementation

Complete search
Skill types: Sorting

Complete search

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	r = []
	for i in range(n):
		r.append(list(map(int, input().split())))
	r.sort(key=lambda x: x[1] - x[0])
	s = set()
	for i in r:
		for j in range(i[0], i[1] + 1):
			if j not in s:
				s.add(j)
				break
		print(i[0], i[1], j)


def interval(d, h):
	if d == h:
		vysledek = d
	elif not intervaly[d]:
		vysledek = d
		intervaly[d + 1].remove(h - d - 1)
		zasobnik.append((d + 1, h))
	elif h - d - 1 in intervaly[d]:
		vysledek = intervaly[d].pop(0) + d + 1
		zasobnik.append((d, h - 1))
	else:
		vysledek = intervaly[d].pop(0) + d + 1
		intervaly[vysledek + 1].remove(h - vysledek - 1)
		zasobnik.append((d, vysledek - 1))
		zasobnik.append((vysledek + 1, h))
	return vysledek
poctest = int(input())
for i in range(poctest):
	intervaly = dict()
	n = int(input())
	for j in range(n):
		(l, r) = map(int, input().split())
		if l in intervaly:
			intervaly[l].append(r - l)
		else:
			intervaly[l] = [r - l]
	for k in intervaly.keys():
		intervaly[k].sort(reverse=True)
	zasobnik = [(1, n)]
	intervaly[1].remove(n - 1)
	while zasobnik:
		(left, right) = zasobnik.pop()
		result = interval(left, right)
		print(left, right, result)
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	x = []
	for __ in range(n):
		x.append(tuple(map(int, input().split())))
	x.sort(reverse=True, key=lambda a: a[1] - a[0])
	for i in range(n):
		if x[i][0] == x[i][1]:
			print(x[i][0], x[i][0], x[i][0])
			continue
		for j in range(i + 1, n):
			if x[i][0] == x[j][0]:
				print(x[i][0], x[i][1], x[j][1] + 1)
				break
			elif x[i][1] == x[j][1]:
				print(x[i][0], x[i][1], x[j][0] - 1)
				break


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append([y - x, x, y])
	a.sort(reverse=True)
	ds = defaultdict(list)
	de = defaultdict(list)
	truth = [False] * n
	(dist, x, y) = a.pop(0)
	q = [[x, y]]
	for i in a:
		ds[i[1]].append(i[2])
		de[i[2]].append(i[1])
	for i in range(n):
		(x, y) = q.pop(0)
		if ds[x] == [] and de[y] == []:
			print(x, y, x)
		elif ds[x] == []:
			print(x, y, x)
			q.append([de[y][0], y])
			m = de[y].pop(0)
			ds[m].pop(0)
		elif de[y] == []:
			print(x, y, y)
			q.append([x, ds[x][0]])
			m = ds[x].pop(0)
			de[m].pop(0)
		else:
			q.append([x, ds[x][0]])
			q.append([de[y][0], y])
			print(x, y, (ds[x][0] + de[y][0]) // 2)
			m1 = ds[x].pop(0)
			de[m1].pop(0)
			m2 = de[y].pop(0)
			ds[m2].pop(0)


t = int(input())
while t != 0:
	n = int(input())
	A = []
	for i in range(n):
		(l, r) = map(int, input().split())
		A.append([r - l + 1, l, r])
	A.sort()
	net = [0] * n
	ans = []
	for i in A:
		(l, r) = (i[1], i[2])
		for j in range(l, r + 1):
			if net[j - 1] == 0:
				net[j - 1] = 1
				print(l, r, j)
				break
	print()
	t -= 1


import math
from functools import cmp_to_key
from collections import deque

def cmp(a, b):
	(la, ra) = a
	(lb, rb) = b
	if ra < rb:
		return -1
	if ra > rb:
		return 1
	if la < lb:
		return -1
	if la > lb:
		return 1
	return 0

def solve(n, LR):
	ans = []
	LR.sort(key=cmp_to_key(cmp))
	unused = []
	for i in range(1, n + 1):
		for (j, (l, r)) in enumerate(LR):
			if i >= l and i <= r:
				ans.append([i, l, r])
				break
		LR.pop(j)
	return ans

def main():
	ans = []
	t = int(input())
	for _ in range(t):
		n = int(input())
		LR = [tuple(map(int, input().split())) for _ in range(n)]
		ans.append(solve(n, LR))
	for a in ans:
		for (i, l, r) in a:
			print(f'{l} {r} {i}')
		print()
main()


t = int(input())
for i in range(t):
	n = int(input())
	range_arr = []
	for theta in range(n):
		(l, r) = map(int, input().split(' '))
		range_arr.append((l, r))
	range_arr.sort()
	final_arr = []
	counter = 0
	while counter < n:
		temp = range_arr[counter][0]
		final_arr.append(str(range_arr[counter][0]) + ' ' + str(range_arr[counter][1]) + ' ' + str(range_arr[counter][0]))
		counter += 1
		while counter < n and range_arr[counter][0] == temp:
			final_arr.append(str(range_arr[counter][0]) + ' ' + str(range_arr[counter][1]) + ' ' + str(range_arr[counter - 1][1] + 1))
			counter += 1
	for delta in range(n):
		print(final_arr[delta])


t = int(input())
for _ in range(t):
	n = int(input())
	seg = []
	freq = [[0, i + 1] for i in range(n)]
	for i in range(n):
		(l, r) = map(int, input().split())
		seg.append((l, r))
		for k in range(l - 1, r):
			freq[k][0] += 1
	freq.sort()
	ds = [freq[i][1] for i in range(n)]
	s = {(1, n)}
	for i in range(n):
		d = ds[i]
		for st in s:
			if st[0] <= d <= st[1]:
				if st[0] < d:
					s.add((st[0], d - 1))
				if st[1] > d:
					s.add((d + 1, st[1]))
				s.remove(st)
				print(st[0], st[1], d)
				break
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	p = []
	for i in range(n):
		(l, r) = map(int, input().split())
		p.append([l, r])
	p.sort(key=lambda x: (x[1] - x[0], x[0]))
	s = set()
	for x in p:
		for i in range(x[0], x[1] + 1):
			if i not in s:
				s.add(i)
				print(x[0], x[1], i)
				break


import sys
input = sys.stdin.readline
k = int(input())
for _ in range(k):
	n = int(input())
	d = []
	for _ in range(n):
		(a, b) = map(int, input().split())
		d.append([b - a, a, b])
	d.sort()
	s = set()
	for i in range(n):
		for j in range(d[i][1], d[i][2] + 1):
			if j not in s:
				s.add(j)
				d[i] = [d[i][1], d[i][2], j]
	for i in d:
		print(*i)
	if _ != k - 1:
		print('')


DEBUG = False
if DEBUG:
	s = '4\n1\n1 1\n3\n1 3\n2 3\n2 2\n6\n1 1\n3 5\n4 4\n3 6\n4 5\n1 6\n5\n1 5\n1 2\n4 5\n2 2\n4 4'
	input_data = iter(s.split('\n'))
else:

	def func():
		while 1:
			yield input()
	input_data = func()

def get_data():
	n_data = int(next(input_data))
	for _ in range(n_data):
		n = int(next(input_data))
		matrix = []
		for _ in range(n):
			(left, right) = map(int, next(input_data).split())
			matrix.append((left, right))
		yield (n, matrix)

def solve(n, matrix):
	with_dif = [None] * n
	for i in range(n):
		(left, right) = matrix[i]
		with_dif[i] = (left, right, right - left)
	with_dif.sort(key=lambda i: i[-1])
	chosen = []
	for (left, right, _) in with_dif:
		if left not in chosen:
			print(left, right, left)
			chosen.append(left)
		elif right not in chosen:
			print(left, right, right)
			chosen.append(right)
		else:
			for i in range(left, right + 1):
				if i in chosen:
					continue
				print(left, right, i)
				chosen.append(i)
				break
	print()

def main():
	for data in get_data():
		solve(*data)
main()


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
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')

class SegmentTree:

	def __init__(self, data, default=10 ** 18, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

class LazySegUpdate:

	def __init__(self, N):
		self.N = N
		n = 4 * N
		self.tree = [0] * n
		self.lazy = [0] * n

	def queryHelper(self, index, s, e, l, r):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return 0
		if s >= l and e <= r:
			return self.tree[index]
		mid = (s + e) // 2
		return max(self.queryHelper(2 * index, s, mid, l, r), self.queryHelper(2 * index + 1, mid + 1, e, l, r))

	def updateHelper(self, index, s, e, l, r, h):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return
		if s >= l and e <= r:
			self.tree[index] = max(self.tree[index], h)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], h)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], h)
			return
		mid = (s + e) // 2
		self.updateHelper(2 * index, s, mid, l, r, h)
		self.updateHelper(2 * index + 1, mid + 1, e, l, r, h)
		self.tree[index] = max(self.tree[2 * index], self.tree[2 * index + 1])

	def query(self, l, r):
		return self.queryHelper(1, 0, self.N - 1, l, r - 1)

	def update(self, l, r, h):
		self.updateHelper(1, 0, self.N - 1, l, r - 1, h)

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
tt = 1
tt = int(input())
for _ in range(tt):
	n = int(input())
	a = set()
	for i in range(n):
		a.add(tuple(map(int, input().split())))
	res = []
	c = [0]

	def dfs(l, r):
		if l == r:
			res.append([l, r, l])
			return
		d = l - 1
		for i in range(l, r + 1):
			if (i == l or (l, i - 1) in a) and (i == r or (i + 1, r) in a):
				d = i
				break
		res.append([l, r, d])
		if d > l:
			dfs(l, d - 1)
		if d < r:
			dfs(d + 1, r)
	dfs(1, n)
	for i in res:
		print(*i)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ranges = [tuple(map(int, stdin.readline().split())) for i in range(n)]
	if len(ranges) == 1:
		stdout.write(f'{ranges[0][0]} {ranges[0][0]} {ranges[0][0]}\n')
		continue
	ranges.sort(key=lambda t: (t[0], -t[1]))
	a = ranges[0]
	b = None
	keep = False
	for i in range(1, n):
		b = ranges[i]
		x = None
		if a[0] == b[0]:
			x = b[1] + 1
		elif a[1] == b[1]:
			x = b[0] - 1
		elif a[0] == a[1]:
			x = a[1]
		stdout.write(f'{a[0]} {a[1]} {x}\n')
		a = b
	stdout.write(f'{b[0]} {b[0]} {b[0]}\n')


for _ in range(int(input())):
	n = int(input())
	lst = []
	for i in range(n):
		(l, r) = map(int, input().split())
		lst.append([l, r, r - l])
	lst = sorted(lst, key=lambda x: (x[1], x[2]), reverse=True)
	for j in range(n):
		if lst[j][1] == lst[j][0]:
			lst[j][2] = lst[j][1]
		elif lst[j][1] == lst[j + 1][1]:
			lst[j][2] = lst[j + 1][0] - 1
		else:
			lst[j][2] = lst[j][1]
	for k in range(n):
		print(lst[k][0], lst[k][1], lst[k][2])
	print('')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

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

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	s = set([i for i in range(1, n + 1)])
	arr = []
	for i in range(n):
		(l, r) = invr()
		ar = [ele for ele in range(l, r + 1)]
		arr.append([[r - l + 1], ar, [l, r]])
	arr.sort()
	for i in arr:
		for j in i[1]:
			if j in s:
				print(*i[2], j)
				s.remove(j)
				break


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = []
	for i in range(n):
		mn = il()
		a.append([mn[1] - mn[0], i] + mn)
	a.sort()
	ans = [[0, 0, 0] for i in range(n)]
	vis = [0 for i in range(n + 1)]
	for i in range(n):
		ind = -1
		for j in range(a[i][2], a[i][3] + 1):
			if vis[j] == 0:
				ind = j
				vis[j] = 1
				break
		ans[a[i][1]] = [a[i][2], a[i][3], ind]
	for i in ans:
		print(*i)
	print()


from typing import DefaultDict
import collections
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	d = defaultdict(lambda : False)
	a = []
	for i in range(n):
		tmp = tuple([int(x) for x in input().split()])
		a.append(tmp)
		d[tmp] = True
	for (l, r) in a:
		if l == r:
			print(l, r, l)
			continue
		if d[l + 1, r]:
			print(l, r, l)
			continue
		if d[l, r - 1]:
			print(l, r, r)
			continue
		for i in range(l + 1, r):
			if d[l, i - 1] and d[i + 1, r]:
				print(l, r, i)
				break


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = [0 for i in range(n)]
	l = [0 for i in range(n + 1)]
	for i in range(n):
		a[i] = list(map(int, sys.stdin.readline().rstrip().split()))
	a = sorted(a, key=lambda x: x[1] - x[0])
	ans = []
	for i in range(n):
		for j in range(a[i][0], a[i][1] + 1):
			if not l[j]:
				l[j] = 1
				ans.append(a[i] + [j])
	for i in ans:
		print(' '.join(list(map(str, i))))
	print()


T = int(input())

def generate():
	import random
	n = 30
	ranges = [[1, n]]
	data = []
	for i in range(n):
		randomrange = random.sample(ranges, 1)
		randomrange = randomrange[0]
		randomval = random.randint(randomrange[0], randomrange[1])
		data.append([randomrange[0], randomrange[1], randomval])
		ranges.remove(randomrange)
		lower = randomrange[0]
		upper = randomrange[1]
		if lower != upper:
			if randomval - 1 >= randomrange[0]:
				ranges.append([randomrange[0], randomval - 1])
			if randomval + 1 <= randomrange[1]:
				ranges.append([randomval + 1, randomrange[1]])
	return data

def brute(data, answers):
	n = len(answers)
	ls = [i for i in range(1, n + 1)]
	for (left, right, k) in answers:
		try:
			ls.remove(k)
		except:
			print('d', data)
			print('a', answers)
			break
	print('remaining nums', ls)
for t in range(T):
	n = int(input())
	queries = []
	for i in range(n):
		(l, r) = [int(j) for j in input().split()]
		queries.append([r - l + 1, l, r])
	answers = [0 for i in range(n)]
	queries.sort()
	seen = {}
	for i in range(n):
		(diff, left, right) = queries[i]
		sum = 0
		unseenvals = []
		for j in range(left, right + 1):
			if j not in seen:
				unseenvals.append(j)
				continue
			sum += seen[j]
		if sum == right - left:
			seen[unseenvals[-1]] = 1
			answers[i] = [left, right, unseenvals[-1]]
	for i in range(n):
		print(*answers[i])


import sys
I = lambda : [*map(int, sys.stdin.readline().split())]
(t,) = I()
for _ in range(t):
	(n,) = I()
	ranges = set()
	for i in range(n):
		ranges.add(tuple(I()))
	for (a, b) in ranges:
		if a == b:
			print(a, b, a)
		else:
			for i in range(a + 1, b):
				if (a, i - 1) in ranges and (i + 1, b) in ranges:
					print(a, b, i)
					break
			else:
				if (a + 1, b) in ranges:
					print(a, b, a)
				elif (a, b - 1) in ranges:
					print(a, b, b)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [0] * n
	b = []
	for r in range(n):
		b += [list(map(int, input().split()))]
	b.sort(key=lambda x: x[1] - x[0])
	for s in range(n):
		if b[s][1] - b[s][0] == 0:
			print(b[s][0], b[s][0], b[s][0])
			a[b[s][0] - 1] = 1
		else:
			for r in range(b[s][0] - 1, b[s][1]):
				if a[r] == 0:
					print(b[s][0], b[s][1], r + 1)
					a[r] = 1
					break


for _ in range(int(input())):
	n = int(input())
	info = []
	for i in range(n):
		(l, r) = map(int, input().split())
		info.append([r - l, l, r])
	info.sort()
	mySet = set()
	ans = []
	for i in range(n):
		(difference, l, r) = info[i]
		for j in range(l, r + 1):
			if j not in mySet:
				ans.append([l, r, j])
				mySet.add(j)
				break
	for i in ans:
		print(*i)


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
mod = 10 ** 9 + 7
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	ANS = []
	n = int(input())
	arr = []
	for i in range(n):
		(l, r) = map(int, input().split())
		arr.append([l, r])
	arr.sort(key=lambda x: (x[1], -x[0]))
	used = [0] * (n + 1)
	for i in range(n):
		if arr[i][0] == arr[i][1]:
			ANS.append([arr[i][0], arr[i][0], arr[i][0]])
			used[arr[i][0]] = 1
		elif used[arr[i][1]] == 0:
			ANS.append([arr[i][0], arr[i][1], arr[i][1]])
			used[arr[i][1]] = 1
		elif used[arr[i][0]] == 0:
			ANS.append([arr[i][0], arr[i][1], arr[i][0]])
			used[arr[i][0]] = 1
		else:
			for j in range(1, n + 1):
				if used[j] == 0 and j <= arr[i][1] and (j >= arr[i][0]):
					ANS.append([arr[i][0], arr[i][1], j])
					used[j] = 1
	for i in ANS:
		print(*i)
	print()


sr = lambda : input()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	n = ir()
	LR = [lr() for i in range(n)]
	LR.sort(key=lambda x: x[1] - x[0])
	data = [0] * (n + 1)

	def add(k, x):
		while k <= n:
			data[k] += x
			k += k & -k

	def get(k):
		s = 0
		while k:
			s += data[k]
			k -= k & -k
		return s
	N0 = 2 ** (n - 1).bit_length()

	def lower_bound(x):
		w = i = 0
		k = N0
		while k:
			if i + k <= n and w + data[i + k] <= x:
				w += data[i + k]
				i += k
			k >>= 1
		return i + 1
	for num in range(n):
		add(num + 1, 1)
	ans = []
	for (l, r) in LR:
		min_num = lower_bound(get(l - 1))
		ans.append([l, r, min_num])
		add(min_num, -1)
	for (l, r, x) in ans:
		print(l, r, x)
	print()


t = int(input())
for i in range(t):
	n = int(input())
	unused = [i for i in range(1, n + 1)]
	range_list = []
	answer_list = []
	for n in range(n):
		(l, r) = tuple(map(int, input().rstrip().split()))
		range_list.append([l, r, r - l])
	sorted_range_list = sorted(range_list, key=lambda x: x[2])
	for k in sorted_range_list:
		l = k[0]
		r = k[1]
		if l == r:
			answer_list.append([l, l, l])
			unused.remove(l)
		else:
			for u in unused:
				if l <= u <= r:
					answer_list.append([l, r, u])
					unused.remove(u)
					break
				else:
					continue
	for a in answer_list:
		print(f'{a[0]} {a[1]} {a[2]}')
	print()


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')
import math
from collections import Counter
from itertools import permutations
from itertools import combinations

def prob():
	n = int(input())
	grid = []
	for i in range(n):
		l = [int(x) for x in input().split()]
		k = abs(l[0] - l[-1])
		grid.append([k, l])
	grid.sort()
	done = [False for i in range(n + 1)]
	ans = []
	for i in grid:
		k = i[-1]
		for j in range(k[0], k[1] + 1):
			if done[j] == False:
				done[j] = True
				ans.append([k[0], k[-1], j])
				break
	for i in ans:
		print(*i)
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = 1
t = int(input())
for _ in range(0, t):
	prob()


for i in range(int(input())):
	n = int(input())
	a = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		m = 0
		x = a[i][0]
		for j in range(n):
			if a[j][0] == a[i][0] and a[j][1] < a[i][1] or (a[i][1] == a[j][1] and a[j][0] > a[i][0]):
				if a[j][1] - a[j][0] + 1 > m:
					m = a[j][1] - a[j][0] + 1
					if a[j][0] == a[i][0] and a[j][1] < a[i][1]:
						x = a[j][1] + 1
					else:
						x = a[j][0] - 1
		print(a[i][0], a[i][1], x)


import os, sys
isCoding = os.environ.get('CODE_ENV', '') != ''
if isCoding:
	sys.stdin = open('./examples/1.in', 'r')
for _ in range(int(input())):
	n = int(input())
	d = dict()
	for i in range(n):
		(l, r) = map(int, input().split())
		df = r - l
		d[df] = d.get(df, [])
		d[df] += ([l, r],)
	dfp = dict()
	dn = set()
	st = set()
	for x in d[0]:
		dfp[str(x[0]) + ' ' + str(x[0])] = str(x[0])
		dn.add(x[0])
		lx = x[0] - 1
		rx = x[0] + 1
		if lx > 0:
			st.add(lx)
		if rx < n + 1:
			st.add(rx)
	for i in range(1, n):
		if i in d:
			for x in d[i]:
				lx = x[0]
				rx = x[1]
				tst = set()
				for y in st:
					if lx <= y <= rx:
						dfp[str(lx) + ' ' + str(rx)] = str(y)
						dn.add(y)
						nl = y - 1
						nr = y + 1
						if nl > 0 and nl not in dn:
							tst.add(nl)
						if nr < n + 1 and nr not in dn:
							tst.add(nr)
					else:
						tst.add(y)
				st = tst
	for x in dfp:
		print(x, dfp[x])


import sys

def cont(task: dict, l, r):
	if r - l in task.keys():
		return (l, r) in task[r - l]
	else:
		return False

def checkandcont(task: dict, l, r, d, unused: set):
	if d in unused:
		return cont(task, l, r)
	else:
		return False

def solve(task: dict, n):
	unused = set(range(1, n + 1))
	leng = 0
	dst = []
	while unused and leng < n + 1:
		if leng in task.keys():
			for seg in task[leng]:
				(l, r) = seg
				if l == r:
					dst.append([l, r, l])
					unused.remove(l)
				elif checkandcont(task, l + 1, r, l, unused):
					dst.append([l, r, l])
					unused.remove(l)
				elif checkandcont(task, l, r - 1, r, unused):
					dst.append([l, r, r])
					unused.remove(r)
				else:
					for d in range(l + 1, r):
						if d in unused and cont(task, d + 1, r) and cont(task, l, d - 1):
							dst.append([l, r, d])
							unused.remove(d)
		leng += 1
	return dst

def put(task: dict, n, l, r):
	if r - l in task.keys():
		task[r - l].add((l, r))
	else:
		task[r - l] = set([(l, r)])
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	task = {}
	for _ in range(n):
		(l, r) = map(int, sys.stdin.readline().split(' '))
		put(task, n, l, r)
	dst = solve(task, n)
	for dstl in dst:
		dstls = ' '.join(map(str, dstl))
		print(dstls)
	print()


from sys import *
setrecursionlimit(5000001)
from collections import *
from math import *
TT = int(input())
for i in range(TT):
	n = int(input())
	lst = []
	for i in range(n):
		(a, b) = map(int, input().split())
		lst.append([b - a, a, b])
	lst.sort()
	arr = [0] * (n + 1)
	for i in range(n):
		a = lst[i][1]
		b = lst[i][2]
		for j in range(a, b + 1):
			if arr[j] == 0:
				arr[j] = 1
				print(a, b, j)
				break


for _ in range(int(input())):
	n = int(input())
	data = []
	setData = set()
	for i in range(n):
		temp = list(map(int, input().split()))
		data.append(temp)
	data.sort(key=lambda x: x[1] - x[0])
	for i in range(n):
		temp = 0
		for j in range(data[i][0], data[i][1] + 1):
			if j not in setData:
				temp = j
		setData.add(temp)
		print(data[i][0], data[i][1], temp)


from sys import stdin

def solve():
	for _ in range(int(stdin.readline().strip())):
		n = int(stdin.readline().rstrip())
		ranges = []
		for i in range(n):
			(l, r) = map(int, stdin.readline().rstrip().split())
			ranges.append((r - l, l, r))
		ranges.sort()
		prev = set()
		results = []
		for (_, l, r) in ranges:
			if l == r:
				results.append(str(l) + ' ' + str(l) + ' ' + str(l))
				prev.add(l)
			else:
				tmp = set(range(l, r + 1)) - prev
				x = tmp.pop()
				results.append(str(l) + ' ' + str(r) + ' ' + str(x))
				prev.add(x)
		print('\n'.join(results))
solve()


import sys
input = sys.stdin.readline
for _ in ' ' * int(input()):
	n = int(input())
	lines = [[int(x) for x in input().split()] for i in range(n)]
	lines.sort(key=lambda x: x[1] - x[0])
	met = {}
	for line in lines:
		(L, R) = line
		if L == R:
			print(L, R, L)
		else:
			for d in range(L, R + 1):
				left = [L, d - 1]
				right = [d + 1, R]
				if (d <= L or d - 1 in met.get(L, set())) and (d >= R or R in met.get(d + 1, set())):
					if d > L:
						met[L].remove(d - 1)
					if d < R:
						met[d + 1].remove(R)
					print(L, R, d)
		met.setdefault(L, set())
		met[L].add(R)
	print()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	ranges = []
	for i in range(n):
		t = tuple(map(int, sys.stdin.readline().strip().split()))
		ranges.append(t)
	ranges.sort(key=lambda x: x[1] - x[0])
	chosen = [False] * n
	for rang in ranges:
		for num in range(rang[0], rang[1] + 1):
			if not chosen[num - 1]:
				print(*rang, num)
				chosen[num - 1] = True
				break


def solve():
	n = int(input())
	arr = []
	simple_range = {}
	for _ in range(n):
		(l, r) = map(int, input().split())
		arr.append([abs(l - r), l, r])
	arr.sort(reverse=True)
	if n == 1:
		print(arr[0][1], arr[0][1], arr[0][1])
		return
	(left_occur, right_occur) = ({}, {})
	for (diff, l, r) in arr:
		if l == r:
			if left_occur.get(l) is not None:
				left_occur[l].append(l)
			else:
				right_occur[l].append(l)
			continue
		if left_occur.get(l) is None:
			left_occur[l] = []
		else:
			left_occur[l].append(r)
		if right_occur.get(r) is None:
			right_occur[r] = []
		else:
			right_occur[r].append(l)
	for (diff, l, r) in arr:
		if l == r:
			print(l, l, l)
			continue
		if len(left_occur[l]):
			x = left_occur[l].pop(0)
		else:
			x = None
		if len(right_occur[r]):
			y = right_occur[r].pop(0)
		else:
			y = None
		if x and y:
			print(l, r, (x + y) // 2)
		elif x is None:
			print(l, r, l)
		else:
			print(l, r, r)
for _ in range(int(input())):
	solve()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	ranges = [tuple(map(int, input().split())) for _ in range(n)]
	ranges = sorted(ranges, key=lambda x: x[1] - x[0], reverse=True)
	for (l, r) in ranges:
		if l == r:
			print(l, r, r)
		else:
			for (x, y) in ranges:
				if r == y and y - x < r - l:
					print(l, r, x - 1)
					break
				elif l == x and y - x < r - l:
					print(l, r, y + 1)
					break
	print()


q = int(input())
for _ in range(q):
	n = int(input())
	se = set([i for i in range(1, n + 1)])
	dic = []
	for _ in range(n):
		dic.append(list(map(int, input().split())))
	dic = sorted(dic, key=lambda x: abs(x[1] - x[0]))
	for (i, j) in dic:
		if i == j:
			se.remove(i)
			print(i, j, i)
		for k in range(i, j + 1):
			if k in se:
				se.remove(k)
				print(i, j, k)
				break


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = set()
	for i in range(n):
		(a, b) = map(int, input().split())
		s.add((a, b))
	stack = []
	stack.append((1, n))
	ans = []
	while len(stack) > 0:
		ele = stack.pop()
		(a, b) = (ele[0], ele[1])
		s.remove(ele)
		if a == b:
			ans.append((a, b, a))
			continue
		q = -1
		for d in range(a, b + 1):
			f = 0
			z = []
			if d - 1 < a:
				pass
			elif (a, d - 1) not in s:
				f = 1
			else:
				z.append((a, d - 1))
			if d + 1 > b:
				pass
			elif (d + 1, b) not in s:
				f = 1
			else:
				z.append((d + 1, b))
			if not f:
				q = d
				break
		ans.append((a, b, d))
		for x in z:
			stack.append(x)
	for x in ans:
		sys.stdout.write(str(x[0]) + ' ' + str(x[1]) + ' ' + str(x[2]) + '\n')


import os, 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))
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from math import inf
from collections import defaultdict as dd

def main(t):
	n = ii1()
	dic = []
	arr = []
	for i in range(n):
		(l, r) = iia()
		dic.append([abs(l - r), l, r, i])
		arr.append([l, r])
	dic.sort()
	vis = [False] * n
	for (_, l, r, idx) in dic:
		for j in range(l, r + 1):
			if not vis[j - 1]:
				vis[j - 1] = True
				arr[idx].append(j)
	for (l, r, val) in arr:
		print(l, r, val)
	print()
t = 1
t = ii1()
for _ in range(t):
	main(_)


def f(x):
	return x[1] - x[0]
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	used = set()
	for i in range(n):
		(lft, rgt) = map(int, input().split())
		arr.append([lft, rgt])
	arr.sort(key=f)
	for el in arr:
		for i in range(el[0], el[1] + 1):
			if i not in used:
				print(el[0], el[1], i)
				used.add(i)


t = int(input())
for x in range(t):
	n = int(input())
	L = []
	R = []
	ans = [0] * n
	ones = []
	ct = [0] * (n + 1)
	for a in range(n):
		[l, r] = [int(d) for d in input().split()]
		L.append(l)
		R.append(r)
		for b in range(l, r + 1):
			ct[b] += 1
	for a in range(1, n + 1):
		if ct[a] == 1:
			ones.append(a)
	for a in range(n):
		assert len(ones) > a
		for c in range(n):
			if L[c] <= ones[a] and R[c] >= ones[a] and (ans[c] == 0):
				ans[c] = ones[a]
				for b in range(L[c], R[c] + 1):
					ct[b] -= 1
					if ct[b] == 1:
						ones.append(b)
	for a in range(n):
		print(str(L[a]) + ' ' + str(R[a]) + ' ' + str(ans[a]))


t = int(input())
while t > 0:
	n = int(input())
	l = []
	ans = []
	for i in range(n):
		(a, b) = map(int, input().split(' '))
		l.append([a, b])
	for i in l:
		r = i[1] - i[0]
		if r == 0:
			ans.append(i[0])
		else:
			val = []
			for j in l:
				r2 = j[1] - j[0]
				if j != i and r > r2:
					if j[0] == i[0]:
						val.append([j[1] + 1, j[1] - j[0]])
					elif j[1] == i[1]:
						val.append([j[0] - 1, j[1] - j[0]])
			max = 0
			for k in val:
				if k[1] >= max:
					max = k[1]
					v = k[0]
			ans.append(v)
	for i in range(n):
		print(l[i][0], l[i][1], ans[i])
	t -= 1


case = int(input())
for i in range(case):
	S = []
	n = int(input())
	for j in range(n):
		(a, b) = (int(v) for v in input().split())
		S.append([a, b])
		S.sort()
	for k in range(len(S)):
		if S[k][0] == S[k][1]:
			print(str(S[k][0]) + ' ' + str(S[k][1]) + ' ' + str(S[k][0]))
		elif k == 0:
			print(str(S[k][0]) + ' ' + str(S[k][1]) + ' ' + str(S[k][0]))
		elif S[k][0] == S[k - 1][0]:
			print(str(S[k][0]) + ' ' + str(S[k][1]) + ' ' + str(S[k - 1][1] + 1))
		else:
			print(str(S[k][0]) + ' ' + str(S[k][1]) + ' ' + str(S[k][0]))


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		(l, r) = map(int, input().split())
		d[l, r] = 1
	ans = []
	for i in d.keys():
		(l, r) = (i[0], i[1])
		if l == r:
			ans.append([l, r, l])
		elif (l + 1, r) in d.keys():
			ans.append([l, r, l])
		elif (l, r - 1) in d.keys():
			ans.append([l, r, r])
		else:
			for find in range(l + 1, r):
				if (l, find - 1) in d.keys() and (find + 1, r) in d.keys():
					ans.append([l, r, find])
					break
	for i in ans:
		print(*i)


def ga():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	itv = []
	for i in range(n):
		itv.append(ga())
	itv.sort(key=lambda x: x[1] - x[0])
	removed = set()
	for (l, r) in itv:
		for i in range(l, r + 1):
			if i not in removed:
				removed.add(i)
				break
		print(l, r, i)
	print()


def solve(n, given_ranges):
	ordered = sorted(given_ranges, key=lambda x: abs(x[0] - x[1]))
	taken_nums = set()
	for pair in ordered:
		for i in range(pair[0], pair[1] + 1):
			if i not in taken_nums:
				print(pair[0], pair[1], i)
			taken_nums.add(i)
t = int(input())
for i in range(t):
	n = int(input())
	case = []
	for j in range(n):
		w = input().split(' ')
		case.append((int(w[0]), int(w[1])))
	solve(n, case)
	print()


for _ in range(int(input())):
	n = int(input())
	ranges = []
	for _ in range(n):
		(l, r) = map(int, input().split(' '))
		ranges.append((r - l + 1, [l, r]))
	ranges = sorted(ranges)
	hashes = {}
	for i in range(n):
		hashes[i + 1] = 'not gone'
	answers = []
	for range_ in ranges:
		length = range_[0]
		if length == 1:
			answers.append((range_[1][0], range_[1][1], range_[1][1]))
			hashes[range_[1][1]] = 'gone'
		else:
			(l, r) = range_[1]
			for j in range(l, r + 1, 1):
				if hashes[j] != 'gone':
					answers.append((range_[1][0], range_[1][1], j))
					hashes[j] = 'gone'
					break
	assert len(answers) == n
	for ans in answers:
		print(ans[0], ans[1], ans[2])


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	n = int(stdin.readline())
	lr = []
	for i in range(n):
		(nl, nr) = map(int, stdin.readline().split())
		lr.append((nl, -nr))
	lr.sort()
	for i in range(n):
		(nl, nr) = (lr[i][0], -lr[i][1])
		if nl == nr or lr[i + 1][0] != nl:
			ans = str(nl) + ' ' + str(nr) + ' ' + str(nl)
		else:
			ans = str(nl) + ' ' + str(nr) + ' ' + str(-lr[i + 1][1] + 1)
		ANS.append(ans)
	ANS.append('')
print('\n'.join(ANS))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy, random
from functools import reduce
import operator
inf = 10 ** 9 + 7
mod = 10 ** 9 + 7

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

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

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

def endl():
	return print('\n')

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

def grayCode(n):
	return n ^ n >> 1
sys.setrecursionlimit(20000)
graph = collections.defaultdict(list)
grid = []
visited = set()
ways = ['D', 'U', 'R', 'L']
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def find(i):
	if par[i] != i:
		par[i] = find(par[i])
	return par[i]

def union(a, b):
	a = find(a)
	b = find(b)
	if a == b:
		return False
	par[a] = b
	return True

def initGraph(m):
	for _ in range(m):
		(u, v) = LI()
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	return graph

def initGraphW(m):
	for _ in range(m):
		(a, b, c) = LI()
		graph[a - 1].append((b - 1, c))
		graph[b - 1].append((a - 1, c))

def initGrid(h, w):
	for i in range(h):
		s = S()
		grid.append(list(s))
	return grid

def soe(limit):
	a = [True] * limit
	a[0] = a[1] = False
	for (i, isprime) in enumerate(a):
		if isprime:
			yield i
			for n in range(i * i, limit, i):
				a[n] = False
	return a
for _ in range(I()):
	n = I()
	options = set(range(1, n + 1))
	vals = []
	for i in range(n):
		(l, r) = LI()
		vals.append((l, r, 0, i))
	vals.sort(key=lambda x: abs(x[1] - x[0]))
	for i in range(n):
		options = list(options)
		value = None
		for x in options:
			if x >= vals[i][0]:
				value = x
				break
		vals[i] = (vals[i][0], vals[i][1], value, vals[i][-1])
		options.remove(value)
	vals.sort(key=lambda x: x[-1])
	for i in range(n):
		lst = [vals[i][0], vals[i][1], vals[i][2]]
		print(*lst)
	print('\n')


t = int(input())
for j in range(t):
	dic1 = {}
	for i in range(1, 1001):
		dic1[i] = 1
	n = int(input())
	lstf = []
	dic = {}
	for u in range(n):
		(l, r) = map(int, input().split())
		dic[l, r] = r - l
		lstf.append([(l, r), r - l])
	lstf.sort(key=lambda x: x[1])
	for k in lstf:
		l = k[0][0]
		r = k[0][1]
		for f in range(l, r + 1):
			if dic1[f] == 1:
				dic[l, r] = f
				dic1[f] = 0
				break
	for y in dic.keys():
		print(y[0], y[1], dic[y])


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby, accumulate, permutations
from copy import deepcopy
INF = float('inf')
input = sys.stdin.readline
rl = lambda : list(map(int, input().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	res = []
	LR = [rl() for _ in range(n)]
	LR.sort(key=lambda x: x[1] - x[0])
	seen = [False] * (n + 2)
	for (l, r) in LR:
		if l == r:
			res.append((l, r, l))
			seen[l] = True
		else:
			t = l
			while seen[t]:
				t += 1
			res.append((l, r, t))
			seen[t] = True
	for r in res:
		print(*r)


import sys
from math import sqrt, gcd
from collections import deque
sys.setrecursionlimit(10 ** 8)
I = lambda : int(input())
S = lambda : input().strip()
M = lambda : map(int, input().strip().split())
L = lambda : list(map(int, input().strip().split()))
mod = 1000000007
for _ in range(I()):
	n = I()
	d = {}
	li = []
	for i in range(n):
		(a, b) = M()
		d[a, b] = 1
		li.append([a, b])
	for (l, r) in li:
		if l == r:
			print(l, l, l)
			continue
		if (l + 1, r) in d:
			print(l, r, l)
			continue
		if (l, r - 1) in d:
			print(l, r, r)
			continue
		for j in range(l + 1, r):
			if (l, j - 1) in d and (j + 1, r) in d:
				print(l, r, j)
				break


def r(l):
	return l[0] - l[1]

def solution(l):
	if l[0][0] != l[0][1]:
		for i in range(1, len(l)):
			if l[i][0] == l[0][0] and l[i][1] - l[i][0] < l[0][1] - l[0][0]:
				return l[i][1] + 1
	return l[0][0]
for i in range(0, int(input())):
	list1 = []
	for j in range(0, int(input())):
		list1.append(input().split())
		list1[j] = list(map(int, list1[j]))
	list1.sort(key=r)
	for h in range(0, len(list1)):
		list1[h].append(solution(list1[h:]))
	[print(*items) for items in list1]


t = int(input())
from collections import defaultdict
for i in range(0, t):
	n = int(input())
	ranges = []
	dic = defaultdict(list)
	lis = []
	for j in range(0, n):
		(l, r) = map(int, input().split())
		lis = [l, r]
		dic[r - l + 1].append(lis)
		ranges.append(lis)
	removed = [0] * (n + 1)
	for m in range(1, n + 1):
		for h in dic[m]:
			if m == 1:
				removed[h[0]] = 1
				h.append(h[0])
			else:
				for c in range(h[0], h[1] + 1):
					if removed[c] == 0:
						removed[c] = 1
						h.append(c)
						break
	for m in dic:
		for h in dic[m]:
			print(h[0], end=' ')
			print(h[1], end=' ')
			print(h[2], end=' ')
			print('')
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	L = []
	for j in range(n):
		a = [int(x) for x in input().split()]
		L.append(a)
	L.sort(key=lambda x: x[1] - x[0])
	number = set()
	for (f, g) in L:
		for var in range(f, g + 1):
			if var not in number:
				number.add(var)
				break
		print(f, g, var)
	print()


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(tuple(map(int, input().split())))
	a.sort(key=lambda x: x[1] - x[0])
	number = set()
	for (x, y) in a:
		for i in range(x, y + 1):
			if i not in number:
				number.add(i)
				break
		print(x, y, i)


t = int(input())
while t > 0:
	n = int(input())
	l = [[int(x) for x in input().split()] for i in range(n)]
	s = set((k for k in range(1, n + 1)))
	for i in l:
		i.insert(0, i[1] - i[0])
	l = sorted(l)
	for i in l:
		y = s.intersection(set((h for h in range(i[1], i[2] + 1))))
		p = y.pop()
		i.append(p)
		s.discard(p)
	for i in l:
		print(i[1], i[2], i[3])
	print()
	t = t - 1


for t in range(int(input())):
	n = int(input())
	li = []
	for i in range(n):
		(l, r) = map(int, input().split())
		li.append([l, l - r, r])
	li.sort()
	for i in range(0, n - 1):
		if li[i][0] == li[i + 1][0]:
			print(li[i][0], li[i][2], li[i + 1][2] + 1)
		else:
			print(li[i][0], li[i][2], li[i][0])
	print(li[n - 1][0], li[n - 1][2], li[n - 1][0])


t = int(input())
for t1 in range(t):
	n = int(input())
	data = []
	for n1 in range(n):
		(l, r) = map(int, input().split())
		data.append([l, r, r - l])
	data = sorted(data, key=lambda x: x[2])
	remember = dict()
	answer = []
	for r in data:
		for i in range(r[0], r[1] + 1):
			if not i in remember:
				answer.append([r[0], r[1], i])
				remember[i] = True
	for r in answer:
		print(' '.join((str(x) for x in r)))


def solve():
	n = int(input())
	ranges = set()
	for i in range(n):
		ranges.add(tuple(map(int, input().split())))
	for rng in ranges:
		for dig in range(rng[0], rng[1] + 1):
			if (dig == rng[0] or (rng[0], dig - 1) in ranges) and (dig == rng[1] or (dig + 1, rng[1]) in ranges):
				print(rng[0], rng[1], dig)
	print()
for _ in range(int(input())):
	solve()


from itertools import permutations
from math import ceil, e, log2, floor, sqrt, gcd
from collections import defaultdict, deque
from itertools import permutations
import sys
import os.path
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')

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

def solve(testcase):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = MI()
		l.append((a, b))
	d = defaultdict(list)
	for i in range(n - 1, -1, -1):
		d[l[i][0]].append(l[i][1])
	ans = []
	for i in d:
		x = sorted(d[i], reverse=True)
		for j in range(len(x) - 1):
			ans.append([i, x[j], x[j + 1] + 1])
		ans.append([i, x[-1], i])
	for i in ans:
		print(*i)
	print()
t = int(input())
for _ in range(t):
	solve(_ + 1)


class io:
	s = input
	i = lambda : int(io.s())
	f = lambda : float(io.s())
	ts = lambda : io.s().split()
	ti = lambda : map(int, io.ts())
	tf = lambda : map(float, io.ts())
	ls = lambda : list(io.ts())
	li = lambda : list(io.ti())
	lf = lambda : list(io.tf())
for _ in range(int(input())):
	n = io.i()
	a = []
	done = set()
	ans = dict()
	for i in range(n):
		(l, r) = io.ti()
		if l == r:
			ans[l, r] = l
			done.add(l)
		else:
			a.append((l, r, r - l))
	a.sort(key=lambda x: x[2])
	for (l, r, n) in a:
		v = set(range(l, r + 1)).difference(done).pop()
		ans[l, r] = v
		done.add(v)
	for (k, v) in ans.items():
		print(*k, v)
	print()


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		(l, r) = map(int, input().split())
		arr.append([r - l, l, r])
	arr.sort()
	d1 = {}
	for i in arr:
		for j in range(i[1], i[2] + 1):
			if j not in d1:
				d1[j] = 1
				print(i[1], i[2], j)
	print()


def solve():
	n = int(input())
	s = set()
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		s.add(l * (n + 1) + r)
	q = [(1, n)]
	while len(q) > 0:
		(pl, pu) = q.pop(0)
		flag = False
		for p in range(pl + 1, pu):
			if pl * (n + 1) + p - 1 in s and (p + 1) * (n + 1) + pu in s:
				print(pl, pu, p)
				q.append((pl, p - 1))
				q.append((p + 1, pu))
				flag = True
		if flag == False:
			if pl == pu:
				print(pl, pu, pl)
			elif (pl + 1) * (n + 1) + pu in s:
				print(pl, pu, pl)
				q.append((pl + 1, pu))
			else:
				print(pl, pu, pu)
				q.append((pl, pu - 1))
	print('')
for _ in range(int(input())):
	solve()


for t in range(int(input())):
	n = int(input())
	A = [[int(i) for i in input().split()] for j in range(n)]
	d = dict()
	for i in range(n):
		if A[i][0] == A[i][1]:
			d[A[i][0], A[i][1]] = A[i][0]
		else:
			d[A[i][0], A[i][1]] = 0
	for i in range(n):
		if A[i][0] != A[i][1]:
			if (A[i][0] + 1, A[i][1]) in d:
				d[A[i][0], A[i][1]] = A[i][0]
			elif (A[i][0], A[i][1] - 1) in d:
				d[A[i][0], A[i][1]] = A[i][1]
			else:
				for j in range(A[i][0], A[i][1] - 1):
					if (A[i][0], j) in d and (j + 2, A[i][1]) in d:
						d[A[i][0], A[i][1]] = j + 1
						break
	for i in range(n):
		print(A[i][0], A[i][1], d[A[i][0], A[i][1]])


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	if n == 1:
		print(1, 1, 1)
		print()
		continue
	l.sort(key=lambda x: abs(x[0] - x[1]))
	used = [0] * (n + 1)
	for i in range(n):
		for ind in range(l[i][0], l[i][1] + 1):
			if used[ind] == 0:
				used[ind] = 1
				l[i].append(ind)
				break
	for i in l:
		print(*i)
	print()


def Game_On_Ranges(a, n):
	s = set()
	for i in range(n):
		d = a[i][0]
		l = a[i][1]
		r = a[i][2]
		if d == 0:
			a[i].append(l)
			s.add(l)
		else:
			cand = -1
			for x in range(l, r + 1):
				if x not in s:
					a[i].append(x)
					s.add(x)
					break
	for i in range(n):
		print('{} {} {}'.format(a[i][1], a[i][2], a[i][3]))
t = int(input())
for _ in range(t):
	n = int(input())
	alice = []
	for i in range(n):
		(l, r) = map(int, input().split())
		alice.append([r - l, l, r])
	alice.sort(key=lambda x: x[0])
	Game_On_Ranges(alice, n)


import sys, bisect, math
from collections import deque, Counter
input = lambda : sys.stdin.readline().strip()
ceil = lambda x: math.ceil(x)
mod = 10 ** 9 + 7

def solve():
	n = int(input())
	a = []
	visited = [0] * (n + 1)
	for _n in range(n):
		a.append(list(map(int, input().split())))
		(l, r) = a[-1]
		visited[l] = visited[r] = True
	a.sort(key=lambda x: x[1] - x[0])
	ans = []
	for i in a:
		(x, y) = (-1, i[0])
		for j in range(i[0], i[1] + 1):
			if visited[j] == 0:
				x = j
				break
			elif visited[j] == 1:
				y = j
		if x != -1:
			ans.append(i + [x])
			visited[x] = -2
		else:
			ans.append(i + [y])
			visited[y] = -2
	answer = ''
	for i in ans:
		answer += ' '.join((str(x) for x in i)) + '\n'
	return answer
t = 1
t = int(input())
for _ in range(t):
	print(solve())


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
from collections import Counter as ctr
from heapq import heapify, heappush as ha, heappop as hp
from math import ceil, floor, gcd, sqrt
from bisect import bisect_left as bsl, bisect_right as bsr
from bisect import insort_left as isl, insort_right as isr
from itertools import permutations, combinations
ip = lambda : int(stdin.readline())
ips = lambda : str(stdin.readline())
ipm = lambda : map(int, stdin.readline().split())
mod = int(1000000000.0) + 7
mod2 = 998244353
for _ in range(ip()):
	n = ip()
	a = [0 for i in range(n)]
	b = []
	for i in range(n):
		(l, r) = ipm()
		l -= 2
		r -= 1
		a[r] += 1
		if l > -1:
			a[l] -= 1
	for i in reversed(range(n - 1)):
		a[i] += a[i + 1]
	for i in range(n):
		f = 0
		l = 1
		r = n
		for j in range(n):
			if a[j] == -1:
				if f == 1:
					f = 0
					r = j
					b.append([l, r, d])
				l = j + 2
			if a[j] == i + 1:
				d = j + 1
				f = 1
				r = j + 1
				a[j] = -1
		if f == 1:
			b.append([l, n, d])
	for i in range(n):
		print(*b[i])


from collections import defaultdict, deque

def solve():
	n = int(input())
	ranges = []
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		ranges.append((l, r))
	ranges.sort(key=lambda x: x[1] - x[0])
	S = set()
	for i in range(n):
		(l, r) = ranges[i]
		for j in range(l, r + 1):
			if j not in S:
				print(l, r, j)
				S.add(j)
				break
for _ in range(int(input())):
	solve()


class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class OrderedList(SortedList):

	def __init__(self, arg):
		super().__init__(arg)

	def rangeCountByValue(self, leftVal, rightVal):
		leftCummulative = self.bisect_left(leftVal)
		rightCummulative = self.bisect_left(rightVal + 1)
		return rightCummulative - leftCummulative

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		n = int(input())
		ranges = []
		for __ in range(n):
			ranges.append(readIntArr())
		ol = OrderedList([])
		for (l, r) in ranges:
			ol.add((l, -r))
		while ol:
			(l, r) = ol.pop(0)
			r *= -1
			if l == r:
				d = l
			else:
				d = -1
				if ol and ol[0][0] == l:
					d = -ol[0][1] + 1
				if ol and ol[0][1] == -r:
					d = ol[0][0] - 1
				assert d != -1
			allans.append((l, r, d))
		allans.append(['\n'])
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
	print('? {} {} {}'.format(a, b, c))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ansArr):
	print('! {}'.format(' '.join([str(x) for x in ansArr])))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


from __future__ import division, print_function
import math
import sys
import os
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = []
	for i in range(n):
		l.append(inlt())
	l.sort(key=lambda x: x[1] - x[0])
	vis = [0 for i in range(n + 1)]
	ans = []
	for i in range(n):
		(lf, rt) = l[i]
		for i in range(lf, rt + 1):
			if vis[i] == 0:
				ans.append([lf, rt, i])
				vis[i] = 1
				break
	for i in range(n):
		print(*ans[i])
	print()


for t in range(int(input())):
	n = int(input())
	num_list = []
	for i in range(n):
		r = tuple(map(int, input().split()))
		num_list.append(r)
	num_list.sort(key=lambda x: (x[1], x[0]))
	val = [False for i in range(n)]
	for i in range(n):
		for j in range(num_list[i][0] - 1, num_list[i][1]):
			if not val[j]:
				print(*num_list[i], j + 1)
				val[j] = True
				break


import math
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	ans = []
	a = []
	d = []
	h = [0] * n
	for i in range(n):
		(l, r) = [int(i) for i in input().split()]
		a.append([l, r])
	a.sort(key=lambda x: (x[1], -x[0]))
	used = [0] * (n + 1)
	for i in range(n):
		if a[i][0] == a[i][1]:
			ans.append([a[i][0], a[i][0], a[i][0]])
			used[a[i][0]] = 1
		elif used[a[i][1]] == 0:
			ans.append([a[i][0], a[i][1], a[i][1]])
			used[a[i][1]] = 1
		elif used[a[i][0]] == 0:
			ans.append([a[i][0], a[i][1], a[i][0]])
			used[a[i][0]] = 1
		else:
			for j in range(1, n + 1):
				if used[j] == 0 and j <= a[i][1] and (j >= a[i][0]):
					ans.append([a[i][0], a[i][1], j])
					used[j] = 1
	for i in ans:
		print(*i)
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	k = []
	for i in range(n):
		k.append(tuple(map(int, input().split())))
	k.sort(key=lambda a: abs(a[0] - a[1]))
	ans = [0 for i in range(n)]
	seen = set()
	coords = set(range(n))
	while coords:
		nc = coords.copy()
		for i in coords:
			if ans[i]:
				continue
			(p1, p2) = k[i]
			if p1 == p2:
				ans[i] = p1
				seen.add(p1)
				nc.remove(i)
			else:
				p = 0
				repl = 0
				for x in range(p1, p2 + 1):
					if x not in seen:
						repl = x
						p += 1
				if p == 1:
					ans[i] = repl
					seen.add(repl)
					nc.remove(i)
		coords = nc
	for (rang, bob) in zip(k, ans):
		print(*rang, bob)
	print()


def main():
	t = int(input())
	allans = []
	for _ in range(t):
		n = int(input())
		items = []
		for _ in range(n):
			(l, r) = readIntArr()
			items.append((l, -r))
		items.sort()
		for (i, (l, r)) in enumerate(items):
			r *= -1
			if l == r:
				allans.append((l, l, l))
			else:
				(l2, r2) = items[i + 1]
				r2 *= -1
				if l == l2:
					d = r2 + 1
				else:
					d = l
				allans.append((l, r, d))
		allans.append(['\n'])
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
	print('? {} {} {}'.format(a, b, c))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ansArr):
	print('! {}'.format(' '.join([str(x) for x in ansArr])))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


from sys import stdin, stdout
(input, print) = (stdin.readline, stdout.write)
from math import *

def main():
	for _ in range(int(input())):
		n = int(input())
		a = []
		for i in range(n):
			(l, r) = list(map(int, input().split()))
			a.append([l, -r])
		a.sort()
		for i in range(n - 1):
			if a[i][0] == a[i + 1][0]:
				print(str(a[i][0]) + ' ' + str(-a[i][1]) + ' ' + str(-a[i + 1][1] + 1) + '\n')
			else:
				print(str(a[i][0]) + ' ' + str(-a[i][1]) + ' ' + str(a[i][0]) + '\n')
		print(str(a[-1][0]) + ' ' + str(-a[-1][1]) + ' ' + str(a[-1][0]) + '\n')
main()


def solve(n, l):
	for i in range(n):
		d = l[i][1] - l[i][0]
		l[i].insert(0, d)
	l.sort()
	v = [0] * (n + 1)
	for i in range(n):
		for j in range(l[i][1], l[i][2] + 1):
			if v[j] == 0:
				v[j] = 1
				l[i].append(j)
				break
	for i in range(n):
		print(*l[i][1:])
t = int(input())
while t:
	n = int(input())
	l = []
	for i in range(n):
		l.append([int(j) for j in input().split(' ')])
	solve(n, l)
	t -= 1


import sys

def solve(L, n):
	k = len(L)
	for i in range(k):
		L[i] = [L[i][1] - L[i][0]] + L[i]
	L.sort()
	R = [i for i in range(1, n + 1)]
	for e in L:
		if e[0] == 0:
			print(e[1], e[2], e[1])
			R[e[1] - 1] = 0
		else:
			for i in range(e[1] - 1, e[2]):
				if R[i] != 0:
					print(e[1], e[2], R[i])
					R[i] = 0
					break
for _ in range(int(input())):
	n = int(sys.stdin.readline())
	L = []
	for _ in range(n):
		a = list(map(int, sys.stdin.readline().split()))
		L.append(a)
	solve(L, n)
	print('')


for _ in range(int(input())):
	n = int(input())
	arr = [i for i in range(1, n + 1)]
	vis = [0] * n
	d = dict()
	v = []
	for k in range(n):
		(l, r) = map(int, input().split())
		f = str(l) + ' ' + str(r)
		if l == r:
			d[f] = l
			vis[l - 1] = 1
		else:
			v.append([l, r])
	v = sorted(v, key=lambda x: x[1] - x[0])
	for g in v:
		f = str(g[0]) + ' ' + str(g[1])
		for c in range(g[0], g[1] + 1):
			if vis[c - 1] == 0:
				vis[c - 1] = 1
				d[f] = c
				break
	for k in d:
		print(k, d[k])


T = int(input())
for t in range(T):
	n = int(input())
	pairs = []
	for i in range(n):
		pairs.append([int(x) for x in input().split()])
	pairs_dict = dict()
	pairs_diff = []
	for i in pairs:
		pairs_diff.append([i[0], -(i[1] - i[0]), i[1]])
	pairs_diff.sort()
	for i in range(len(pairs_diff) - 1):
		if pairs_diff[i][0] == pairs_diff[i + 1][0]:
			pairs_dict[pairs_diff[i][0], pairs_diff[i][-1]] = pairs_diff[i + 1][-1] + 1
		elif pairs_diff[i][0] == pairs_diff[i][-1]:
			pairs_dict[pairs_diff[i][0], pairs_diff[i][-1]] = pairs_diff[i][-1]
		else:
			pairs_dict[pairs_diff[i][0], pairs_diff[i][-1]] = pairs_diff[i + 1][0] - 1
	pairs_dict[pairs_diff[-1][0], pairs_diff[-1][-1]] = pairs_diff[-1][-1]
	for i in pairs:
		print(i[0], i[1], pairs_dict[tuple(i)])


import sys
input = sys.stdin.readline

def iinput():
	return int(input())

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

def i0input():
	return int(input()) - 1

def linput():
	return list(input().split())

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

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

def li0input():
	return list(map(lambda x: int(x) - 1, input().split()))

def mi0input():
	return map(lambda x: int(x) - 1, input().split())
INF = 10 ** 20
MOD = 1000000007
t = iinput()
for tt in range(t):
	n = iinput()
	lrs = []
	for i in range(n):
		(l, r) = liinput()
		lrs.append((i, l, r))
	used = [False] * n
	lrs.sort(key=lambda x: x[2] - x[1])
	for (k, (i, l, r)) in enumerate(lrs):
		for j in range(l, r + 1):
			if not used[j - 1]:
				break
		used[j - 1] = True
		lrs[k] = (i, l, r, j)
	for (i, l, r, s) in lrs:
		print(l, r, s)
	if tt != t - 1:
		print()


import sys
import os
from math import ceil, floor, sqrt, gcd, factorial, log, log2
from io import BytesIO, IOBase
from collections import Counter, deque
from bisect import bisect
inf = int(10000000000.0)
BUFSIZE = 8192
inp = lambda : int(input())
mp = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))

def main():
	for _ in range(inp()):
		n = inp()
		a = []
		s = {(1, n): 0}
		for i in range(n):
			(l, r) = mp()
			a.append((l, r))
			s[l, r] = 0
		a.sort()
		for i in range(n):
			if a[i][0] == a[i][1]:
				s[a[i]] = a[i][0]
			else:
				for j in range(0, n):
					if i != j and (a[j][0] == a[i][0] or a[j][1] == a[i][1]):
						(u, v) = a[j]
						(x, y) = a[i]
						d = 0
						if u == x:
							d = v + 1
						elif v == y:
							d = u - 1
						t1 = t2 = ()
						if d >= x and d <= y:
							if x <= d - 1:
								t1 = (x, d - 1)
							if d + 1 <= y:
								t2 = (d + 1, y)
							f = True
							if t1 != () and t1 not in s:
								f = False
							if t2 != () and t2 not in s:
								f = False
							if f:
								s[a[i]] = d
								break
		for i in s:
			print(*i, s[i])
		print()

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()


for _ in range(int(input())):
	n = int(input())
	tmp = [True for i in range(n + 1)]
	lis = []
	for i in range(n):
		(l, r) = map(int, input().split())
		lis.append((r - l, l, r))
	lis.sort()
	ans = []
	for triplet in lis:
		if tmp[triplet[1]]:
			ans.append((triplet[1], triplet[2], triplet[1]))
			tmp[triplet[1]] = False
		elif tmp[triplet[2]]:
			ans.append((triplet[1], triplet[2], triplet[2]))
			tmp[triplet[2]] = False
		else:
			for z in range(triplet[1], triplet[2] + 1):
				if tmp[z]:
					ans.append((triplet[1], triplet[2], z))
					tmp[z] = False
					break
	for jawaban in ans:
		print(f'{jawaban[0]} {jawaban[1]} {jawaban[2]}')


t = int(input())
for i in range(t):
	n = int(input())
	li = []
	for i in range(n):
		(a, b) = map(int, input().split())
		li.append([abs(a - b), a, b])
	li.sort()
	d = dict()
	for i in range(1, n + 1):
		d[i] = 0
	ansli = []
	for i in range(n):
		if d[li[i][2]] == 0:
			d[li[i][2]] = 1
			ansli.append([li[i][1], li[i][2], li[i][2]])
		elif d[li[i][1]] == 0:
			d[li[i][1]] = 1
			ansli.append([li[i][1], li[i][2], li[i][1]])
		else:
			st = li[i][1]
			end = li[i][2] + 1
			for j in range(st, end):
				if d[j] == 0:
					d[j] = 1
					ansli.append([li[i][1], li[i][2], j])
	for i in range(n):
		print(*ansli[i])


nb_cases = int(input())
for case in range(nb_cases):
	n = int(input())
	ranges = []
	numbers = []
	for i in range(n):
		ranges.append([])
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		ranges[r - l].append(l)
	for r in range(n):
		for l in ranges[r]:
			for j in range(l, l + r + 1):
				if j not in numbers:
					numbers.append(j)
					print(l, l + r, j)
					continue


T = int(input())
for tt in range(T):
	n = int(input())
	a = [0] * n
	for i in range(n):
		a[i] = tuple(map(int, input().split()))
	t = []
	a.sort(key=lambda x: x[0] - x[1])
	ans = set()
	was = set()
	for i in a:
		for j in t:
			if i[0] == j[0] and j not in was:
				ans.add((j, i[1] + 1))
				t.append(i)
				was.add(j)
				break
			if i[1] == j[1] and j not in was:
				ans.add((j, i[0] - 1))
				t.append(i)
				was.add(j)
				break
		if i[0] - i[1]:
			t.append(i)
		else:
			ans.add(((i[0], i[0]), i[0]))
	for i in ans:
		print(*i[0], i[1])
	if t != T - 1:
		print()


for _ in range(int(input())):
	main = []
	n = int(input())
	for _ in range(n):
		arr = list(map(int, input().split()))
		main.append(arr)
	main.sort()
	arr_1 = []
	arr_2 = []
	for i in main:
		arr_1.append(i[0])
		arr_2.append(i[1])
	for i in range(n):
		if arr_1[i] == arr_2[i]:
			main[i].append(arr_1[i])
		else:
			temp = arr_2[i]
			arr_2[i] = -arr_2[i]
			if temp in arr_2:
				main[i].append(arr_1[arr_2.index(temp)] - 1)
			else:
				main[i].append(temp)
	for i in main:
		print(*i, end=' ')


for _ in range(int(input())):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().split())))
	arr.sort()
	a = [arr[0]]
	new = []
	for i in range(1, n):
		if arr[i][0] == a[-1][0]:
			a.append(arr[i])
		else:
			new.extend(a[::-1])
			a = [arr[i]]
	new.extend(a[::-1])
	i = 0
	while i < n:
		if new[i][0] == new[i][1]:
			print(new[i][0], new[i][0], new[i][0])
		elif new[i][0] == new[i + 1][0]:
			print(new[i][0], new[i][1], new[i + 1][1] + 1)
		else:
			print(new[i][0], new[i][1], new[i + 1][0] - 1)
		i += 1


for _ in range(int(input())):
	n = int(input())
	ll = []
	s = set()
	for i in range(n):
		l = list(map(int, input().split()))
		ll.append([l[1] - l[0], l[0], l[1]])
	ll.sort()
	nn = len(s)
	for i in range(n):
		(ii, l, r) = ll[i]
		for j in range(l, r + 1):
			s.add(j)
			if nn != len(s):
				nn += 1
				print(l, r, j)
				break


ans = []
for _ in range(int(input())):
	n = int(input())
	ranges = []
	res = []
	for _ in range(n):
		ranges.append(list(map(int, input().split())))
	ranges.sort(key=lambda x: abs(x[1] - x[0]))
	peristed = set()
	for (l, r) in ranges:
		for chosen in range(l, r + 1):
			if chosen not in peristed:
				res.append([l, r, chosen])
				peristed.add(chosen)
				break
	ans.append(res)
for a in ans:
	for an in a:
		print(*an)
	print()


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
from collections import deque
import bisect

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(input())

def fun(x, y):
	return 0
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append([int(i) for i in input().split()])
	a.sort(key=lambda x: x[1], reverse=True)
	a.sort(key=lambda x: x[0])
	for i in range(n):
		if a[i][0] == a[i][1]:
			print(*a[i], a[i][0])
		elif a[i][0] != a[i + 1][0]:
			print(*a[i], a[i + 1][0] - 1)
		else:
			print(*a[i], a[i + 1][1] + 1)


from sys import stdout, stdin
from io import IOBase, BytesIO
from os import read, supports_follow_symlinks, write, fstat
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 = read(self._fd, max(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, size: int=...):
		while self.newlines == 0:
			b = read(self._fd, max(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:
			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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def input():
	return stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for _ in ' ' * t:
		n = int(input())
		segment = []
		for _ in ' ' * n:
			(l, r) = map(int, input().split())
			segment.append((l, r, r - l))
		segment = sorted(segment, key=lambda x: x[2])
		bob_numbers = []
		for (l, r, _) in segment:
			for i in range(l, r + 1):
				if i not in bob_numbers:
					bob_numbers.append(i)
					break
		for i in range(n):
			print(segment[i][0], segment[i][1], bob_numbers[i])
main()


for _ in range(int(input())):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(tuple(map(int, input().split())))
	arr.sort(key=lambda s: (s[0], -s[1]))
	res = []
	left = {}
	right = {}
	for i in range(n - 1, -1, -1):
		(l, r) = arr[i]
		if l == r:
			res.append((l, r, l))
		elif l in left:
			res.append((l, r, left[l] + 1))
		elif r in right:
			res.append((l, r, right[r] - 1))
		left[l] = r
		right[r] = l
	for i in range(n):
		print(res[i][0], res[i][1], res[i][2])


import sys
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		x = input().split(' ')
		l.append((int(x[0]), int(x[1])))
	l = sorted(l)
	si = 0
	ei = 0
	var = l[0][0]
	for j in range(1, n):
		if l[j][0] == var:
			ei = ei + 1
		else:
			var = l[j][0]
			l[si:ei + 1] = reversed(l[si:ei + 1])
			si = j
			ei = j
	l[si:ei + 1] = reversed(l[si:ei + 1])
	v1 = l[0][0]
	for j in range(n):
		v = []
		v.append(l[j][0])
		v.append(l[j][1])
		if l[j][0] == l[j][1]:
			v.append(l[j][0])
		elif l[j + 1][0] != l[j][0]:
			v.append(l[j][0])
		else:
			v.append(l[j + 1][1] + 1)
		print(*v)


t = int(input())
for _ in range(t):
	n = int(input())
	ss = []
	for i in range(n):
		ss.append(list(map(int, input().split())))
	ss = sorted(ss, key=lambda x: x[1] - x[0])
	used = set()
	ans = []
	for s in ss:
		(a, b) = (s[0], s[1])
		for i in range(a, b + 1):
			if i not in used:
				print(' '.join([str(j) for j in [a, b, i]]))
				used.add(i)
				break


from sys import stdin
from collections import defaultdict
ii = lambda : int(input())
di = lambda : defaultdict(lambda : 0)
mi = lambda : map(int, stdin.readline().strip().split())
for _ in range(ii()):
	n = ii()
	a = []
	for i in range(n):
		(l, r) = mi()
		a.append([l, r, r - l + 1])
	a.sort(key=lambda x: x[2])
	d = di()
	for i in range(n):
		for j in range(a[i][0], a[i][1] + 1):
			if d[j] == 0:
				d[j] = 1
				print(a[i][0], a[i][1], j)
				break


T = int(input())
for _ in range(T):
	N = int(input())
	L = list()
	for i in range(N):
		(a, b) = map(int, input().split())
		L.append([b - a, a, b])
	L.sort()
	S = set()
	for i in range(N):
		(_, a, b) = L[i]
		for j in range(a, b + 1):
			if j not in S:
				this = j
				break
		S.add(this)
		print(a, b, this)
	print()


t = int(input())
for _ in range(0, t):
	n = int(input())
	dict1 = {}
	for i in range(0, n):
		inputs = [int(num) for num in input().split()]
		l = inputs[0]
		r = inputs[1]
		if l not in dict1:
			dict1[l] = []
		dict1[l].append(r)
	for key in dict1:
		dict1[key].sort()
		for i in range(len(dict1[key]) - 1, 0, -1):
			print(f'{key} {dict1[key][i]} {dict1[key][i - 1] + 1}')
		print(f'{key} {dict1[key][0]} {key}')
	print('')


import heapq
import sys
from math import *
import threading
from heapq import *
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
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')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

	def npr(self, n, k):
		if k < 0 or n < k:
			return 0
		f = self.factorial
		return f.calc(n) * f.invFactorial(n - k) % self.MOD

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

def lower_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			start = middle + 1
		else:
			answer = middle
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [li[0]]
	for i in range(1, len(li)):
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

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

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def given():
	a = list(map(int, input().split()))
	return a

def givenStringList():
	s = list(input())
	return s

def givenStringListInt():
	s = [int(x) for x in givenStringList()]
	return s

def main():
	karmanya = given()[0]
	while karmanya != 0:
		karmanya -= 1
		n = given()[0]
		rang = []
		for i in range(n):
			(l, r) = given()
			rang.append([r - l + 1, l, r])
		rang.sort()
		ans = []
		done = [0] * n
		for i in rang:
			(l, r) = (i[1], i[2])
			for j in range(l, r + 1):
				if done[j - 1] == 0:
					done[j - 1] = 1
					print(l, r, j)
					break
		print('')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		(x, y) = map(int, input().split())
		d = y - x
		a.append([d, x, y])
	a.sort(reverse=True)
	for i in range(n):
		mx = 0
		for j in range(i + 1, n):
			if a[i][1] == a[j][1]:
				if mx < a[j][2]:
					mx = a[j][2]
		mn = n + 1
		for j in range(i + 1, n):
			if a[i][2] == a[j][2]:
				if mn > a[j][1]:
					mn = a[j][1]
		if mx != 0 and mn != n + 1:
			a[i].append((mn + mx) // 2)
		elif mx == 0:
			a[i].append(a[i][1])
		elif mn == n + 1:
			a[i].append(a[i][2])
	for i in range(n):
		print(a[i][1], a[i][2], a[i][3])
	print()


T = int(input())
for _ in range(T):
	n = int(input())
	a = []
	for i in range(n):
		a.append([int(x) for x in input().split()])
	a.sort(key=lambda x: x[1] - x[0])
	nums = set(range(1, n + 1))
	for (l, r) in a:
		dset = nums & set(range(l, r + 1))
		d = dset.pop()
		nums.remove(d)
		print(l, r, d)


t = int(input())
for _ in range(t):
	n = int(input())
	ranges = set()
	for i in range(n):
		ranges.add(tuple(map(int, input().split())))
	for pair in ranges:
		(l, r) = pair
		diff = abs(l - r)
		if diff == 0:
			print(l, r, l)
		elif diff == 1:
			if (l, l) in ranges:
				print(l, r, r)
			elif (r, r) in ranges:
				print(l, r, l)
		else:
			for i in range(r - 1, l - 1, -1):
				if (l, i) in ranges:
					print(l, r, i + 1)
					break
			else:
				if (l + 1, r) in ranges:
					print(l, r, l)
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		a = list(map(int, input().split()))
		l.append(a)
		l.sort()
	b1 = []
	b2 = []
	for j in l:
		b1.append(j[0])
		b2.append(j[1])
	for k in range(n):
		if b1[k] == b2[k]:
			l[k].append(b1[k])
		else:
			x = b2[k]
			b2[k] = -b2[k]
			if x in b2:
				l[k].append(b1[b2.index(x)] - 1)
			else:
				l[k].append(x)
	for j in l:
		print(*j, end=' ')


from sys import stdin
input = stdin.readline

def answer():
	for i in range(n):
		(l, r) = a[i]
		ele = -1
		for j in range(l, r + 1):
			d[j] -= 1
			if d.get(j, 0) == 0:
				if ele == -1:
					ele = j
		print(l, r, ele)
for T in range(int(input())):
	n = int(input())
	(a, d) = ([], dict())
	for i in range(n):
		(l, r) = map(int, input().split())
		a.append([l, r])
		for j in range(l, r + 1):
			d[j] = d.get(j, 0) + 1
	a.sort(key=lambda x: [x[0], -x[1]])
	answer()
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	cut = []
	for i in range(n):
		(l, r) = map(int, input().split())
		cut.append((r - l, l, r))
	cut.sort()
	chosen = [False] * (n + 1)
	for i in range(n):
		(__, l, r) = cut[i]
		candidate = []
		for j in range(l, r + 1):
			if not chosen[j]:
				d = j
				chosen[d] = True
				break
		print(l, r, d)


for _ in range(int(input())):
	n = int(input())
	pairs = []
	for _ in range(n):
		pairs.append(list(map(int, input().strip().split())))
	pairs.sort(key=lambda x: abs(x[0] - x[1]))
	s = set()
	ans = []
	for (a, b) in pairs:
		if a == b:
			s.add(a)
			ans.append(f'{a} {b} {a}')
		else:
			for r in range(a, b + 1):
				if r not in s:
					s.add(r)
					ans.append(f'{a} {b} {r}')
					break
	for a in ans:
		print(a)


from sys import setrecursionlimit
from bisect import bisect_left, bisect_right
from collections import deque
from functools import lru_cache, reduce
from heapq import heappush, heappop
from math import sqrt, ceil, floor, log2
T = int(input())

def rl(t=int):
	return list(map(t, input().split()))
for t in range(1, T + 1):
	n = int(input())
	r = []
	for _ in range(n):
		r.append(rl())
	ret = []
	have = set()
	r.sort(key=lambda t: t[1] - t[0])
	for (s, e) in r:
		for i in range(s, e + 1):
			if i not in have:
				break
		have.add(i)
		ret.append((s, e, i))
	for el in ret:
		print(' '.join(map(str, el)))
	print('\n')


t = int(input())
for _ in range(t):
	lst = []
	n = int(input())
	for i in range(n):
		lst.append(list(map(int, input().split())))
	lst.sort(key=lambda x: (x[0] - x[1], x[0]))
	for i in range(len(lst)):
		cur = lst[i]
		nxt = None
		for j in range(i + 1, len(lst)):
			if lst[j][0] >= cur[0] and lst[j][1] <= cur[1]:
				nxt = lst[j]
				break
		if nxt:
			if nxt[0] > cur[0]:
				print(f'{cur[0]} {cur[1]} {nxt[0] - 1}')
			elif nxt[1] < cur[1]:
				print(f'{cur[0]} {cur[1]} {nxt[1] + 1}')
			else:
				print(f'{cur[0]} {cur[1]} {cur[0]}')
		else:
			print(f'{cur[0]} {cur[1]} {cur[0]}')


t = int(input())
for _ in range(t):
	n = int(input())
	lis = []
	for i in range(n):
		(l, r) = map(int, input().split())
		lis.append((l, r))
	lis.sort(key=lambda x: x[1] - x[0])
	number = set()
	for (x, y) in lis:
		for num in range(x, y + 1):
			if num not in number:
				number.add(num)
				break
		print(x, y, num)
	print()


cases = int(input())
answers = []
for _ in range(cases):
	n = int(input())
	dic = {}
	already_in = {}
	for l_n in range(n):
		line = input().split(' ')
		if dic.get(int(line[1]) - int(line[0])) is not None:
			dic[int(line[1]) - int(line[0])].append((int(line[0]), int(line[1])))
		else:
			dic[int(line[1]) - int(line[0])] = [(int(line[0]), int(line[1]))]
	for key in range(0, n):
		if dic.get(key) is not None:
			for (w, k) in dic[key]:
				for i in range(w, k + 1):
					if already_in.get(i) is None:
						answers.append(str(w) + ' ' + str(k) + ' ' + str(i))
						already_in[i] = ''
						break
print('\n'.join(answers))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from itertools import permutations
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class SegmentTree:

	def __init__(self, data, default=(-2, -2), func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append((b - a + 1, a, b))
	l.sort()
	ans = []
	done = [0] * (n + 1)
	for i in range(n):
		(_, a, b) = l[i]
		for j in range(a, b + 1):
			if done[j] == 0:
				done[j] = 1
				ans.append((a, b, j))
				break
	for i in ans:
		print(*i)
	print()


def cmp(l1, l2):
	return l1[-1] - l1[0] > l2[-1] - l2[0]
t = int(input())
res = []
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		s = input().split()
		s = [int(k) for k in s]
		l.append(s)
	l.sort(key=lambda x: x[-1] - x[0])
	d = {}
	for j in l:
		if j[-1] - j[0] == 0:
			d[j[1]] = 1
			print(j[0], j[-1], j[1])
		else:
			for k in range(j[0], j[-1] + 1):
				if k not in d:
					d[k] = 1
					print(j[0], j[-1], k)


t = int(input())
for ppp in range(t):
	n = int(input())
	sussies = []
	for i in range(n):
		sussies.append(list(map(int, input().split())))
	sussies.sort(key=lambda x: x[1] - x[0])
	sus = set()
	ans = []
	for i in sussies:
		if i[0] == i[1]:
			ans.append((i[0], i[1], i[0]))
			sus.add(i[0])
		for j in range(i[0], i[1] + 1):
			if j not in sus:
				ans.append((i[0], i[1], j))
				sus.add(j)
	for i in ans:
		print(*i)


import array
import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		to = f(*args, **kwargs)
		if stack:
			return to
		else:
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						return to
					to = stack[-1].send(to)
	return wrappedfunc

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def dfs_utility(self, nodes, visited_nodes, colors, parity, level):
		global count
		if nodes == 1:
			colors[nodes] = -1
		elif len(self.graph[nodes]) == 1 and parity % 2 == 0:
			if q == 1:
				colors[nodes] = 1
			else:
				colors[nodes] = -1
				count += 1
		elif parity % 2 == 0:
			colors[nodes] = -1
		else:
			colors[nodes] = 1
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			new_level = level + 1
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)

	def dfs(self, node):
		Visited = set()
		color = collections.defaultdict()
		self.dfs_utility(node, Visited, color, 0, 0)
		return color

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1
		return False

class Tree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UnionFind:
	parents = []
	sizes = []
	count = 0

	def __init__(self, n):
		self.count = n
		self.parents = [i for i in range(n)]
		self.sizes = [1 for i in range(n)]

	def find(self, i):
		if self.parents[i] == i:
			return i
		else:
			self.parents[i] = self.find(self.parents[i])
			return self.parents[i]

	def unite(self, i, j):
		root_i = self.find(i)
		root_j = self.find(j)
		if root_i == root_j:
			return
		elif root_i < root_j:
			self.parents[root_j] = root_i
			self.sizes[root_i] += self.sizes[root_j]
		else:
			self.parents[root_i] = root_j
			self.sizes[root_j] += self.sizes[root_i]

	def same(self, i, j):
		return self.find(i) == self.find(j)

	def size(self, i):
		return self.sizes[self.find(i)]

	def group_count(self):
		return len(set((self.find(i) for i in range(self.count))))

	def answer(self, extra, p, q):
		dic = collections.Counter()
		for q in range(n):
			dic[self.find(q)] = self.size(q)
		hq = list(dic.values())
		heapq._heapify_max(hq)
		ans = -1
		for z in range(extra + 1):
			if hq:
				ans += heapq._heappop_max(hq)
			else:
				break
		return ans

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

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

def p_sum(array):
	return list(itertools.accumulate(array))

def base_change(nn, bb):
	if nn == 0:
		return [0]
	digits = []
	while nn:
		digits.append(int(nn % bb))
		nn //= bb
	return digits[::-1]

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
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, **kwargs):
		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))

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

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))

def interactive():
	return sys.stdout.flush()
for _ in range(int(inp())):
	n = int(inp())
	arr = []
	for i in range(n):
		(l, r) = map_inp(int)
		arr.append((l, r, r - l))
	arr = list(sorted(arr, key=lambda x: -x[2]))
	temp = set(arr)
	dic = {}
	it = queue([arr[0]])
	while it:
		item = it.popleft()
		temp.discard(item)
		if item[2] == 0 and item[1] == item[0]:
			dic[item[0], item[1]] = item[0]
			continue
		flag = 1
		for i in range(item[0], item[1] + 1):
			if i == item[0]:
				if (i + 1, item[1], item[1] - i - 1) in temp:
					dic[item[0], item[1]] = i
					it.append((i + 1, item[1], item[1] - i - 1))
					flag = 0
					break
			elif i == item[1]:
				if (item[0], i - 1, i - 1 - item[0]) in temp:
					dic[item[0], item[1]] = i
					it.append((item[0], i - 1, i - 1 - item[0]))
					flag = 0
					break
			elif (item[0], i - 1, i - 1 - item[0]) and (i + 1, item[1], item[1] - (i + 1)) in temp:
				dic[item[0], item[1]] = i
				it.append((item[0], i - 1, i - 1 - item[0]))
				it.append((i + 1, item[1], item[1] - (i + 1)))
				flag = 0
				break
		if flag:
			while True:
				print(item)
				exit()
	for item in dic.keys():
		print(*item, dic[item])


cases = int(input())
for i in range(cases):
	rows = int(input())
	full = []
	for x in range(rows):
		(l, r) = map(int, input().split())
		full.append((l, r))
	full.sort(key=lambda x: x[1] - x[0])
	number = set()
	for (a, b) in full:
		for num in range(a, b + 1):
			if num not in number:
				number.add(num)
				break
		print(a, b, num)
	print()


from __future__ import print_function
from math import log10
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
mod = 10 ** 9 + 7

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

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

def hash(a, b):
	return (a - 1) * n + b
global n

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
for _ in range(inp()):
	n = inp()
	cnt = [[0, i] for i in range(n)]
	l = []
	for i in range(n):
		(a, b) = invr()
		l.append((a, b))
		for i in range(a, b + 1):
			cnt[i - 1][0] += 1
	cnt.sort()
	q = set()
	q.add(n)
	for i in range(n):
		s = cnt[i][1] + 1
		for j in q:
			a = ceil(j, n)
			if j % n == 0:
				b = n
			else:
				b = j % n
			if a <= s and b >= s:
				print(a, b, s)
				q.remove(j)
				if s != a:
					q.add(hash(a, s - 1))
				if s != b:
					q.add(hash(s + 1, b))
				break


for _ in range(int(input())):
	n = int(input())
	q = []
	for i in range(n):
		q.append(list(map(int, input().split())))
	q.sort(key=lambda diff: abs(diff[0] - diff[1]))
	check = [0] * (n + 1)
	ans = []
	for ele in q:
		for i in range(ele[0], ele[1] + 1):
			if check[i] == 0:
				check[i] = 1
				ans.append([ele[0], ele[1], i])
				break
	for ele in ans:
		print(*ele)


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [[] for _ in range(n)]
		for _ in range(n):
			(l, r) = map(int, input().split())
			a[l - 1].append(r - 1)
		for ai in a:
			ai.sort()
		for i in range(n):
			while len(a[i]) >= 2:
				print(i + 1, a[i].pop() + 1, a[i][-1] + 2)
			if a[i]:
				print(i + 1, a[i][0] + 1, i + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._file = 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 _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	b = []
	for i in range(n):
		st = set()
		for j in range(a[i][0], a[i][1] + 1):
			st.add(j)
		b.append(st)
	was = [0] * n
	for i in range(1, n + 1):
		minl = 1000000000.0
		ind = 0
		for j in range(len(b)):
			if i in b[j] and len(b[j]) <= minl and (not was[j]):
				minl = len(b[j])
				ind = j
		print(*a[ind], i)
		was[ind] = 1
		for j in range(len(b)):
			if i in b[j]:
				b[j].remove(i)
	print()


problem_num = int(input())
for _ in range(problem_num):
	n = int(input())
	lst = []
	for i in range(n):
		(l, r) = map(int, input().split())
		lst.append((l, r))
	lst.sort(key=lambda x: x[1] - x[0])
	numb = set()
	for (x, y) in lst:
		for num in range(x, y + 1):
			if num not in numb:
				print(x, y, num)
				numb.add(num)
				break


t = int(input())
for i in range(t):
	n = int(input())
	matrix = []
	for i in range(n):
		matrix.append(list(map(int, input().split())))
	matrix.sort(key=lambda x: [x[0], -x[1]])
	for i in range(n - 1):
		if matrix[i][0] == matrix[i + 1][0]:
			print(matrix[i][0], matrix[i][1], matrix[i + 1][1] + 1)
		elif matrix[i][0] != matrix[i + 1][0]:
			print(matrix[i][0], matrix[i][1], matrix[i][0])
	print(matrix[n - 1][0], matrix[n - 1][1], matrix[n - 1][0])
	print('\r')


import sys
for t in range(int(input())):
	n = int(input())
	memo = [0 for _ in range(n)]
	rmemo = []
	for i in range(n):
		(a, b) = map(lambda x: int(x) - 1, input().split(' '))
		for j in range(a, b + 1):
			memo[j] += 1
		rmemo.append((a, b))
	for i in range(n):
		(a, b) = rmemo[i]
		idx = memo[a:b + 1].index(min(memo[a:b + 1]))
		print(a + 1, b + 1, idx + a + 1)
		memo[idx + a] = sys.maxsize


import queue
from sys import stdin, stdout

def test_case():
	n = int(stdin.readline().rstrip())
	pairs = set()
	(bl, br) = (0, -1)
	for i in range(n):
		(l, r) = [int(x) for x in stdin.readline().rstrip().split()]
		pairs.add((l, r))
		if r - l > br - bl:
			(bl, br) = (l, r)
	q = queue.Queue()
	q.put((bl, br))
	while not q.empty():
		(l, r) = q.get()
		if l == r:
			print(l, r, l)
			continue
		for d in range(l + 1, r):
			if (l, d - 1) in pairs and (d + 1, r) in pairs:
				q.put((l, d - 1))
				q.put((d + 1, r))
				print(l, r, d)
				continue
		if (l, r - 1) in pairs:
			q.put((l, r - 1))
			print(l, r, r)
			continue
		if (l + 1, r) in pairs:
			q.put((l + 1, r))
			print(l, r, l)
			continue
t = int(stdin.readline())
for i in range(t):
	test_case()


import sys
from collections import deque
import math
from bisect import bisect_left
from functools import cmp_to_key

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

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

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

def SI():
	return sys.stdin.readline().strip()

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
for _ in range(II()):
	n = II()
	d = [0 for i in range(n + 1)]
	ans = []
	for i in range(n):
		(l, r) = MI()
		for j in range(l, r + 1):
			d[j] += 1
		ans.append((l, r))
	temp = [i for i in range(1, n + 1)]
	temp.sort(key=lambda x: d[x])
	for i in temp:
		for (x, y) in ans:
			if i >= x and i <= y:
				ans.remove((x, y))
				print(x, y, i)
				break
	print()


import sys
input = sys.stdin.readline

def dfs(left, right):
	rights[left].pop()
	if left == right:
		print(left, left, left)
		return 0
	elif not rights[left]:
		print(left, right, left)
		dfs(left + 1, right)
	else:
		i = rights[left][-1]
		print(left, right, i + 1)
		if i >= 1:
			dfs(left, i)
		if i < n and i + 2 <= right:
			dfs(i + 2, right)
		return 0
for _ in range(int(input())):
	n = int(input())
	rights = [[] for _ in range(n + 1)]
	for _ in range(n):
		(l, r) = map(int, input().split())
		rights[l].append(r)
	for i in range(1, n + 1):
		rights[i].sort()
	dfs(1, n)


test = int(input())
for t in range(test):
	n = int(input())
	arr = []
	for _ in range(n):
		arr.append(list(map(int, input().strip().split())))
	arr.sort(key=lambda x: (x[0], -x[1]))
	for i in range(n):
		(curr0, curr1) = (arr[i][0], arr[i][1])
		print(curr0, curr1, end=' ')
		if curr0 == curr1:
			print(curr0)
		elif arr[i + 1][0] > curr0:
			print(curr0)
		else:
			print(arr[i + 1][1] + 1)


for _ in range(int(input())):
	n = int(input())
	seti = set()
	for i in range(n):
		(x, y) = map(int, input().split())
		seti.add((x - 1, y - 1))
	ans = []
	while len(seti):
		arr = [0] * (n + 1)
		for i in seti:
			arr[i[0]] += 1
			arr[i[1] + 1] -= 1
		ind = -1
		if arr[0] == 1:
			ind = 0
		else:
			for i in range(1, n):
				arr[i] += arr[i - 1]
				if arr[i] == 1:
					ind = i
					break
		for i in seti:
			if ind >= i[0] and ind <= i[1]:
				seti.remove(i)
				ans.append([i[0] + 1, i[1] + 1, ind + 1])
				break
	for i in ans:
		print(*i)


import random
import sys
import os
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
MOD = 1000000007

def calc(n, a):
	a.sort(key=lambda x: (x[0], -x[1]))
	for i in range(n - 1):
		(x, y, z) = (a[i][0], a[i][1], a[i + 1][1])
		if x == y:
			print(x, y, x)
		elif x != a[i + 1][0]:
			print(x, y, x)
		else:
			print(x, y, z + 1)
	x = a[-1][0]
	print(x, x, x)

def solve():
	global tcases
	n = int(sys.stdin.readline())
	a = []
	for _ in range(n):
		pair = tuple(map(int, sys.stdin.readline().split()))
		a.append(pair)
	calc(n, a)

def test():
	for _z in range(100000):
		(n, k) = [random.randint(5, 20) for _ in range(2)]
		a = [random.randint(1, 10) for _ in range(n)]
		calc(n, k, a)
tcases = int(sys.stdin.readline())
if tcases < 0:
	test()
	exit(0)
for _ in range(tcases):
	solve()


import sys, os, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def readint():
	return int(input())

def readstr():
	return list(map(str, input().split()))

def readstr2():
	return list(map(int, input().split()))
cases = readint()

def solve(its, arr):
	graph = defaultdict(set)
	new = []
	for (s, e) in arr:
		new.append([-(e - s), s, e])
	new.sort()
	start = [new[0][1], new[0][2]]
	for (_, s, e) in new[1:]:
		graph[s].add((s, e))
		graph[e].add((s, e))
	out = defaultdict(set)
	seen = set([(start[0], start[1])])

	def dfs(s, e):
		nonlocal seen
		last = True
		if s in graph:
			for (ns, ne) in graph[s]:
				if (ns, ne) not in seen:
					last = False
					seen.add((ns, ne))
					if (s, e) not in out:
						out[s, e] = ne + 1
					dfs(ns, ne)
		if e in graph:
			for (ns, ne) in graph[e]:
				if (ns, ne) not in seen:
					last = False
					seen.add((ns, ne))
					if (s, e) not in out:
						out[s, e] = ns - 1
					dfs(ns, ne)
		if last:
			out[s, e] = s
	dfs(start[0], start[1])
	for (s, e) in arr:
		print(s, e, out[s, e])
	return
for _ in range(int(cases)):
	its = readstr2()[0]
	arr = []
	for _ in range(its):
		arr.append(readstr2())
	solve(its, arr)
	print('')


import heapq

def problem2(arr):
	ans = []
	visited = set()
	heap = []
	for (left, right) in arr:
		heapq.heappush(heap, (right - left + 1, left, right))
	while heap:
		(n, left, right) = heapq.heappop(heap)
		for num in range(left, right + 1):
			if num in visited:
				continue
			visited.add(num)
			ans.append((left, right, num))
			print(left, right, num)
			break
for _ in range(int(input())):
	n = int(input())
	ranges = []
	for _ in range(n):
		ranges.append([int(num) for num in input().split(' ')])
	problem2(ranges)


t = int(input())
import sys
for _ in range(t):
	m = []
	n = int(sys.stdin.readline())
	for i in range(n):
		m.append(list(map(int, sys.stdin.readline().split())))
	m.sort(key=lambda x: (x[0], -x[1]))
	for i in range(len(m) - 1):
		if m[i + 1][0] == m[i][0]:
			m[i].append(m[i + 1][1] + 1)
		else:
			m[i].append(m[i][0])
	m[-1].append(m[-1][0])
	for i in range(len(m)):
		print(*m[i])


for _ in range(int(input())):
	a = []
	for _ in range(int(input())):
		a.append(tuple(map(int, input().split())))
	a.sort(key=lambda x: (x[0], -x[1]))
	for i in range(len(a)):
		if i == len(a) - 1 and a[i][0] != a[i][1]:
			print(a[i][0], a[i][1], a[i][0])
			continue
		if a[i][0] == a[i][1]:
			print(a[i][0], a[i][0], a[i][0])
			continue
		(x, b, c, d) = (a[i][0], a[i][1], a[i + 1][0], a[i + 1][1])
		if c > x:
			print(x, b, c - 1)
			continue
		if b > d:
			print(x, b, d + 1)
			continue
	print()


import bisect
for _ in range(int(input())):
	n = int(input())
	vals = {}
	ranges = []
	for i in range(n):
		(l, r) = map(int, input().split())
		if vals.get(l) == None:
			vals[l] = {'r': [r], 'l': []}
		else:
			vals[l]['r'].append(r)
		if vals.get(r) == None:
			vals[r] = {'r': [], 'l': [l]}
		else:
			vals[r]['l'].append(l)
		ranges.append([l, r])
	for v in vals:
		vals[v]['r'].sort()
		vals[v]['l'].sort()
	for i in ranges:
		if i[0] == i[1]:
			i.append(i[1])
		else:
			jr = bisect.bisect_left(vals[i[0]]['r'], i[1])
			jl = bisect.bisect_left(vals[i[1]]['l'], i[0])
			if jl == len(vals[i[1]]['l']) - 1:
				i.append(i[1])
			elif jr == 0:
				i.append(i[0])
			else:
				i.append(vals[i[0]]['r'][jr - 1] + 1)
	for i in ranges:
		print(*i)
	print()


result = []
for _ in range(int(input())):
	n = int(input())
	a = sorted([list(map(int, input().split())) for i in range(n)], key=lambda x: x[1] - x[0])
	filled = [False for i in range(n)]
	for (l, r) in a:
		for c in range(l, r + 1):
			if not filled[c - 1]:
				filled[c - 1] = True
				break
		result.append([l, r, c])
print('\n'.join(map(lambda x: ' '.join(map(str, x)), result)))


for iii in range(int(input())):
	n = int(input())
	q = []
	q1 = {}
	for i in range(n):
		(x, y) = map(int, input().split())
		q.append([x, y])
		q1[x, y] = 1
	for (l, r) in q:
		if l == r:
			print(l, r, r)
		elif (l + 1, r) in q1:
			print(l, r, l)
		elif (l, r - 1) in q1:
			print(l, r, r)
		else:
			for i in range(l + 1, r):
				if (l, i - 1) in q1 and (i + 1, r) in q1:
					print(l, r, i)
					break


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	n = I()
	l = []
	d = {}
	for i in range(n):
		l.append(L())
	l.sort(key=lambda x: -(x[1] - x[0] + 1))
	for i in l:
		for j in range(i[0], i[1] + 1):
			d[j] = d.get(j, 0) + 1
	for i in range(n):
		(a, b) = l[i]
		p = []
		for j in range(l[i][0], l[i][1] + 1):
			d[j] -= 1
		for j in range(a, b + 1):
			if d[j] == 0:
				print(a, b, j)
				break


for _ in range(int(input())):
	n = int(input())
	dic = dict()
	for _ in range(n):
		(l, r) = map(int, input().split())
		dic[l] = dic.get(l, []) + [r]
	key = sorted(dic.keys())
	for i in range(len(key)):
		temp = sorted(dic[key[i]], reverse=True)
		for j in range(len(temp) - 1):
			print(key[i], temp[j], temp[j + 1] + 1)
		print(key[i], temp[-1], key[i])


t = int(input())

def sort(L, R, a):
	if L >= R:
		return
	pivot = R
	storeIndex = R - 1
	for i in range(R - 1, L - 1, -1):
		if a[pivot][0] > a[i][0] or (a[pivot][0] == a[i][0] and a[pivot][1] > a[i][1]):
			(a[storeIndex], a[i]) = (a[i], a[storeIndex])
			storeIndex -= 1
	(a[pivot], a[storeIndex + 1]) = (a[storeIndex + 1], a[pivot])
	sort(L, storeIndex, a)
	sort(storeIndex + 2, R, a)
	return
for k in range(t):
	n = int(input())
	li = []
	free = []
	for i in range(n):
		current = tuple((int(x) for x in input().split()))
		li.append(current)
		free.append(True)
	if n == 1:
		print(1, 1, 1)
	else:
		sort(0, n - 1, li)
		for i in range(0, n):
			for j in range(li[i][1], li[i][0] - 1, -1):
				if free[j - 1]:
					print(li[i][0], li[i][1], j)
					free[j - 1] = False
					break


import sys
import math
from itertools import accumulate

def read_string():
	return sys.stdin.readline().strip()

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

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

def solve():
	n = int(input())
	ranges = []
	for _ in range(n):
		ranges.append(tuple(read_ints()))
	ranges.sort(key=lambda k: k[1] - k[1] + 1)
	hash_ranges = {}
	for (a, b) in ranges:
		hash_ranges[a, b] = True
	ans = []
	for (i, (a, b)) in enumerate(ranges):
		if a == b:
			ans.append(a)
		elif (a, b - 1) in ranges:
			ans.append(b)
		elif (a + 1, b) in ranges:
			ans.append(a)
		else:
			for k in range(a + 1, b):
				if (a, k - 1) in ranges and (k + 1, b) in ranges:
					ans.append(k)
	for i in range(n):
		print(ranges[i][0], ranges[i][1], ans[i])
T = int(input())
for i in range(T):
	solve()
	if i != T - 1:
		print()


t = int(input())
for test in range(t):
	n = int(input())
	l = []
	d = {}
	for i in range(1, n + 1):
		d[i] = 1
	for i in range(n):
		l1 = []
		(a, b) = map(int, input().split())
		c = abs(a - b)
		l1.append(c)
		l1.append(a)
		l1.append(b)
		if a == b:
			l1.append(a)
			d[a] = 0
		else:
			l1.append(0)
		l.append(l1)
	l.sort()
	for i in range(n):
		if l[i][3] == 0:
			for j in range(l[i][1], l[i][2] + 1):
				if d[j] == 1:
					l[i][3] = j
					d[j] = 0
					break
	for i in range(n):
		print(l[i][1], l[i][2], l[i][3])


from sys import stdin
import math
from collections import deque
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
input = stdin.readline

def ceil(m, n):
	val = m // n
	if m % n != 0:
		return val + 1
	return val

def ms(x, y):
	return str(x) + ' ' + str(y)
for _ in range(int(input())):
	n = int(input())
	given = []
	deg = {i: 0 for i in range(1, n + 1)}
	for _ in range(n):
		(x, y) = map(int, input().split())
		for i in range(x, y + 1):
			deg[i] += 1
	steps = 0
	ranges = [[1, n]]
	while steps < n:
		(minval, minidx) = (n + 1, 0)
		for key in deg.keys():
			if deg[key] <= minval:
				minval = deg[key]
				minidx = key
		key = minidx
		(x, y) = ranges.pop()
		if key >= x + 1:
			ranges.append([x, key - 1])
		if key <= y - 1:
			ranges.append([key + 1, y])
		for i in range(x, y + 1):
			deg[i] -= 1
		print(x, y, key)
		deg.pop(key)
		steps += 1
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	h = {i: [] for i in range(n)}
	ans = {}
	s = set()
	for i in range(n):
		a = [int(i) for i in input().split()]
		h[a[1] - a[0]].append(a)
	for i in range(n):
		for j in h[i]:
			for k in range(j[0], j[1] + 1):
				if k not in s:
					ans[tuple(j)] = k
					s.add(k)
					break
	for i in ans:
		print(i[0], i[1], ans[i])