There are N people numbered from 1 to N such that:
Exactly one of these people is a thief and always lies;
All the others are honest and always tell the truth. 

If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief.

It is guaranteed that at least one person can be the thief.

------ Input Format ------ 

- First line will contain T, the number of test cases. Then the test cases follow.
- First line of each test case will contain N, the number of people. N lines follow. 
- The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is.

------ Output Format ------ 

- For each test case, in the first line, output K, the number of possible thieves. 
- In the next K lines, output the list of people that could be the thieves, in ascending order. 

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$3 ≤ N ≤ 10^{5}$
$1 ≤ L_{i} ≤ R_{i} ≤ N$
- Sum of $N$ over all test cases does not exceed $10^{5}$.
- It is guaranteed that at least one person can be the thief.

----- Sample Input 1 ------ 
1
4
2 2
1 1
1 3
1 3
----- Sample Output 1 ------ 
2
1
2
----- explanation 1 ------ 
Test case $1$: Two people (numbered $1$ and $2$) can be thief:
- Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. 
- Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. 
- Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. 
- Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Range queries

Complete search


Solutions:
for _ in range(int(input())):
	n = int(input())
	(arr, ll, rl, lr) = ([i for i in range(1, n + 1)], [0 for i in range(n)], [0 for i in range(n)], [])
	for i in range(n):
		(l, r) = map(int, input().split())
		lr.append([l, r])
		ll[l - 1] += 1
		rl[r - 1] += 1
	(ans, l1, r1) = ([max(ll[0], rl[0])], ll[0], rl[0])
	for i in range(1, n):
		ans.append(l1 + ll[i] - r1)
		l1 += ll[i]
		r1 += rl[i]
	ans1 = []
	for i in range(1, n + 1):
		if lr[i - 1][0] <= i <= lr[i - 1][1]:
			continue
		if ans[i - 1] == n - 1:
			ans1.append(i)
	print(len(ans1))
	for i in ans1:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	res = [0] * (n + 1)
	d = dict()
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		l = l - 1
		r = r - 1
		res[l] += 1
		res[r + 1] -= 1
		d[i] = (l, r)
	for i in range(1, n):
		res[i] = res[i - 1] + res[i]
	op = []
	for i in range(n):
		if res[i] == n - 1:
			(u, v) = d[i]
			if not (i >= u and i <= v):
				op.append(i + 1)
	print(len(op))
	for i in op:
		print(i)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	suspicion = [0] * n
	interogations = []
	for i in range(n):
		(x, y) = [int(x) for x in input().split()]
		interogations.append((x - 1, y - 1))
		x -= 1
		suspicion[x] += 1
		if y < n:
			suspicion[y] -= 1
	curSum = 0
	for i in range(n):
		curSum += suspicion[i]
		suspicion[i] = curSum
	suspects = []
	for i in range(n):
		if suspicion[i] == n - 1 and (interogations[i][0] > i or interogations[i][1] < i):
			suspects.append(i + 1)
	print(len(suspects))
	for i in suspects:
		print(i)


t = int(input())
while t >= 1:
	t -= 1
	n = int(input())
	arr = [0 for i in range(n + 2)]
	ind = [True for i in range(n + 2)]
	for i in range(n):
		(l, r) = map(int, input().split(' '))
		arr[l] += 1
		arr[r + 1] -= 1
		if i + 1 >= l and i + 1 <= r:
			ind[i + 1] = False
	ans = 0
	l = []
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
		if arr[i] == n - 1 and ind[i] == True:
			ans += 1
			l.append(i)
	print(ans)
	for each in l:
		print(each)


t = int(input())
while t:
	n = int(input())
	arr = [0] * (n + 1)
	l = [-1] * (n + 1)
	r = [-1] * (n + 1)
	for i in range(1, n + 1):
		(li, ri) = [int(x) for x in input().split()]
		l[i] = li
		r[i] = ri
		arr[li] += 1
		if ri < n:
			arr[ri + 1] -= 1
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
	ans = []
	for i in range(1, n + 1):
		if arr[i] == n - 1 and (not (l[i] <= i and i <= r[i])):
			ans.append(i)
	print(len(ans))
	for el in ans:
		print(el)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = [0] * (n + 1)
	d = dict()
	for i in range(n):
		(l, r) = map(int, input().split())
		(l, r) = (l - 1, r - 1)
		arr[l] += 1
		arr[r + 1] -= 1
		d[i] = (l, r)
	cur = arr[0]
	for i in range(1, n + 1):
		arr[i] = cur + arr[i]
		cur = arr[i]
	res = []
	for i in range(n):
		if arr[i] == n - 1:
			(u, v) = d[i]
			if not (i >= u and i <= v):
				res.append(i + 1)
	print(len(res))
	for i in res:
		print(i)


t = int(input())

def update(l, r, range_sum):
	if l > r:
		return
	range_sum[l] += 1
	range_sum[r + 1] -= 1
while t:
	t -= 1
	n = int(input())
	range_sum = [0] * (n + 1)
	curr_person = 0
	notthief = set()
	while curr_person < n:
		(l, r) = [int(x) for x in input().split(' ')]
		l -= 1
		r -= 1
		if curr_person >= l and curr_person <= r:
			notthief.add(curr_person)
			update(l, curr_person - 1, range_sum)
			update(curr_person + 1, r, range_sum)
		else:
			update(l, r, range_sum)
		curr_person += 1
	cum_sum = 0
	result = []
	for curr in range_sum[:-1]:
		cum_sum += curr
		result.append(cum_sum)
	maybe_theif = []
	for (idx, freq) in enumerate(result):
		if freq == n - 1:
			if idx not in notthief:
				maybe_theif.append(idx)
	print(len(maybe_theif))
	for theif in maybe_theif:
		print(theif + 1)


from bisect import bisect_right, bisect_left

def solve(n, claim):
	starts = []
	ends = []
	for (l, r) in claim:
		starts.append(l)
		ends.append(r)
	starts.sort()
	ends.sort()
	thieves = []
	for i in range(1, n + 1):
		if claim[i - 1][0] <= i <= claim[i - 1][1]:
			continue
		s = bisect_right(starts, i)
		e = bisect_left(ends, i)
		if s - e == n - 1:
			thieves.append(i)
	return thieves
