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

Solutions:
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)


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


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