This is the hard version of the problem. The difference between the versions is that the hard version does require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.

Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.

The main element of this machine are n rods arranged along one straight line and numbered from 1 to n inclusive. Each of these rods must carry an electric charge quantitatively equal to either 1 or -1 (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.

More formally, the rods can be represented as an array of n numbers characterizing the charge: either 1 or -1. Then the condition must hold: a_1 - a_2 + a_3 - a_4 + … = 0, or ∑_{i=1}^n (-1)^{i-1} ⋅ a_i = 0.

Sparky charged all n rods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has q questions. In the ith question Sparky asks: if the machine consisted only of rods with numbers l_i to r_i inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Also Sparky wants to know the numbers of these rods. Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don't have to remove the rods at all.

If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.

Help your friends and answer all of Sparky's questions!

Input

Each test contains multiple test cases.

The first line contains one positive integer t (1 ≤ t ≤ 10^3), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains two positive integers n and q (1 ≤ n, q ≤ 3 ⋅ 10^5) — the number of rods and the number of questions.

The second line of each test case contains a non-empty string s of length n, where the charge of the i-th rod is 1 if s_i is the "+" symbol, or -1 if s_i is the "-" symbol.

Each next line from the next q lines contains two positive integers l_i ans r_i (1 ≤ l_i ≤ r_i ≤ n) — numbers, describing Sparky's questions.

It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5, and the sum of q over all test cases does not exceed 3 ⋅ 10^5.

It is guaranteed that the sum of the answers (minimal number of rods that can be removed) over all test cases does not exceed 10^6.

Output

For each test case, print the answer in the following format:

In the first line print a single integer k — the minimal number of rods that can be removed.

In the second line print k numbers separated by a space — the numbers of rods to be removed.

If there is more than one correct answer, you can print any.

Example

Input


3
14 1
+--++---++-++-
1 14
14 3
+--++---+++---
1 14
6 12
3 10
4 10
+-+-
1 1
1 2
1 3
1 4
2 2
2 3
2 4
3 3
3 4
4 4


Output


2
5 8
2
1 11
1
9
0
1
1
2
1 2
1
2
2
1 3
1
2
2
2 3
1
3
1
3
2
3 4
1
4

Note

In the first test case for the first query you can remove the rods numbered 5 and 8, then the following set of rods will remain: +--+--++-++-. It is easy to see that here the sign-variable sum is zero.

In the second test case:

  * For the first query, we can remove the rods numbered 1 and 11, then the following set of rods will remain: --++---++---. It is easy to see that here the sign-variable sum is zero. 
  * For the second query we can remove the rod numbered 9, then the following set of rods will remain: ---++-. It is easy to see that here the variable sum is zero. 
  * For the third query we can not remove the rods at all.

Difficulty: HARD
Tags: Data structures

Mathematics
Skill types: Data structures

Starter code:

Solutions:
import sys, io, os
try:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	input = lambda : sys.stdin.readline().encode()
read = lambda : map(int, input().split())
from collections import defaultdict as dd
O = []
for _ in range(int(input())):
	(n, q) = read()
	s = input().strip()
	p = [[0], [0]]
	for i in range(n):
		p[i & 1].append(p[i & 1][-1] + 44 - s[i])
	for i in range(q):
		(l, r) = read()
		L = [l // 2, (l - 1) // 2]
		R = [(r + 1) // 2, r // 2]
		if l - r & 1:
			if p[0][R[0]] - p[0][L[0]] == p[1][R[1]] - p[1][L[1]]:
				O.append('0')
				continue
			else:
				O.append('2')
				l += 1
				L = [l // 2, (l - 1) // 2]
				f = 1
		else:
			O.append('1')
			f = 0
		B = [l, r]
		left = p[1][R[1]] - p[1][l // 2] - (p[0][R[0]] - p[0][(l + 1) // 2])
		if left == 0:
			if f:
				O.append(f'{l - 1} {l}')
			else:
				O.append(f'{l}')
			continue
		right = p[0][r // 2] - p[0][L[0]] - (p[1][(r - 1) // 2] - p[1][L[1]])
		if right == 0:
			if f:
				O.append(f'{l - 1} {r}')
			else:
				O.append(f'{r}')
			continue
		while B[1] - B[0] > 1:
			m = sum(B) // 2
			mid0 = p[0][m // 2] - p[0][L[0]] - (p[0][R[0]] - p[0][(m + 1) // 2])
			mid1 = p[1][(m - 1) // 2] - p[1][L[1]] - (p[1][R[1]] - p[1][m // 2])
			mid = mid0 - mid1
			if mid == 0:
				if f:
					O.append(f'{l - 1} {m}')
				else:
					O.append(f'{m}')
				break
			elif mid > 0:
				if left > 0:
					B[0] = m
					left = mid
				else:
					B[1] = m
					right = mid
			elif left > 0:
				B[1] = m
				right = mid
			else:
				B[0] = m
				left = mid
print('\n'.join(O))


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, q) = map(int, input().split())
	s = input()
	arr = [0]
	for i in range(n):
		if i & 1:
			if s[i] == '+':
				arr.append(arr[-1] - 1)
			else:
				arr.append(arr[-1] + 1)
		elif s[i] == '-':
			arr.append(arr[-1] - 1)
		else:
			arr.append(arr[-1] + 1)
	queries = [[] for i in range(n + 1)]
	for i in range(q):
		(l, r) = map(int, input().split())
		queries[l].append((r, i))
	ans = [0] * q
	d = defaultdict(list)
	for i in range(1, n + 1):
		d[arr[i] + arr[i - 1]].append(i)
	d1 = defaultdict(int)
	for i in range(1, n + 1):
		for (r, j) in queries[i]:
			if arr[r] - arr[i - 1] == 0:
				ans[j] = (0, None)
			elif (r - i + 1) % 2:
				su = arr[r] + arr[i - 1]
				while d[su][d1[su]] < i:
					d1[su] += 1
				ans[j] = (1, d[su][d1[su]])
			else:
				r -= 1
				su = arr[r] + arr[i - 1]
				while d[su][d1[su]] < i:
					d1[su] += 1
				ans[j] = (2, d[su][d1[su]], r + 1)
	for i in ans:
		if i[0] == 0:
			print(0)
		elif i[0] == 1:
			print(i[0])
			print(i[1])
		else:
			print(2)
			print(i[1], i[2])


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
from bisect import bisect_left, bisect_right
from itertools import accumulate
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	arr = list(input())
	for i in range(n):
		arr[i] = chr(arr[i])
	for i in range(n):
		if i % 2 == 0:
			if arr[i] == '+':
				arr[i] = 1
			else:
				arr[i] = -1
		elif arr[i] == '-':
			arr[i] = 1
		else:
			arr[i] = -1
	dct = defaultdict(list)
	brr = [0] + list(accumulate(arr))
	for i in range(n):
		dct[brr[i] + brr[i + 1]].append(i + 1)
	for i in range(q):
		(l, r) = map(int, input().split())
		c = brr[r] - brr[l - 1]
		if c == 0:
			print(0)
			continue
		if (r - l + 1) % 2 == 0:
			d = brr[r] + brr[l]
			bb = dct[d][bisect_left(dct[d], l + 0.5)]
			print(2)
			print(l, bb)
		else:
			d = brr[r] + brr[l - 1]
			bb = dct[d][bisect_left(dct[d], l - 0.5)]
			print(1)
			print(bb)


import io as _io
import itertools as _itertools
import sys as _sys

def which_rods_should_remove_to_make_machine_charged_correctly(rods, queries):
	rods = list(rods)
	rods = [+x if i % 2 == 0 else -x for (i, x) in enumerate(rods)]
	prefix_sums = tuple(_itertools.accumulate(rods))
	for query in queries:
		yield tuple(_process_query(query, prefix_sums))

def _process_query(query, prefix_sums):

	def get_prefix_sum(i):
		return prefix_sums[i] if i >= 0 else 0
	(l, r) = query
	sum_before_prefix = get_prefix_sum(l - 1)
	initial_sum = get_prefix_sum(r) - sum_before_prefix
	if initial_sum == 0:
		return
	if (initial_sum - 1) % 2 != 0:
		yield from _process_query((l, r - 1), prefix_sums)
		yield r
		return

	def get_sum_by_deletion(i):
		sum_before_deletion = get_prefix_sum(i - 1) - sum_before_prefix
		sum_after_deletion = get_prefix_sum(r) - get_prefix_sum(i)
		return sum_before_deletion - sum_after_deletion
	first_sum = get_sum_by_deletion(r)
	if first_sum == 0:
		yield r
		return
	min_i_to_del = l
	max_i_to_del = r
	while min_i_to_del != max_i_to_del:
		i = (min_i_to_del + max_i_to_del) // 2
		current_sum = get_sum_by_deletion(i)
		if current_sum * first_sum < 0:
			min_i_to_del = i + 1
		else:
			max_i_to_del = i
	i_to_del = min_i_to_del
	yield i_to_del

def _main():
	output = []
	[tests_n] = _read_ints()
	for i_test in range(tests_n):
		[rods_n, queries_n] = _read_ints()
		rods = _read_string()
		assert len(rods) == rods_n and set(rods).issubset({'+', '-'})
		rods = [+1 if ch == '+' else -1 for ch in rods]
		queries = [_read_query() for i_query in range(queries_n)]
		results = which_rods_should_remove_to_make_machine_charged_correctly(rods, queries)
		for result in results:
			output.append(str(len(result)))
			output.append(' '.join([str(i + 1) for i in result]))
	_sys.stdout.write('\n'.join(output))
	_sys.stdout.write('\n')

def _read_query(file=_sys.stdin):
	[l, r] = _read_ints(file)
	l -= 1
	r -= 1
	return (l, r)

def _read_ints(file=_sys.stdin):
	return map(int, _read_string(file).split())

def _read_string(file=_sys.stdin):
	[result] = file.readline().splitlines()
	return result

def _write_ints(*ints, sep=' ', end='\n', file=_sys.stdout):
	file.write(sep.join(map(str, ints)))
	file.write(end)
_main()


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')
from collections import defaultdict
from bisect import bisect_left

def check(A, l, r, R):
	assert l <= r
	sign = 1
	s = 0
	for i in range(l, r + 1):
		if i not in R:
			s += sign * value(A[i])
			sign *= -1
	if s != 0:
		print(A[l:r + 1], l, r, R, St)
	assert s == 0

def value(e):
	return 1 if e == '+' else -1
T = int(input())
for _ in range(T):
	(n, q) = map(int, input().split(' '))
	A = input()
	sign = 1
	prefix = [sign * value(A[0])]
	for a in A[1:]:
		sign *= -1
		prefix.append(prefix[-1] + sign * value(a))
	S = defaultdict(list)
	for i in range(n - 1):
		S[prefix[i] + prefix[i + 1]].append(i)
	for _ in range(q):
		(l, r) = map(int, input().split(' '))
		l -= 1
		r -= 1
		s = prefix[r] - (prefix[l - 1] if l > 0 else 0)
		(k, R) = (0, [])
		(l1, r1) = (l, r)
		if s == 0:
			pass
		else:
			if (r - l + 1) % 2 == 0:
				R.append(r)
				r -= 1
				k += 1
			s = prefix[r] - (prefix[l - 1] if l > 0 else 0)
			if s != 0:
				if prefix[l] - (prefix[l - 1] if l > 0 else 0) == s:
					k += 1
					R.append(l)
				elif prefix[r] - (prefix[r - 1] if r > 0 else 0) == s:
					k += 1
					R.append(r)
				else:
					St = S[prefix[r] + (prefix[l - 1] if l > 0 else 0)]
					i = bisect_left(St, r - 1)
					k += 1
					v = 1 + (St[i - 1] if i == len(St) else St[i - 1])
					assert l <= v <= r
					R.append(v)
		print(k)
		if k != 0:
			print(' '.join((str(r + 1) for r in R)))


import itertools as _itertools
import sys as _sys

def which_rods_should_remove_to_make_machine_charged_correctly(rods, queries):
	rods = list(rods)
	rods = [+x if i % 2 == 0 else -x for (i, x) in enumerate(rods)]
	prefix_sums = tuple(_itertools.accumulate(rods))
	for query in queries:
		yield tuple(_process_query(query, prefix_sums))

def _process_query(query, prefix_sums):

	def get_prefix_sum(i):
		return prefix_sums[i] if i >= 0 else 0
	(l, r) = query
	sum_before_prefix = get_prefix_sum(l - 1)
	initial_sum = get_prefix_sum(r) - sum_before_prefix
	if initial_sum == 0:
		return
	if (initial_sum - 1) % 2 != 0:
		yield from _process_query((l, r - 1), prefix_sums)
		yield r
		return

	def get_sum_by_deletion(i):
		sum_before_deletion = get_prefix_sum(i - 1) - sum_before_prefix
		sum_after_deletion = get_prefix_sum(r) - get_prefix_sum(i)
		return sum_before_deletion - sum_after_deletion
	first_sum = get_sum_by_deletion(r)
	if first_sum == 0:
		yield r
		return
	min_i_to_del = l
	max_i_to_del = r
	while min_i_to_del != max_i_to_del:
		i = (min_i_to_del + max_i_to_del) // 2
		current_sum = get_sum_by_deletion(i)
		if current_sum * first_sum < 0:
			min_i_to_del = i + 1
		else:
			max_i_to_del = i
	i_to_del = min_i_to_del
	yield i_to_del

def _main():
	input_lines = iter(_sys.stdin.read().splitlines())
	output = []
	[tests_n] = _read_ints(next(input_lines))
	for i_test in range(tests_n):
		[rods_n, queries_n] = _read_ints(next(input_lines))
		rods = next(input_lines)
		assert len(rods) == rods_n and set(rods).issubset({'+', '-'})
		rods = [+1 if ch == '+' else -1 for ch in rods]
		queries = [_read_query(next(input_lines)) for i_query in range(queries_n)]
		results = which_rods_should_remove_to_make_machine_charged_correctly(rods, queries)
		for result in results:
			output.append(str(len(result)))
			output.append(' '.join([str(i + 1) for i in result]))
	_sys.stdout.write('\n'.join(output))
	_sys.stdout.write('\n')

def _read_query(string):
	[l, r] = _read_ints(string)
	l -= 1
	r -= 1
	return (l, r)

def _read_ints(string):
	return map(int, string.split())
_main()


from sys import stdin, stdout
raw_input = input
xrange = range
raw_input = lambda : stdin.readline().rstrip()
input = lambda : int(raw_input())
I = lambda : map(int, raw_input().split())

def f(l, r):
	global pprefix, prefix, p
	xl = sign(g(l))
	if xl == 0:
		return l
	xr = sign(g(r))
	if xr == 0:
		return r
	l1 = l
	r1 = r
	while True:
		m = (r1 + l1) // 2
		x = sign(g(m))
		if x == 0:
			return m
		if x != xl:
			r1 = m
		elif x != xr:
			l1 = m

def sign(n):
	if n > 0:
		return 1
	elif n < 0:
		return -1
	else:
		return 0

def g(i):
	global pprefix, p
	return p + pprefix[i]
t = input()
for _ in xrange(t):
	(n, q) = I()
	s = raw_input()
	prefix = [0]
	pprefix = [0]
	c = 0
	prevC = 0
	for i in xrange(n):
		if i % 2:
			if s[i] == '-':
				c += 1
			else:
				c -= 1
		elif s[i] == '+':
			c += 1
		else:
			c -= 1
		prefix.append(c)
		pprefix.append(c + prevC)
		prevC = c
	for _ in xrange(q):
		(a, b) = I()
		w = prefix[b] - prefix[a - 1]
		if w == 0:
			stdout.write('0\n')
		elif (b - a) % 2 == 0:
			stdout.write('1\n')
			l = a
			r = b
			p = -(prefix[l - 1] + prefix[r])
			y = f(l, r)
			stdout.write(str(y) + '\n')
		else:
			stdout.write('2\n')
			l = a
			r = b - 1
			p = -(prefix[l - 1] + prefix[r])
			y = f(l, r)
			stdout.write(str(y) + ' ' + str(b) + '\n')


from collections import defaultdict
import bisect
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	s = input()
	sumList = [0]
	sumDictionary = defaultdict(lambda : [])
	for i in range(n):
		sumList.append(sumList[-1] + (1 if s[i] == '+' else -1) * (1 if i % 2 == 0 else -1))
	for i in range(n):
		sumDictionary[sumList[i] + sumList[i + 1]].append(i + 1)
	for _ in range(q):
		(l, r) = map(int, input().split())
		if (l - r) % 2 == 0:
			print(1)
			calc = sumDictionary[sumList[r] + sumList[l - 1]]
			print(calc[bisect.bisect_left(calc, l - 0.5)])
		elif sumList[r] == sumList[l - 1]:
			print(0)
		else:
			print(2)
			calc = sumDictionary[sumList[r] + sumList[l]]
			print(l, calc[bisect.bisect_left(calc, l + 0.5)])


import sys
input = sys.stdin.readline
from _collections import defaultdict
T = int(input())

def bilower(a, x):
	if len(a) == 0:
		return -1
	mi = 0
	ma = len(a) - 1
	if a[0] > x:
		return -1
	if a[ma] <= x:
		return ma
	while ma - mi > 1:
		mid = (ma + mi) // 2
		if a[mid] <= x:
			mi = mid
		else:
			ma = mid
	return mi

def bihigher(a, x):
	if len(a) == 0:
		return 0
	mi = 0
	ma = len(a) - 1
	if a[ma] < x:
		return ma + 1
	if a[0] >= x:
		return 0
	while ma - mi > 1:
		mid = (ma + mi) // 2
		if a[mid] >= x:
			ma = mid
		else:
			mi = mid
	return ma

def birange(a, l, r):
	left = bihigher(a, l)
	right = bilower(a, r)
	return right - left + 1
for iii in range(T):
	(n, q) = map(int, input().split())
	dic1 = defaultdict(lambda : [])
	dic2 = defaultdict(lambda : [])
	a = [0] + list(input()[:-1])
	for i in range(1, n + 1):
		if a[i] == '+':
			a[i] = 1
		else:
			a[i] = -1
	s = [0] * (n + 1)
	for i in range(1, n + 1):
		if i % 2 == 1:
			pass
		else:
			a[i] *= -1
		s[i] = s[i - 1] + a[i]
		if a[i] > 0:
			dic1[s[i - 1]].append(i)
		else:
			dic2[s[i - 1]].append(i)
	for _ in range(q):
		(l, r) = map(int, input().split())
		res = s[r] - s[l - 1]
		if res == 0:
			print(0)
		elif res % 2 == 1:
			print(1)
			if res > 0:
				print(dic1[res // 2 + s[l - 1]][bihigher(dic1[res // 2 + s[l - 1]], l)])
			else:
				h = (res + 1) // 2
				print(dic2[h + s[l - 1]][bihigher(dic2[h + s[l - 1]], l)])
		else:
			print(2)
			res -= a[r]
			if res > 0:
				print(dic1[res // 2 + s[l - 1]][bihigher(dic1[res // 2 + s[l - 1]], l)], r)
			else:
				h = (res + 1) // 2
				print(dic2[h + s[l - 1]][bihigher(dic2[h + s[l - 1]], l)], r)


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

def bs(beg, end, l, r, val):
	while beg <= end:
		mid = (beg + end) // 2
		v = pre[mid - 1] - pre[l - 1] - (pre[r] - pre[mid])
		if v == 0:
			return mid
		elif v < 0 and val < 0 or (v > 0 and val > 0):
			end = mid - 1
		else:
			beg = mid + 1
	return beg
T = int(input())
for _ in range(T):
	(n, q) = map(int, input().split())
	s = list(input())
	pre = [0 for i in range(n + 1)]
	for i in range(n):
		if s[i] == '+':
			if i % 2 == 0:
				pre[i + 1] = pre[i] + 1
			else:
				pre[i + 1] = pre[i] - 1
		elif i % 2 == 0:
			pre[i + 1] = pre[i] - 1
		else:
			pre[i + 1] = pre[i] + 1
	for i in range(q):
		(l, r) = map(int, input().split())
		v = pre[r] - pre[l - 1]
		if v == 0:
			print(0)
		elif v % 2 == 0:
			print(2)
			if pre[r] - pre[l] % 2 != 0:
				x = bs(l + 1, r, l + 1, r, pre[r] - pre[l])
				print(l, x)
			else:
				x = bs(l + 1, r, l + 1, r, pre[r - 1] - pre[l - 1])
				print(x, r)
		else:
			print(1)
			x = bs(l, r, l, r, v)
			print(x)


import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

def calc(l, r, x):
	return abs(S[x - 1] - S[l - 1] - (S[r] - S[x]))
t = int(input())
for tests in range(t):
	(n, q) = map(int, input().split())
	S = input().strip()
	A = []
	for i in range(n):
		if S[i] == '+':
			x = 1
		else:
			x = -1
		if i % 2 == 0:
			A.append(x)
		else:
			A.append(-x)
	S = [0]
	X1 = defaultdict(list)
	X2 = defaultdict(list)
	for i in range(n):
		a = A[i]
		if a == 1:
			X1[S[-1] + a].append(i + 1)
		else:
			X2[S[-1] + a].append(i + 1)
		S.append(S[-1] + a)
	ANS = []
	for queries in range(q):
		(l, r) = map(int, input().split())
		k = S[r] - S[l - 1]
		if k == 0:
			ANS.append((0,))
		elif k % 2 == 0:
			ANS.append((2,))
			k = S[r - 1] - S[l - 1]
			flag = 0
			xx = bisect.bisect_left(X1[(k + 1) // 2 + S[l - 1]], l)
			for yy in range(xx, len(X1[(k + 1) // 2 + S[l - 1]])):
				uu = X1[(k + 1) // 2 + S[l - 1]][yy]
				if l <= uu <= r - 1:
					if calc(l, r - 1, uu) == 0:
						ANS.append((uu, r))
						flag = 1
						break
				else:
					break
			if flag == 1:
				continue
			xx = bisect.bisect_left(X2[(k - 1) // 2 + S[l - 1]], l)
			for yy in range(xx, len(X2[(k - 1) // 2 + S[l - 1]])):
				uu = X2[(k - 1) // 2 + S[l - 1]][yy]
				if l <= uu <= r - 1:
					if calc(l, r - 1, uu) == 0:
						ANS.append((uu, r))
						flag = 1
						break
				else:
					break
		else:
			ANS.append((1,))
			flag = 0
			xx = bisect.bisect_left(X1[(k + 1) // 2 + S[l - 1]], l)
			for yy in range(xx, len(X1[(k + 1) // 2 + S[l - 1]])):
				uu = X1[(k + 1) // 2 + S[l - 1]][yy]
				if l <= uu <= r:
					if calc(l, r, uu) == 0:
						ANS.append((uu,))
						flag = 1
						break
				else:
					break
			if flag == 1:
				continue
			xx = bisect.bisect_left(X2[(k - 1) // 2 + S[l - 1]], l)
			for yy in range(xx, len(X2[(k - 1) // 2 + S[l - 1]])):
				uu = X2[(k - 1) // 2 + S[l - 1]][yy]
				if l <= uu <= r:
					if calc(l, r, uu) == 0:
						ANS.append((uu,))
						flag = 1
						break
				else:
					break
	for ans in ANS:
		print(*ans)


from sys import stdin, stdout
import heapq
from collections import defaultdict
import math
import bisect
import io, os

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, q) = list(map(int, stdin.readline().split()))
		S = stdin.readline().strip()
		dp = [0]
		cur = 0
		dp_p = defaultdict(list)
		dp_m = defaultdict(list)
		for (i, s) in enumerate(S):
			if i % 2 == 0:
				if s == '+':
					cur += 1
				else:
					cur -= 1
			elif s == '+':
				cur -= 1
			else:
				cur += 1
			dp.append(cur)
			if i + 1 < n:
				if S[i + 1] == '+' and (i + 1) % 2 == 0 or (S[i + 1] == '-' and (i + 1) % 2 == 1):
					dp_p[cur].append(i + 1)
				else:
					dp_m[cur].append(i + 1)
		for qq in range(q):
			(l, r) = list(map(int, stdin.readline().split()))
			if dp[r] - dp[l - 1] == 0:
				stdout.write('0\n')
				continue
			ans = []
			if (l - r + 1) % 2 == 0:
				ans.append(l)
				l += 1
			if l == r:
				ans.append(l)
			else:
				target = int((dp[r] - dp[l - 1]) / 2) + dp[l - 1]
				if dp[r] - dp[l - 1] > 0:
					pos = bisect.bisect_left(dp_p[target], l)
					if pos >= len(dp_p[target]):
						ans.append(l)
					else:
						ans.append(dp_p[target][pos] + 1)
				else:
					pos = bisect.bisect_left(dp_m[target], l)
					if pos >= len(dp_m[target]):
						ans.append(l)
					else:
						ans.append(dp_m[target][pos] + 1)
			stdout.write(str(len(ans)) + '\n')
			stdout.write(' '.join([str(x) for x in ans]) + '\n')
main()


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

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

def ls():
	return [i for i in input().split()]
import bisect
from collections import defaultdict
for t in range(ii()):
	t += 1
	(n, q) = li()
	s = input().strip()
	s = '&' + s
	a = [0]
	dic = defaultdict(lambda : [])
	for i in range(1, n + 1):
		if s[i] == '+':
			a.append(1)
		else:
			a.append(-1)
	prf = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		if i % 2:
			prf[i] = prf[i - 1] + a[i]
		else:
			prf[i] = prf[i - 1] - a[i]
	for i in range(0, n):
		dic[prf[i] + prf[i + 1]].append(i + 1)
	for _ in range(q):
		(l, r) = li()
		if (r - l + 1) % 2:
			print(1)
			xx = prf[l - 1] + prf[r]
			ind = bisect.bisect_left(dic[xx], l)
			print(dic[prf[l - 1] + prf[r]][ind])
		else:
			if prf[r] == prf[l - 1]:
				print(0)
				continue
			print(2)
			r -= 1
			xx = prf[l - 1] + prf[r]
			ind = bisect.bisect_left(dic[xx], l)
			print(r + 1, dic[xx][ind])


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

def mdn(v):
	if v == 0:
		return 0
	if v % 2:
		return 1
	return 2

def bs(lf, r, v):
	(s, e) = (lf, r)
	while s <= e:
		m = (s + e) // 2
		val = l[m - 1] - l[lf - 1] - l[r] + l[m]
		if val == 0:
			return m
		if v < 0 and val < 0 or (v > 0 and val > 0):
			e = m - 1
		else:
			s = m + 1
	return s
for _ in range(inp()):
	(n, q) = invr()
	s = insr()
	d = {'+': 1, '-': -1}
	l = [0]
	for i in range(n):
		if i % 2:
			l.append(l[-1] - d[s[i]])
		else:
			l.append(l[-1] + d[s[i]])
	for i in range(q):
		(lf, rt) = invr()
		v = l[rt] - l[lf - 1]
		if v == 0:
			print(0)
		elif v % 2:
			print(1)
			print(bs(lf, rt, v))
		else:
			print(2)
			if (l[rt] - l[lf]) % 2 != 0:
				print(lf, bs(lf + 1, rt, l[rt] - l[lf]))
			else:
				print(bs(lf + 1, rt, l[rt - 1] - l[lf - 1]), rt)


from collections import defaultdict
import bisect
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	s = list(input().rstrip())
	x = [0]
	for i in range(n):
		if i % 2:
			if s[i] == '+':
				x.append(x[-1] + 1)
			else:
				x.append(x[-1] - 1)
		elif s[i] == '-':
			x.append(x[-1] + 1)
		else:
			x.append(x[-1] - 1)
	d = defaultdict(lambda : [])
	x0 = [x[i] + x[i + 1] for i in range(n)]
	for i in range(n):
		d[x[i] + x[i + 1]].append(i + 1)
	for _ in range(q):
		(l, r) = map(int, input().split())
		c = x[r] - x[l - 1]
		d0 = r - l + 1
		if d0 % 2:
			k = 1
		else:
			k = 0 if c == 0 else 2
		ans = []
		print(k)
		if k == 1:
			y = x[r] + x[l - 1]
			ans.append(d[y][bisect.bisect_left(d[y], l - 0.5)])
		if k == 2:
			ans.append(l)
			y = x[r] + x[l]
			ans.append(d[y][bisect.bisect_left(d[y], l + 0.5)])
		if k:
			print(*ans)


import os, sys, bisect
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')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	s = input()
	arr = [0 for i in range(n)]
	for i in range(n):
		if s[i] == '+':
			arr[i] = 1
		else:
			arr[i] = -1
		if i % 2:
			arr[i] = -arr[i]
	prefix = [0] * (n + 1)
	for i in range(1, n + 1):
		prefix[i] = prefix[i - 1] + arr[i - 1]
	memo = {}
	for i in range(1, n + 1):
		value = prefix[i] + prefix[i - 1]
		if value not in memo:
			memo[value] = [i]
		else:
			memo[value].append(i)
	ans = [0 for i in range(q)]
	for i in range(q):
		(l, r) = map(int, input().split())
		value = prefix[r] - prefix[l - 1]
		if abs(value) == 0:
			print(0)
		elif (r - l + 1) % 2 == 0:
			print(2)
			l += 1
			num = prefix[r] + prefix[l - 1]
			point = bisect.bisect_left(memo[num], l)
			print(l - 1, memo[num][point])
		else:
			print(1)
			num = prefix[r] + prefix[l - 1]
			point = bisect.bisect_left(memo[num], l)
			print(memo[num][point])


import sys, bisect
for _ in range(int(sys.stdin.readline())):
	(n, q) = [int(i) for i in sys.stdin.readline().split()]
	s = sys.stdin.readline()
	r = [0] * (n + 1)
	d = {}
	for i in range(n):
		x = r[i + 1] = r[i] + ((s[i] == '-') * 2 - 1) * (i % 2 * 2 - 1)
		if x in d:
			d[x].append(i)
		else:
			d[x] = [i]
	for i in range(q):
		(a, b) = [int(x) for x in sys.stdin.readline().split()]
		t = r[b] - r[a - 1]
		if t % 2:
			p = d[r[a - 1] + (t // 2 + (t > 0))]
			sys.stdout.write('1\n%d\n' % (p[bisect.bisect_left(p, a - 1)] + 1))
		elif t == 0:
			sys.stdout.write('0\n')
		else:
			t = r[b] - r[a]
			p = d[r[a] + (t // 2 + (t > 0))]
			sys.stdout.write('2\n%d %d\n' % (a, p[bisect.bisect_left(p, a)] + 1))


import io, os
import bisect
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	(n, q) = map(int, input().split())
	s = input()
	accu = [0] * (n + 1)
	dic = {}
	for i in range(n):
		if i % 2 == 0:
			if s[i] == ord('+'):
				accu[i] = accu[i - 1] + 1
			else:
				accu[i] = accu[i - 1] - 1
		elif s[i] == ord('+'):
			accu[i] = accu[i - 1] - 1
		else:
			accu[i] = accu[i - 1] + 1
		num = accu[i] + accu[i - 1]
		if num not in dic:
			dic[num] = []
		dic[num].append(i)
	for _ in range(q):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		if (r - l + 1) % 2 == 1:
			print(1)
			sub = accu[r] + accu[l - 1]
			arr = dic[sub]
			loc = bisect.bisect_left(arr, l)
			print(arr[loc] + 1)
		elif accu[r] == accu[l - 1]:
			print(0)
		else:
			print(2)
			sub = accu[r] + accu[l]
			arr = dic[sub]
			loc = bisect.bisect_left(arr, l)
			print(l + 1, arr[loc] + 1)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

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')
from bisect import bisect_left, bisect_right

def solve(l, r, rod, pre):
	left = l
	right = r
	while left <= right:
		middle = (left + right) // 2
		if pre[middle - 1] - pre[l - 1] == pre[r] - pre[middle]:
			return middle
		if pre[middle - 1] - pre[l - 1] > pre[r] - pre[middle] and pre[r] >= pre[l] or (pre[middle - 1] - pre[l - 1] < pre[r] - pre[middle] and pre[r] <= pre[l]):
			right = middle - 1
		else:
			left = middle + 1
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	get = input()
	rod = [0] + [1 if get[i] == '+' and i % 2 == 0 or (get[i] == '-' and i % 2 == 1) else -1 for i in range(n)]
	pre = [0]
	for i in range(1, n + 1):
		pre.append(pre[i - 1] + rod[i])
	for i in range(q):
		(l, r) = map(int, input().split())
		subsum = pre[r] - pre[l - 1]
		if subsum == 0:
			print(0)
		elif subsum % 2 == 1:
			print(1)
			print(solve(l, r, rod, pre))
		else:
			print(2)
			print(solve(l, r - 1, rod, pre), r)


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')
import bisect as bs
for i in range(int(input())):
	(n, q) = map(int, input().split())
	s = input()
	ps = [0] * (n + 1)
	d = {}
	d['+'] = 1
	d['-'] = -1
	for i in range(1, n + 1):
		x = 1
		if i % 2 == 0:
			x = -1
		ps[i] = ps[i - 1] + x * d[s[i - 1]]
	d = {}
	for i in range(1, n + 1):
		x = ps[i] + ps[i - 1]
		if x not in d:
			d[x] = []
			d[x].append(i)
		else:
			d[x].append(i)
	for i in range(q):
		(l, r) = map(int, input().split())
		x = ps[r] - ps[l - 1]
		if x == 0:
			print(0)
		elif (r - l + 1) % 2 == 1:
			if r == l:
				print(1)
				print(r)
				continue
			print(1)
			val = ps[r] + ps[l - 1]
			x = bs.bisect_left(d[val], l)
			print(d[val][x])
		else:
			print(2)
			if r == l + 1:
				print(l, r)
				continue
			val = ps[r] + ps[l]
			x = bs.bisect_left(d[val], l + 1)
			print(l, d[val][x])


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')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
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
bs = BinarySearch()
for _ in range(int(input()) if True else 1):
	(n, q) = map(int, input().split())
	s = input()
	di = {}
	pre = [0]
	for i in range(n):
		pre += [pre[-1] + (1 if i % 2 == 0 and s[i] == '+' or (i % 2 and s[i] == '-') else -1)]
		ch = (pre[-2], pre[-1])
		if ch not in di:
			di[ch] = []
		di[ch] += [i]

	def get(x, y):
		diff = pre[y + 1] - pre[x]
		final = pre[y + 1]
		t1 = pre[x] + (-(-diff // 2) if diff < 0 else diff // 2)
		t2 = t1 + 1 if final > pre[x] else t1 - 1
		assert final == pre[y + 1]
		return bs.greater_than(x - 1, di[t1, t2]).value + 1
	for __ in range(q):
		(x, y) = map(int, input().split())
		x -= 1
		y -= 1
		if pre[y + 1] - pre[x] == 0:
			print(0)
			continue
		elif (y - x + 1) % 2:
			print(1)
			print(get(x, y))
		else:
			print(2)
			print(x + 1, get(x + 1, y))


from collections import defaultdict
import bisect
import sys
input = sys.stdin.readline
maxN = 300000
sumDictionary = [[] for i in range(4 * maxN + 1)]
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	s = input()
	currentSum = 0
	sumList = [0]
	for (i, char) in enumerate(s):
		sumList.append(sumList[i] + (1 if char == '+' else -1) * (1 if i % 2 == 0 else -1))
		sumDictionary[sumList[i] + sumList[i + 1] + 2 * maxN] = []
	for i in range(n):
		sumDictionary[sumList[i] + sumList[i + 1] + 2 * maxN].append(i + 1)
	for _ in range(q):
		(l, r) = map(int, input().split())
		if (l - r) % 2 == 0:
			print(1)
			calc = sumDictionary[sumList[r] + sumList[l - 1] + 2 * maxN]
			print(calc[bisect.bisect_left(calc, l)])
		elif sumList[r] == sumList[l - 1]:
			print(0)
		else:
			print(2)
			calc = sumDictionary[sumList[r] + sumList[l] + 2 * maxN]
			print(l, calc[bisect.bisect_left(calc, l + 1)])


import sys
input = sys.stdin.readline

def main():
	(n, q) = map(int, input().split())
	S = input().strip()
	cum = [0]
	for (i, s) in enumerate(S):
		if (s == '+') ^ (i % 2 == 1):
			cum.append(cum[-1] + 1)
		else:
			cum.append(cum[-1] - 1)
	for _ in range(q):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		d = cum[r + 1] - cum[l]
		if d == 0:
			print(0)
			continue
		elif d % 2 == 1:
			x = 1
			print(1)
		else:
			x = 2
			print(2)
			y = r
			r -= 1
			d = cum[r + 1] - cum[l]
		if d > 0:
			d = (d + 1) // 2
			ll = l - 1
			rr = r
			while rr - ll > 1:
				mid = (rr + ll) // 2
				if cum[mid + 1] - cum[l] >= d:
					rr = mid
				else:
					ll = mid
			if x == 1:
				print(rr + 1)
			else:
				print(rr + 1, y + 1)
		else:
			d = (d - 1) // 2
			ll = l - 1
			rr = r
			while rr - ll > 1:
				mid = (rr + ll) // 2
				if cum[mid + 1] - cum[l] <= d:
					rr = mid
				else:
					ll = mid
			if x == 1:
				print(rr + 1)
			else:
				print(rr + 1, y + 1)
for _ in range(int(input())):
	main()


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 16
md = 10 ** 9 + 7
from collections import defaultdict
from bisect import bisect_left

def solve():
	(n, q) = LI()
	s = SI()
	aa = []
	for (i, c) in enumerate(s):
		if i & 1 ^ (c == '+'):
			aa.append(1)
		else:
			aa.append(-1)
	cs = [0] * (n + 1)
	for i in range(n)[::-1]:
		cs[i] = aa[i] + cs[i + 1]
	tt = [0] * (n + 1)
	for i in range(n):
		tt[i] = 2 * cs[i + 1] + aa[i]
	ttoi = defaultdict(list)
	for (i, t) in enumerate(tt):
		ttoi[t].append(i)
	for _ in range(q):
		(l, r) = LI()
		l -= 1
		v = cs[l] - cs[r]
		if v == 0:
			print(0)
			continue
		ans = []
		if r - l & 1 == 0:
			ans.append(r)
			r -= 1
		t = cs[l] + cs[r]
		j = bisect_left(ttoi[t], l)
		i = ttoi[t][j]
		ans.append(i + 1)
		print(len(ans))
		print(*ans)
for testcase in range(II()):
	solve()


import io, os
import bisect
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

class segment_tree(object):

	def merge(self, num, minimum):
		return min(minimum, num)

	def __init__(self, n, initial):
		self.n = n
		self.arr = [2147483647] * (2 * n)
		for i in range(2 * n - 1, 0, -1):
			if i >= n:
				self.arr[i] = initial[i - n]
			else:
				self.arr[i] = self.merge(self.arr[2 * i], self.arr[2 * i + 1])

	def update(self, index, target):
		self.arr[index] = target
		if index & 1:
			nexttarget = self.merge(self.arr[index], self.arr[index - 1])
		else:
			nexttarget = self.merge(self.arr[index], self.arr[index + 1])
		if index > 0:
			self.update(index >> 1, nexttarget)

	def addnum(self, index, diff):
		self.update(index + self.n, self.arr[index + self.n] + diff)

	def query(self, left, right):
		(i, j) = (self.n + left, self.n + right + 1)
		output = 2147483647
		while i < j:
			if i & 1:
				output = self.merge(self.arr[i], output)
				i += 1
			if j & 1:
				j -= 1
				output = self.merge(self.arr[j], output)
			i = i >> 1
			j = j >> 1
		return output

def main(t):
	(n, q) = map(int, input().split())
	s = input()
	accu = [0] * (n + 1)
	dic = {}
	neighaccu = [0] * n
	for i in range(n):
		if i % 2 == 0:
			if s[i] == ord('+'):
				accu[i] = accu[i - 1] + 1
			else:
				accu[i] = accu[i - 1] - 1
		elif s[i] == ord('+'):
			accu[i] = accu[i - 1] - 1
		else:
			accu[i] = accu[i - 1] + 1
		num = accu[i] + accu[i - 1]
		if num not in dic:
			dic[num] = []
		dic[num].append(i)
		neighaccu[i] = num
	seg = segment_tree(n, neighaccu)
	for _ in range(q):
		(l, r) = map(int, input().split())
		l -= 1
		r -= 1
		if (r - l + 1) % 2 == 1:
			print(1)
			sub = accu[r] + accu[l - 1]
			arr = dic[sub]
			loc = bisect.bisect_left(arr, l)
			print(arr[loc] + 1)
		elif accu[r] == accu[l - 1]:
			print(0)
		else:
			print(2)
			diff = accu[r] - accu[l - 1]
			minimum = seg.query(l, r)
			if diff > 0:
				arr = dic[minimum]
				loc = bisect.bisect_left(arr, l)
				x = arr[loc]
				arr = dic[minimum + diff]
				loc = bisect.bisect(arr, r) - 1
				y = arr[loc]
			else:
				arr = dic[minimum - diff]
				loc = bisect.bisect_left(arr, l)
				x = arr[loc]
				arr = dic[minimum]
				loc = bisect.bisect(arr, r) - 1
				y = arr[loc]
			print(x + 1, y + 1)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


import os, sys
from io import BytesIO, IOBase
from collections import defaultdict
from bisect import bisect_left as bl

def main():
	for _ in range(int(input())):
		(n, Q) = map(int, input().split())
		s = input().strip()
		su = [0]
		for (idx, i) in enumerate(s):
			si = -1 if idx & 1 else 1
			num = 1 if i == '+' else -1
			su.append(su[-1] + num * si)
		dct = defaultdict(list)
		for (idx, i) in enumerate(su):
			dct[i].append(idx)
		for _ in range(Q):
			(l, r) = map(int, input().split())
			x = su[r] - su[l - 1]
			if not x:
				print(0)
			elif x & 1:
				print(1)
				y = x // 2 + (1 if x > 0 else 0) + su[l - 1]
				print(dct[y][bl(dct[y], l)])
			else:
				print(2)
				x = su[r - 1] - su[l - 1]
				y = x // 2 + (1 if x > 0 else 0) + su[l - 1]
				print(dct[y][bl(dct[y], l)], r)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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