for _ in range(int(input())):
	n = int(input())
	claim = []
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		claim.append((l, r))
	thieves = solve(n, claim)
	print(len(thieves))
	for person in thieves:
		print(person)


for _ in range(int(input())):
	n = int(input())
	freq = [0] * (n + 1)
	ans = []
	for i in range(n):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		freq[l] += 1
		freq[r + 1] -= 1
		if i < l or i > r:
			ans.append(i + 1)
	for i in range(1, n):
		freq[i] = freq[i] + freq[i - 1]
	res = []
	for num in ans:
		if freq[num - 1] == n - 1:
			res.append(num)
	print(len(res))
	for i in res:
		print(i)


t = int(input())
for i in range(t):
	n = int(input())
	votes = [0 for i in range(n)]
	cand = []
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		l -= 1
		r -= 1
		votes[l] = votes[l] + 1
		if r + 1 < n:
			votes[r + 1] = votes[r + 1] - 1
		if i < l or i > r:
			cand.append(i + 1)
	for i in range(1, n):
		votes[i] = votes[i - 1] + votes[i]
	li = []
	cnt = 0
	for i in range(len(votes)):
		if votes[i] == n - 1 and i + 1 in cand:
			cnt += 1
			li.append(i + 1)
	li.sort()
	print(cnt)
	for i in li:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [0 for _ in range(n + 2)]
	ranges = {}
	for i in range(n):
		(l, r) = map(int, input().split())
		arr[l] += 1
		arr[r + 1] -= 1
		ranges[i + 1] = [l, r]
	thieves = []
	ans = 0
	for i in range(1, n + 1):
		ans += arr[i]
		if (i < ranges[i][0] or i > ranges[i][1]) and ans == n - 1:
			thieves.append(i)
	print(len(thieves))
	for t in thieves:
		print(t)


for _ in range(int(input())):
	n = int(input())
	l = []
	call = []
	mark = [0]
	mp = {}
	for i in range(1, n + 1):
		l.append(i)
		mp[i] = 0
		mark.append(0)
	for i in range(n):
		(a, b) = map(int, input().split())
		mark[a - 1] += 1
		mark[b] -= 1
		if i + 1 <= b and i + 1 >= a:
			call.append(-1)
		else:
			call.append(1)
	for i in range(1, n):
		mark[i] += mark[i - 1]
	max_ = 0
	for i in range(n):
		mark[i] += call[i]
		max_ = max(max_, mark[i])
	for i in range(n):
		mp[l[i]] = mark[i]
	ans = []
	for i in range(n):
		if mp[l[i]] == max_:
			ans.append(l[i])
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i])


t = int(input())
while t > 0:
	n = int(input())
	arr = [0 for _ in range(n + 2)]
	ma = {}
	for i in range(1, n + 1):
		[l, r] = [int(x) for x in input().split()]
		arr[l] += 1
		arr[r + 1] -= 1
		if i >= l and i <= r:
			ma[i] = True
	ct = 0
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
		if arr[i] == n - 1 and i not in ma:
			ct += 1
	print(str(ct))
	for i in range(1, n + 1):
		if arr[i] == n - 1 and i not in ma:
			print(str(i))
	t -= 1


def solve(intervals):
	(start, end) = intervals.pop()
	ans = [[start, end]]
	while intervals:
		(start_temp, end_temp) = intervals.pop()
		start = max(start, start_temp)
		end = min(end, end_temp)
		ans.append([start, end])
	return ans
t = int(input())
for i in range(t):
	N = int(input())
	intervals = []
	lstt = []
	ans = []
	faltu = []
	for i in range(N):
		arr = [int(i) for i in input().split()]
		intervals.append(arr)
		lstt.append(arr)
		faltu.append(arr)
	arr1 = solve(intervals)
	lstt = lstt[::-1]
	arr2 = solve(lstt)
	z = 0
	for i in range(N):
		if i == 0:
			realinfo = arr1[N - 2]
		elif i == N - 1:
			realinfo = arr2[N - 2]
		else:
			info = solve([arr2[i - 1], arr1[N - i - 2]])
			realinfo = info[-1]
		if realinfo[1] < realinfo[0]:
			pass
		elif realinfo[0] <= i + 1 <= realinfo[1]:
			if faltu[i][0] <= i + 1 <= faltu[i][1]:
				pass
			else:
				ans.append(i + 1)
				z += 1
		else:
			pass
	print(z)
	for i in ans:
		print(i)


for _ in range(int(input())):
	n = int(input())
	arr = [0] * (n + 1)
	d = dict()
	for i in range(n):
		(l, r) = map(int, input().split(' '))
		(l, r) = (l - 1, r - 1)
		arr[l] += 1
		arr[r + 1] -= 1
		d[i] = (l, r)
	curr = arr[0]
	for i in range(1, n + 1):
		arr[i] = curr + arr[i]
		curr = arr[i]
	ans = []
	for i in range(n):
		if arr[i] == n - 1:
			(u, v) = d[i]
			if not (i >= u and i <= v):
				ans.append(i + 1)
	print(len(ans))
	for item in ans:
		print(item)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = [0 for _ in range(n + 1)]
	temp = []
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		l -= 1
		arr[l] += 1
		arr[r] -= 1
		temp.append([l, r - 1])
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
	ans = []
	for i in range(n):
		if i >= temp[i][0] and i <= temp[i][1]:
			continue
		if arr[i] == n - 1:
			ans.append(i + 1)
	print(len(ans))
	for i in ans:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	votes = [0] * (n + 1)
	candidates = []
	for i in range(n):
		(left, right) = list(map(int, input().split()))
		left -= 1
		right -= 1
		votes[left] += 1
		votes[right + 1] -= 1
		if i < left or i > right:
			candidates.append(i + 1)
	for i in range(1, n + 1):
		votes[i] += votes[i - 1]
	res = []
	for candidate in candidates:
		if votes[candidate - 1] == n - 1:
			res.append(candidate)
	print(len(res))
	for candidate in res:
		print(candidate)


def segf(arr, n):
	temp = [0 for i in range(n + 1)]
	for lst in arr:
		l = lst[0]
		r = lst[1]
		temp[l - 1] += 1
		temp[r] -= 1
	for i in range(1, n + 1):
		temp[i] += temp[i - 1]
	count = 0
	ans = []
	for i in range(1, n + 1):
		lst = arr[i - 1]
		if (i < lst[0] or i > lst[1]) and temp[i - 1] == n - 1:
			count += 1
			ans.append(i)
	print(count)
	for e in ans:
		print(e)
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		temp = list(map(int, input().split()))
		arr.append(temp)
	segf(arr, n)


for _ in range(int(input())):
	n = int(input())
	arr = [0] * (n + 1)
	mapp = {}
	for i in range(n):
		(s, e) = map(int, input().split())
		mapp[i] = (s - 1, e - 1)
		arr[s - 1] += 1
		arr[e] -= 1
	(s, e) = mapp[0]
	ans = [1] if arr[0] == n - 1 and (not s <= 0 <= e) else []
	for i in range(1, n):
		arr[i] += arr[i - 1]
		(s, e) = mapp[i]
		if arr[i] == n - 1 and (not s <= i <= e):
			ans.append(i + 1)
	print(len(ans))
	for i in ans:
		print(i)


def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	if b == 0:
		return a
	return gcd(b, a % b)
import sys

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

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

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	n = int(input())
	pre = [0 for i in range(n)]
	isThief = [True for i in range(n)]

	def solve():
		for i in range(n):
			(l, r) = get_ints()
			l -= 1
			r -= 1
			pre[l] += 1
			if r != n - 1:
				pre[r + 1] -= 1
			if i >= l and i <= r:
				isThief[i] = False
		cnt = [pre[0] for _ in range(n)]
		for i in range(1, n):
			cnt[i] = cnt[i - 1] + pre[i]
		for i in range(n):
			if cnt[i] != n - 1:
				isThief[i] = False
		res = isThief.count(True)
		print(res)
		for i in range(n):
			if isThief[i]:
				print(i + 1)
	solve()


for _ in range(int(input())):
	n = int(input())
	a = [0] * (n + 1)
	nth = set()
	for i in range(1, n + 1):
		(l, r) = map(int, input().split())
		a[l - 1] += 1
		a[r] -= 1
		if l <= i <= r:
			nth.add(i)
	for i in range(n):
		a[i + 1] += a[i]
	th = []
	for i in range(1, n + 1):
		if i not in nth and a[i - 1] == n - 1:
			th.append(i)
	print(len(th))
	for t in th:
		print(t)


for i in range(int(input())):
	a = int(input())
	l = []
	for i in range(a):
		l.append(list(map(int, input().split(' '))))
	r = [0] * (a + 2)
	choose = []
	for i in range(a):
		if i + 1 < l[i][0] or i + 1 > l[i][1]:
			choose.append(i + 1)
	for i in range(a):
		r[l[i][0] - 1] += 1
		r[l[i][1]] -= 1
	sum = [0] * (a + 1)
	k = 0
	for i in range(a + 1):
		k += r[i]
		sum[i] = k
	cnt = 0
	ans = []
	for i in range(len(choose)):
		if sum[choose[i] - 1] == a - 1:
			ans.append(choose[i])
	print(len(ans))
	print(*ans, sep='\n')


import sys
input = sys.stdin.readline
M = int(1000000000.0) + 7

def solve():
	n = int(input())
	lr = [[int(x) - 1 for x in input().split()] for _ in range(n)]
	pre = [0] * (n + 1)
	for (i, j) in lr:
		pre[i] += 1
		pre[j + 1] -= 1
	for i in range(1, n + 1):
		pre[i] += pre[i - 1]
	ans = []
	for i in range(n):
		if pre[i] == n - 1:
			if lr[i][0] <= i and i <= lr[i][1]:
				continue
			ans.append(i + 1)
	print(len(ans))
	for i in ans:
		print(i)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	ans = []
	nums = []
	people = [0] * (n + 1)
	for i in range(n):
		(l, r) = map(int, input().split())
		nums.append([l, r])
		people[l] += 1
		if r < n:
			people[r + 1] -= 1
	for i in range(2, n + 1):
		people[i] += people[i - 1]
	for i in range(1, n + 1):
		if people[i] == n - 1 and (i < nums[i - 1][0] or i > nums[i - 1][1]):
			ans.append(i)
	print(len(ans))
	for i in ans:
		print(i)


from itertools import accumulate as acc

def miis():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list((list(miis()) for i in range(n)))
	pref = [0 for i in range(n + 1)]
	for i in a:
		(l, r) = i
		pref[l - 1] += 1
		pref[r] -= 1
	ac = list(acc(pref))
	th = []
	for i in range(n):
		if ac[i] == n - 1 and (a[i][0] > i + 1 or a[i][1] < i + 1):
			th.append(i + 1)
	print(len(th))
	print(*th, sep='\n')


t = int(input())
for i in range(0, t):
	n = int(input())
	d = {}
	for j in range(0, n + 1):
		d[j] = 0
	s = set()
	for j in range(0, n):
		(a, b) = map(int, input().split(' '))
		if a <= j + 1 <= b:
			s.add(j + 1)
		d[a - 1] += 1
		d[b] -= 1
	ans = []
	for j in range(1, n + 1):
		d[j] += d[j - 1]
	for j in range(0, n):
		if d[j] == n - 1 and j + 1 not in s:
			ans.append(j + 1)
	print(len(ans))
	for j in ans:
		print(j)


for _ in range(int(input())):
	n = int(input())
	arr = [0] * (n + 1)
	s = set()
	for i in range(n):
		(a, b) = map(int, input().split())
		if a <= i + 1 <= b:
			s.add(i + 1)
		arr[a - 1] += 1
		arr[b] -= 1
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
	ans = []
	for i in range(len(arr)):
		if arr[i] == n - 1 and i + 1 not in s:
			ans += [i + 1]
	print(len(ans))
	print(*ans, sep='\n')


import math
import sys
from collections import deque

def answer(n):
	check = []
	for i in range(n + 2):
		check.append(0)
	check2 = []
	for i in range(n):
		check2.append(0)
	for i in range(n):
		txt = input()
		(l, r) = list(map(int, txt.split(' ')))
		check[l] += 1
		check[r + 1] += -1
		if i + 1 >= l and i + 1 <= r:
			check2[i] = 1
	for i in range(1, n + 1):
		check[i] = check[i] + check[i - 1]
	check = deque(check)
	check.popleft()
	check.pop()
	ans = []
	for i in range(n):
		if check[i] >= n - 1 and check2[i] == 0:
			ans.append(i + 1)
	print(len(ans))
	for ele in ans:
		print(ele)
t = int(input())
for test in range(t):
	n = int(input())
	answer(n)


import math
import collections
import sys
for _ in range(int(input())):
	N = int(input())
	A = []
	for _ in range(N):
		A.append(list(map(int, input().split())))
	l = -sys.maxsize
	r = sys.maxsize
	B = [[0, 0] for i in range(N)]
	for i in range(N - 1, -1, -1):
		l = max(l, A[i][0])
		r = min(r, A[i][1])
		B[i][0] = l
		B[i][1] = r
	l = -sys.maxsize
	r = sys.maxsize
	E = []
	for i in range(N):
		(C, D) = (l, r)
		if i + 1 < N:
			C = max(B[i + 1][0], l)
			D = min(B[i + 1][1], r)
		if C <= i + 1 and D >= i + 1:
			if A[i][0] > i + 1 or A[i][1] < i + 1:
				E.append(i + 1)
		l = max(A[i][0], l)
		r = min(A[i][1], r)
	print(len(E))
	for i in E:
		print(i)


t = int(input())
while t > 0:
	n = int(input())
	a = []
	for i in range(n):
		a.append([int(i) for i in input().split()])
	ls = [a[i][0] for i in range(len(a))]
	rs = [a[i][1] for i in range(len(a))]
	(ls, rs) = (sorted(ls), sorted(rs))
	k = []
	for i in range(1, n + 1):
		if i < a[i - 1][0] or i > a[i - 1][1]:
			(l, r) = (ls[-1], rs[0])
			if a[i - 1][0] == ls[-1]:
				l = ls[-2]
			if a[i - 1][1] == rs[0]:
				r = rs[1]
			if i <= r and i >= l:
				k.append(i)
	print(len(k))
	k = sorted(k)
	for i in range(len(k)):
		print(k[i])
	t -= 1


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd, ceil, log2
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def yn(a):
	print('YES' if a else 'NO')
cl = lambda a, b: (a + b - 1) // b

class RangeQuery:

	def __init__(self, data, func=min, default=0):
		self.func = func
		self._data = _data = [list(data)]
		self.defualt = default
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1
		self.bit_len = [0 for i in range(n + 1)]
		for i in range(1, n + 1):
			self.bit_len[i] = self.bit_len[i // 2] + 1

	def query_normal(self, start, stop):
		ans = self.defualt
		for j in range(self.bit_len[stop - start] - 1, -1, -1):
			if 1 << j <= stop - start:
				ans = self.func(ans, self._data[j][start])
				start += 1 << j
		return ans

	def query(self, start, stop):
		depth = self.bit_len[stop - start] - 1
		return self.func(self._data[depth][start], self._data[depth][stop - (1 << depth)])

	def __getitem__(self, idx):
		return self._data[0][idx]

def fun(l, r):
	start = max(l[0], r[0])
	end = min(l[1], r[1])
	if start > end:
		return [0, 0]
	return [start, end]
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		(l, r) = [int(i) for i in input().split()]
		arr.append([l, r])
	q = RangeQuery(arr, fun, [1, n])
	counter = []
	for i in range(n):
		(a, b) = ([1, n], [1, n])
		l = arr[i]
		if i != 0:
			a = q.query(0, i)
		if i != n - 1:
			b = q.query(i + 1, n)
		ans = a
		ans = fun(ans, b)
		if ans[0] <= i + 1 <= ans[1] and (not l[0] <= i + 1 <= l[1]):
			counter.append(i)
	print(len(counter))
	for i in counter:
		print(i + 1)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	suff = [[0, 0]] * n
	(a, b) = (1, n)
	for i in range(n - 1, -1, -1):
		(a, b) = (max(a, arr[i][0]), min(b, arr[i][1]))
		if a <= b:
			suff[i] = [a, b]
	suff.append([1, n])
	(a, b) = (1, n)
	ans = []
	for i in range(n):
		if suff[i + 1] != [0, 0]:
			(c, d) = (max(a, suff[i + 1][0]), min(b, suff[i + 1][1]))
			if not arr[i][0] <= i + 1 <= arr[i][1] and c <= i + 1 <= d:
				ans.append(i + 1)
		(a, b) = (max(a, arr[i][0]), min(b, arr[i][1]))
	print(len(ans))
	for e in ans:
		print(e)


import sys
import numpy as np
input = sys.stdin.readline

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

def inlt(input):
	return list(map(int, input().split()))
t = inp()
for _ in range(t):
	n = inp()
	cand = [0] * (n + 2)
	store = [None]
	for _ in range(n):
		(start, end) = inlt(input)
		store.append((start, end))
		cand[start] += 1
		cand[end + 1] -= 1
	cumsum = list(np.cumsum(cand))
	count = []
	found = -1
	for i in range(1, n + 1):
		if cumsum[i] == n - 1:
			if not store[i][0] <= i <= store[i][1]:
				count.append(i)
	print(len(count))
	for i in range(len(count)):
		print(count[i])


def Solution(l1, l2, n):
	arr = [0 for i in range(n + 2)]
	for i in range(0, n):
		arr[l1[i]] += 1
		arr[l2[i] + 1] -= 1
	msum = arr[0]
	for i in range(1, n + 2):
		arr[i] += arr[i - 1]
	return arr
import collections
for _ in range(int(input())):
	n = int(input())
	p = []
	d2 = collections.defaultdict(lambda : 0)
	for z in range(1, n + 1):
		(l, r) = map(int, input().split())
		p.append((l, r))
	q = p.copy()
	p.sort()
	l1 = []
	l2 = []
	for (x, y) in p:
		l1.append(x)
		l2.append(y)
	ans = Solution(l1, l2, n)
	t = []
	for i in range(n + 1):
		if ans[i] == n - 1:
			(a, b) = q[i - 1]
			if a <= i and i <= b:
				continue
			else:
				t.append(i)
	print(len(t))
	for e in t:
		print(e)


t = int(input())
while t:
	k = int(input())
	m = [0] * (k + 2)
	low = [0]
	high = [0]
	r = []
	for g in range(1, k + 1):
		(i, j) = map(int, input().split())
		low.append(i)
		high.append(j)
		m[i] += 1
		m[j + 1] -= 1
	for i in range(1, k + 1):
		m[i] += m[i - 1]
	for i in range(1, k + 1):
		if m[i] == k - 1:
			if not (low[i] <= i and high[i] >= i):
				r.append(i)
	print(len(r))
	for i in sorted(r):
		print(i, end='\n')
	t -= 1


def fun(l, r, out, x, y, i):
	if x > r or y < l:
		if i >= l and i <= r:
			out.append(i)
		return
	if l < x:
		if i >= l and i < x:
			out.append(i)
			return
	if y < r:
		if i > y and i <= r:
			out.append(i)
	return
for t in range(int(input())):
	n = int(input())
	a = [list((int(i) for i in input().split())) for i in range(n)]
	f = [[0, 0] for i in range(n)]
	prev = [1, n]
	for i in range(n):
		f[i][0] = max(prev[0], a[i][0])
		f[i][1] = min(prev[1], a[i][1])
		prev[0] = f[i][0]
		prev[1] = f[i][1]
	b = [[0, 0] for i in range(n)]
	b.append([-n - 1, n + 1])
	prev = [1, n]
	for i in range(n - 1, -1, -1):
		b[i][0] = max(prev[0], a[i][0])
		b[i][1] = min(prev[1], a[i][1])
		prev[0] = b[i][0]
		prev[1] = b[i][1]
	out = []
	for i in range(1, n):
		l = max(f[i - 1][0], b[i + 1][0])
		r = min(f[i - 1][1], b[i + 1][1])
		if l <= r:
			fun(l, r, out, a[i][0], a[i][1], i + 1)
	if b[1][0] <= b[1][1]:
		fun(b[1][0], b[1][1], out, a[0][0], a[1][0], 1)
	c = len(out)
	out.sort()
	print(c)
	for i in range(c):
		print(out[i])


def craet(n):
	arr = []
	for i in range(n):
		arr.append(list(map(int, input().split())))
	x = {}
	for i in arr:
		a = i[0]
		b = i[1]
		if a not in x:
			x[a] = [0, 0]
		if b not in x:
			x[b] = [0, 0]
		x[a][0] += 1
		x[b][1] += 1
	count = {}
	c = 0
	for i in range(1, n + 1):
		if i in x:
			c += x[i][0]
		count[i] = c
		if i in x:
			c -= x[i][1]
	ans = []
	for i in count:
		if count[i] == n - 1 and (i < arr[i - 1][0] or i > arr[i - 1][1]):
			ans.append(str(i))
	print(len(ans))
	print('\n'.join(ans))
for i in range(int(input())):
	craet(int(input()))


from bisect import bisect_left, bisect_right

def ins(ls, rs, tup):
	(x, y) = tup
	if y < x:
		return
	ptl = bisect_left(ls, x)
	ptr = bisect_right(rs, y)
	if ptl > ptr:
		return
	for i in range(ptl, ptr):
		ls.pop(ptl)
		rs.pop(ptl)
	if ptl > 0 and rs[ptl - 1] >= x - 1:
		ptl -= 1
		x = ls[ptl]
		ls.pop(ptl)
		rs.pop(ptl)
	if ptl < len(rs) and ls[ptl] <= y + 1:
		y = rs[ptl]
		ls.pop(ptl)
		rs.pop(ptl)
	ls.insert(ptl, x)
	rs.insert(ptl, y)
t = int(input())
for _ in range(t):
	n = int(input())
	ls = []
	rs = []
	for i in range(1, n + 1):
		(l, r) = map(int, input().split())
		ns = []
		if i < l:
			ns.append((1, i - 1))
			ns.append((i + 1, l - 1))
			ns.append((r + 1, n))
		elif i > r:
			ns.append((1, l - 1))
			ns.append((r + 1, i - 1))
			ns.append((i + 1, n))
		else:
			ns.append((1, l - 1))
			ns.append((i, i))
			ns.append((r + 1, n))
		for tup in ns:
			ins(ls, rs, tup)
	pos = 0
	ans = []
	for i in range(1, n + 1):
		if pos >= len(ls):
			ans.append(i)
		else:
			if i > rs[pos]:
				pos += 1
			if pos >= len(ls):
				ans.append(i)
			elif not ls[pos] <= i <= rs[pos]:
				ans.append(i)
	print(len(ans))
	for i in ans:
		print(i)


import math
from collections import Counter
t = int(input())
while t:
	t -= 1
	n = int(input())
	mar = [0] * (n + 2)
	sm = [0] * (n + 1)
	for i in range(n):
		a = list(map(int, input().split()))
		if a[0] <= i + 1 <= a[1]:
			sm[i + 1] = 1
		mar[a[0]] += 1
		mar[a[1] + 1] -= 1
	su = 0
	for i in range(n + 2):
		su += mar[i]
		mar[i] = su
	vi = []
	dd = n - 1
	for i in range(len(mar)):
		if mar[i] == dd and sm[i] == 0:
			vi.append(i)
	print(len(vi))
	for i in vi:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	L = [0] * (n + 1)
	M = []
	for i in range(n):
		(a, b) = map(int, input().split())
		M.append((a, b))
	for i in range(n):
		(a, b) = M[i]
		j = i + 1
		L[a - 1] += 1
		L[b] -= 1
	for i in range(1, n):
		L[i] += L[i - 1]
	for i in range(n):
		(a, b) = M[i]
		j = i + 1
		if j < a or j > b:
			L[i] += 1
		else:
			L[i] -= 1
	ans = []
	for i in range(n):
		if L[i] == n:
			ans.append(i + 1)
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i])


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

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())
for T in range(int(input())):
	n = ni()
	final = [0] * (n + 1)
	potential = []
	for i in range(n):
		(l, r) = mi()
		if not (l <= i + 1 and r >= i + 1):
			potential.append(i)
		final[l - 1] += 1
		final[r] -= 1
	for i in range(1, len(final)):
		final[i] += final[i - 1]
	final = final[:-1]
	count = []
	for i in potential:
		if final[i] == n - 1:
			count.append(i + 1)
	print(len(count))
	for i in count:
		print(i)


import sys
readline = sys.stdin.readline
import math
from sys import stdin
sys_max = sys.maxsize
from collections import Counter
from collections import deque
for _ in range(int(input())):
	n = int(input())
	l = []
	ans = []
	for i in range(n):
		(x, y) = [int(x) for x in input().split()]
		l.append([x, y])
	pre = [0 for _ in range(n + 2)]
	vis = [0 for _ in range(n + 1)]
	for i in range(n):
		u = l[i][0]
		v = l[i][1]
		pre[u] += 1
		pre[v + 1] -= 1
		if u > i + 1 or v < i + 1:
			vis[i + 1] = 1
	cnt = 0
	for i in range(1, n + 2):
		pre[i] += pre[i - 1]
	for i in range(1, n + 1):
		if pre[i] == n - 1 and vis[i] == 1:
			cnt += 1
			ans.append(i)
	print(len(ans))
	for i in ans:
		print(i)
	print()


def initializeDiffArray(A):
	n = len(A)
	D = [0 for i in range(0, n + 1)]
	D[0] = A[0]
	D[n] = 0
	for i in range(1, n):
		D[i] = A[i] - A[i - 1]
	return D

def update(D, l, r, x):
	D[l] += x
	D[r + 1] -= x

def printArray(A, D):
	arr = []
	for i in range(0, len(A)):
		if i == 0:
			A[i] = D[i]
		else:
			A[i] = D[i] + A[i - 1]
		arr.append(A[i])
	return arr
T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	k = []
	d = []
	A = [0] * (n + 1)
	D = initializeDiffArray(A)
	for i in range(1, n + 1):
		(l, r) = map(int, input().split())
		if l <= i <= r:
			pass
		else:
			d.append(i)
		update(D, l, r, 1)
	p = printArray(A, D)
	ans = []
	for i in d:
		if p[i] == n - 1:
			ans.append(i)
	print(len(ans))
	print(*ans, sep='\n')


strng = lambda : input().split()[0]
inp = lambda : int(input())
mul = lambda : map(int, input().split())
jn = lambda x, l: x.join(map(str, l))
slst = lambda : list(input().split()[0])
silst = lambda : list(map(int, input().split()[0]))
lst = lambda : list(map(int, input().split()))
dd = lambda : defaultdict(lambda : 0)
import sys
input = sys.stdin.readline
from collections import defaultdict
from math import ceil, log, floor, sqrt, gcd, log10

def merge(a, lo, hi, m):
	tmp = []
	i = lo
	j = m + 1
	while i <= m and j <= hi:
		if a[i] > a[j]:
			tmp += [a[j]]
			j += 1
		else:
			tmp += [a[i]]
			i += 1
	while i <= m:
		tmp += [a[i]]
		i += 1
	while j <= hi:
		tmp += [a[j]]
		j += 1
	j = 0
	for i in range(lo, hi + 1):
		a[i] = tmp[j]
		j += 1

def msrt(arr, lo, hi):
	if lo < hi:
		m = (lo + hi) // 2
		msrt(arr, lo, m)
		msrt(arr, m + 1, hi)
		merge(arr, lo, hi, m)

def part(a, lo, hi):
	i = lo - 1
	j = 0
	while j < hi:
		if a[j] <= a[hi]:
			i += 1
			(a[j], a[i]) = (a[i], a[j])
		j += 1
	(a[i + 1], a[hi]) = (a[hi], a[i + 1])
	return i + 1

def qsrt(arr, lo, hi):
	if lo < hi:
		m = part(arr, lo, hi)
		print(m)
		qsrt(arr, lo, m - 1)
		qsrt(arr, m + 1, hi)
for _ in range(inp()):
	n = inp()
	a = [0] * n
	d = defaultdict(lambda : 0)
	for i in range(n):
		(l, r) = mul()
		a[l - 1] += 1
		if i >= l - 1 and i <= r - 1:
			d[i] += 1
		if r < n:
			a[r] -= 1
	s = 0
	for i in range(n):
		s += a[i]
		a[i] = s
	maxi = n - 1
	ans = 0
	ansarr = []
	for i in range(n):
		if a[i] == maxi and i not in d:
			ans += 1
			ansarr += [i + 1]
	print(ans)
	print(*ansarr, sep='\n')


for _ in range(int(input())):
	n = int(input())
	freq = [0 for i in range(n + 1)]
	l = n
	h = 0
	d1 = {}
	for i in range(1, n + 1):
		(a, b) = map(int, input().split())
		if a < l:
			l = a
		if b > h:
			h = b
		freq[a] = freq[a] + 1
		if b < n:
			freq[b + 1] = freq[b + 1] - 1
		if i >= a and b >= i:
			d1[i] = 1
	for i in range(l, h + 1):
		freq[i] = freq[i] + freq[i - 1]
	ans = 0
	l1 = []
	for i in range(1, n + 1):
		if freq[i] == n - 1 and d1.get(i) == None:
			ans += 1
			l1.append(i)
	print(ans)
	for i in l1:
		print(i)
	print()


for _ in range(int(input())):
	n = int(input())
	a = [0] * (n + 2)
	s = set()
	for i in range(1, n + 2):
		a[i] = 0
	if 443434 == 343434:
		print('Tanmay')
	for i in range(1, n + 1):
		(l, r) = [int(x) for x in input().split()]
		a[l] += 1
		a[r + 1] -= 1
		if i >= l and i <= r:
			s.add(i)
	for i in range(1, n + 1):
		a[i] += a[i - 1]
	aa = []
	for i in range(1, n + 1):
		if a[i] == n - 1 and i not in s:
			aa.append(i)
	print(len(aa))
	for i in aa:
		print(i)


T = int(input())
for i in range(T):
	N = int(input())
	rlist = []
	vals = []
	for theta in range(N):
		(L, R) = map(int, input().split(' '))
		rlist.append((L, R, theta + 1))
	rlist.sort(key=lambda x: x[0])
	ub = N
	for delta in range(N - 1):
		ub = min(ub, rlist[delta][1])
	if rlist[-1][2] in range(rlist[-2][0], min(ub + 1, rlist[-1][0])):
		vals.append(rlist[-1][2])
	rlist.sort(key=lambda x: x[1])
	lb = 0
	for epsilon in range(1, N):
		lb = max(lb, rlist[epsilon][0])
	if rlist[0][2] in range(max(rlist[0][1] + 1, lb), rlist[1][1] + 1):
		vals.append(rlist[0][2])
	print(len(vals))
	vals.sort()
	for alpha in range(len(vals)):
		print(vals[alpha])


for _ in range(int(input())):
	n = int(input())
	l = [0] * (n + 2)
	start = [0] * (n + 2)
	end = [0] * (n + 2)
	for i in range(1, n + 1):
		(s, e) = map(int, input().strip().split(' '))
		start[i] = s
		end[i] = e
		l[s] += 1
		l[e + 1] -= 1
	for i in range(1, n + 1):
		l[i] += l[i - 1]
	res = []
	for i in range(1, n + 1):
		if l[i] == n - 1:
			if not (start[i] <= i and end[i] >= i):
				res.append(i)
	print(len(res))
	for i in res:
		print(i)


t = int(input())
for x in range(t):
	n = int(input())
	queries = []
	a = [0 for _ in range(n + 2)]
	for i in range(n):
		(l, r) = map(int, input().split())
		queries.append((l, r))
		a[l] += 1
		a[r + 1] -= 1
	for i in range(1, n + 1):
		a[i] += a[i - 1]
	st = set()
	for i in range(1, n + 1):
		if a[i] == n - 1:
			(l, r) = queries[i - 1]
			if l <= i <= r:
				continue
			st.add(i)
	ans = sorted(st)
	print(len(ans))
	for i in ans:
		print(i)


from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid

def Sieve(limit=10 ** 6):
	isPrime = [1] * (limit + 1)
	isPrime[0] = isPrime[1] = 0
	for i in range(2, limit + 1):
		if isPrime[i] != 1:
			continue
		for j in range(i * i, limit + 1, i):
			isPrime[j] = i
	return isPrime

def get_prime_factors(n, isPrime):
	if n < 2:
		return []
	result = []
	while isPrime[n] != 1:
		result += [isPrime[n]]
		n //= isPrime[n]
	result += [n]
	return result

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

def main():
	for _ in range(int(input())):
		n = int(input())
		lst = [None]
		for i in range(n):
			a = tuple(map(int, input().split()))
			lst.append(a)
		fin = []
		for i in range(1, n + 1):
			v1 = lst[i][0]
			v2 = lst[i][1]
			if i < v1 or i > v2:
				chk = True
				for k in range(1, n + 1):
					if i != k:
						v3 = lst[k][0]
						v4 = lst[k][1]
						if i < v3 or i > v4:
							chk = False
							break
				if chk:
					fin.append(i)
		print(len(fin))
		for i in fin:
			print(i)
main()


for _ in range(int(input())):
	n = int(input())
	diff = [0 for i in range(n + 1)]
	ranges = []
	for i in range(n):
		(u, v) = [int(x) - 1 for x in input().split()]
		ranges.append([u, v])
		diff[u] += 1
		diff[v + 1] -= 1
	thieves = []
	for i in range(1, n + 1):
		diff[i] += diff[i - 1]
	for i in range(n):
		if diff[i] == 0 or (i >= ranges[i][0] and i <= ranges[i][1]):
			continue
		if diff[i] == n - 1:
			thieves.append(i + 1)
	print(len(thieves))
	for x in thieves:
		print(x)


import sys

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

def main():
	for _ in range(int(_input())):
		n = int(_input())
		l = [None]
		for i in range(n):
			x = tuple(map(int, _input().split()))
			l.append(x)
		ans = []
		for i in range(1, n + 1):
			x1 = l[i][0]
			y1 = l[i][1]
			if i >= x1 and i <= y1:
				pass
			else:
				check = True
				for j in range(1, n + 1):
					if i != j:
						x2 = l[j][0]
						y2 = l[j][1]
						if i >= x2 and i <= y2:
							pass
						else:
							check = False
							break
				if check:
					ans.append(i)
		print(len(ans))
		for i in ans:
			print(i)
main()


def solve(n, qr):
	arr = [0 for i in range(n + 1)]
	for val in qr:
		arr[val[0] - 1] += 1
		arr[val[1]] -= 1
	for i in range(1, n + 1):
		arr[i] += arr[i - 1]
	return arr

def ans(arr, qr, n):
	te = []
	for i in range(n):
		if qr[i][0] - 1 <= i <= qr[i][1] - 1:
			arr[i] -= 1
			if arr[i] == n:
				te.append(i + 1)
			arr[i] += 1
		else:
			arr[i] += 1
			if arr[i] == n:
				te.append(i + 1)
			arr[i] -= 1
	return te
for i in range(int(input())):
	n = int(input())
	quer = []
	for i in range(n):
		(v1, v2) = map(int, input().split())
		quer.append((v1, v2))
	arr = solve(n, quer)
	sol = ans(arr, quer, n)
	print(len(sol))
	for val in sol:
		print(val)


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache
from itertools import *

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

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

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

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for _ in range(how_much_noob_I_am):
		n = inpu()
		arr = [lis() for i in range(n)]
		p = [0] * (n + 1)
		s = set()
		for k in range(len(arr)):
			(i, j) = arr[k]
			if i <= k + 1 <= j:
				s.add(k + 1)
			i -= 1
			j -= 1
			p[i] += 1
			p[j + 1] -= 1
		p = list(accumulate(p))
		ans = []
		for i in range(n):
			if p[i] == n - 1:
				if i + 1 in s:
					continue
				ans.append(i)
		print(len(ans))
		for i in ans:
			print(i + 1)
main()


for h in range(int(input())):
	n = int(input())
	x = [0] * (n + 1)
	vec = []
	temp = []
	for j in range(n):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		x[a] += 1
		x[b + 1] -= 1
		vec.append([a, b])
	x[-1] = 0
	for i in range(n):
		x[i] += x[i - 1]
		if (i > vec[i][1] or i < vec[i][0]) and x[i] == n - 1:
			temp.append(i + 1)
	print(len(temp))
	for i in temp:
		print(i)


for _ in range(int(input())):
	n = int(input())
	thief = [0] * (n + 1)
	lst = []
	for x in range(n):
		(x, y) = map(int, input().split())
		lst.append([x, y])
		thief[x - 1] += 1
		thief[y] -= 1
	for x in range(1, n + 1):
		thief[x] += thief[x - 1]
	rslt = []
	cnt = 0
	for x in range(1, 1 + n):
		y = lst[x - 1][0]
		z = lst[x - 1][1]
		if thief[x - 1] == n - 1 and (x < y or x > z):
			rslt.append(x)
			cnt += 1
	print(cnt)
	print(*rslt, sep='\n')


def update(D, l, r, x):
	D[l] += x
	D[r + 1] -= x
t = int(input())
for tt in range(t):
	n = int(input())
	a = [list(map(int, input().split())) for i in range(n)]
	a1 = [0] * (n + 1)
	for r in a:
		update(a1, r[0] - 1, r[1] - 1, 1)
	ans = 0
	aa = []
	for j in range(1, n):
		a1[j] = a1[j] + a1[j - 1]
	for k in range(n):
		if a1[k] == n - 1 and (a[k][0] > k + 1 or a[k][1] < k + 1):
			ans += 1
			aa += [k + 1]
	print(ans)
	for y in aa:
		print(y)


for _ in range(int(input())):
	n = int(input())
	l = [0 for i in range(n + 1)]
	q = []
	for i in range(n):
		(a, b) = map(int, input().split())
		q.append((a, b))
		l[a - 1] += 1
		l[b] -= 1
	ans = []
	for i in range(n):
		if i > 0:
			l[i] += l[i - 1]
		if q[i][0] - 1 <= i <= q[i][1] - 1:
			l[i] -= 1
			if l[i] == n:
				ans.append(i + 1)
			l[i] += 1
		else:
			l[i] += 1
			if l[i] == n:
				ans.append(i + 1)
			l[i] -= 1
	print(len(ans))
	for val in ans:
		print(val)


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	newa = set()
	j = 1
	for i in a:
		if i[0] <= j and i[1] >= j:
			newa.add(j)
		j += 1
	now = [0 for i in range(n)]
	for i in a:
		now[i[0] - 1] += 1
		if i[1] < n:
			now[i[1]] -= 1
	for i in range(1, n):
		now[i] = now[i] + now[i - 1]
	ans = []
	for i in newa:
		now[i - 1] = 0
	c = max(now)
	for i in range(n):
		if now[i] == c:
			ans.append(i + 1)
	ans.sort()
	print(len(ans))
	for i in ans:
		print(i)


from itertools import groupby
T = int(input())
for _ in range(T):
	N = int(input())
	events = []
	a = []
	for i in range(N):
		(L, R) = list(map(int, input().split()))
		a.append((L, R))
		events.append((L, 1))
		events.append((R + 1, -1))
	for i in range(1, N + 1):
		events.append((i, 0))
	events.sort()
	cnt = 0
	answer = []
	for (i, group) in groupby(events, key=lambda x: x[0]):
		for x in group:
			cnt += x[1]
		if i != N + 1:
			answer.append(cnt)
	K = 0
	possible = []
	for i in range(N):
		if answer[i] == N - 1 and (i + 1 < a[i][0] or i + 1 > a[i][1]):
			possible.append(i + 1)
			K += 1
	print(K)
	for p in possible:
		print(p)


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	c = []
	for j in range(n + 1):
		a.append(0)
	for i in range(n):
		(j, k) = map(int, input().split())
		j -= 1
		k -= 1
		a[j] += 1
		a[k + 1] -= 1
		if i < j or i > k:
			b.append(1)
		else:
			b.append(0)
	for i in range(n):
		a[i + 1] = a[i] + a[i + 1]
		if a[i] == n - 1 and b[i] == 1:
			c.append(i + 1)
	print(len(c))
	for i in c:
		print(i)


for h in range(int(input())):
	n = int(input())
	x = [0] * (n + 1)
	z = []
	v = []
	for i in range(n):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		z.append([a, b])
		x[a] += 1
		x[b + 1] -= 1
	x[-1] = 0
	for i in range(n):
		x[i] += x[i - 1]
		if x[i] == n - 1 and (i < z[i][0] or i > z[i][1]):
			v.append(i + 1)
	print(len(v))
	for i in v:
		print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = []
	ans = []
	for i in range(n):
		(j, k) = map(int, input().split())
		l1.append([j, k])
	for i in range(0, n):
		(l, r) = (l1[i][0], l1[i][1])
		if i + 1 >= l and i + 1 <= r:
			continue
		temp = l1.copy()
		temp.pop(i)
		for y in temp:
			(l, r) = (y[0], y[1])
			if i + 1 < l or i + 1 > r:
				break
		else:
			ans.append(i + 1)
	print(len(ans))
	for i in ans:
		print(i)


def main():
	n = int(input())
	prefix = [0] * (n + 10)
	notThief = set()
	for i in range(1, n + 1):
		(l, r) = map(int, input().split())
		if i >= l and i <= r:
			notThief.add(i)
		prefix[l] += 1
		prefix[r + 1] -= 1
	arr = []
	curr = 0
	for i in range(1, n + 1):
		curr += prefix[i]
		arr.append(curr)
	ans = []
	for i in range(n):
		if i + 1 in notThief:
			continue
		if arr[i] == n - 1:
			ans.append(i + 1)
	print(len(ans))
	for z in ans:
		print(z)
	return
for _ in range(int(input())):
	main()


import sys
input = lambda : sys.stdin.readline()
T = int(input())
for _ in range(T):
	n = int(input().strip())
	L = [0 for i in range(n + 2)]
	dic = {}
	for i in range(n):
		(l, r) = map(int, input().strip().split())
		dic[i] = [l, r]
		L[l] += 1
		L[r + 1] -= 1
	count = 0
	ans = 0
	M = []
	for i in range(1, n + 1):
		count += L[i]
		if count == n - 1 and (dic[i - 1][1] < i or dic[i - 1][0] > i):
			ans += 1
			M.append(i)
	print(ans)
	for i in M:
		print(i)


import sys
from math import sqrt, gcd, factorial, ceil, floor, pi
from collections import deque, Counter, OrderedDict
from heapq import heapify, heappush, heappop
input = lambda : sys.stdin.readline()
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()
	(al, ar) = (1, n)
	arr = [0] * (n + 2)
	d = {}
	for i in range(n):
		(l, r) = M()
		d[i] = [l, r]
		arr[l] += 1
		arr[r + 1] -= 1
	c = 0
	(ans, farr) = (0, [])
	for i in range(1, n + 1):
		c += arr[i]
		if c == n - 1 and (d[i - 1][1] < i or d[i - 1][0] > i):
			ans += 1
			farr.append(i)
	print(ans)
	for i in farr:
		print(i)