Vivek was quite bored with the lockdown, so he came up with an interesting task. He successfully completed this task and now, he would like you to solve it.
You are given two strings $A$ and $B$, each with length $N$. Let's index the characters in each string from $0$ ― for each $i$ ($0 \le i < N$), the $i+1$-th characters of $A$ and $B$ are denoted by $A_i$ and $B_i$ respectively. You should convert $A$ to $B$ by performing operations of the following type:
- Choose a subset $S$ of the set $\{0, 1, \ldots, N-1\}$.
- Let $c$ be the alphabetically smallest character among $A_x$ for all $x \in S$.
- For each $x \in S$, replace $A_x$ by $c$.
You should find the smallest necessary number of operations or report that it is impossible to convert $A$ to $B$. If it is possible, you also need to find one way to convert $A$ to $B$ using this smallest number of operations. If there are multiple solutions, you may find any one.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains a single string $A$.
- The third line contains a single string $B$.

-----Output-----
For each test case:
- If it is impossible to convert $A$ to $B$, print a single line containing the integer $-1$.
- Otherwise, first, print a line containing a single integer $K$ ― the minimum number of operations.
- Then, print $K$ lines describing the operations. Each of these lines should contain a positive integer $Z$, followed by a space and $Z$ pairwise distinct space-separated integers from the set $\{0, 1, \ldots, N-1\}$ ― the elements of $S$.

-----Constraints-----
- $1 \le T \le 20$
- $1 \le N \le 10^3$
- $|A| = |B| = N$
- $A$ and $B$ contain only lowercase English letters

-----Subtasks-----
Subtask #1 (30 points): $B$ contains only characters 'a' and 'b'
Subtask #2 (70 points): original constraints

-----Example Input-----
3
5
abcab
aabab
3
aaa
aab
2
de
cd

-----Example Output-----
2
3 1 2 4
3 0 1 3
-1
-1

-----Explanation-----
Example case 1:
- First, we can choose $S = (1, 2, 4)$, so the character $c$ is 'b' and the string $A$ after this operation is "abbab".
- Then, we choose $S = (0, 1, 3)$, so $c$ is 'a', and $A$ becomes "aabab".
- There is no way to convert $A$ to $B$ in only one operation.
Example case 2: We can see that it is impossible to convert $A$ to $B$ since $c$ is always 'a'.
Example case 3: We can see again that it is impossible to convert $A$ to $B$ since $c$ cannot be 'c'.

Difficulty: MEDIUM_HARD

Solutions:
import collections

def possible(a, b):
	setA = collections.Counter(a)
	for i in range(len(a)):
		if ord(a[i]) < ord(b[i]) or b[i] not in setA:
			return True
	return False

def solve(a, b):
	setA = collections.defaultdict(set)
	setB = collections.defaultdict(set)
	for i in range(len(a)):
		setA[a[i]].add(i)
		if a[i] != b[i]:
			setB[b[i]].add(i)
	print(len(setB))
	setBkeys = list(setB.keys())
	setBkeys.sort(reverse=True)
	for key in setBkeys:
		temp = setA[key].union(setB[key])
		print(len(temp), ' '.join(map(str, temp)))
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if possible(a, b):
		print(-1)
		continue
	else:
		solve(a, b)


try:
	import string
	alphabets = string.ascii_lowercase
	test = int(input())

	def solve():
		ans = []
		n = int(input())
		string1 = []
		string2 = []
		present = [None] * 26
		string1 = list(input())
		string2 = list(input())
		for i in range(n):
			if string1[i] < string2[i]:
				print(-1)
				return
		for i in range(n):
			present[ord(string1[i]) - ord('a')] = 1
		for i in range(n):
			if present[ord(string2[i]) - ord('a')] != 1:
				print(-1)
				return
		for alpha in alphabets[::-1]:
			index = []
			for i in range(n):
				if string1[i] != alpha and string2[i] == alpha:
					index.append(i)
			if index:
				for i in range(n):
					if string1[i] == alpha:
						index.append(i)
			if index:
				ans.append(index)
			for i in range(len(index)):
				idx = index[i]
				string1[idx] = alpha
		print(len(ans))
		for i in ans:
			i.sort()
			print(len(i), *i)
	for _ in range(test):
		solve()
except:
	pass


def get_all_indexes_of_substring(string, substring):
	all_indexes = []
	start_pos = 0
	find_result = string.find(substring, start_pos)
	while find_result != -1:
		all_indexes.append(find_result)
		start_pos = find_result + 1
		find_result = string.find(substring, start_pos)
	return all_indexes

def calculate(a, b, n):
	if a == b:
		print(0)
		return
	a_indexes_that_require_change = []
	distinct_elements_in_b = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		if b[i] > a[i]:
			print('-1')
			return
		if b[i] not in a:
			print(-1)
			return
		a_indexes_that_require_change.append(i)
		if b[i] not in distinct_elements_in_b:
			distinct_elements_in_b.append(b[i])
	K = len(distinct_elements_in_b)
	print(K)
	for _ in range(K):
		b_diff_set = [b[i] for i in a_indexes_that_require_change]
		element_to_change = max(b_diff_set)
		all_indices = get_all_indexes_of_substring(''.join(b), element_to_change)
		for index in all_indices:
			if index in a_indexes_that_require_change:
				a_indexes_that_require_change.remove(index)
		seed = a.index(element_to_change)
		if seed not in all_indices:
			all_indices.append(seed)
		all_indices.sort()
		print(len(all_indices), ' '.join(map(str, all_indices)))
T = int(input())
for _ in range(T):
	N = int(input())
	A = input()
	B = input()
	calculate(A, B, N)


import string
t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	s = []
	c = []
	count = 0
	s_ = []
	if not set(b).issubset(set(a)):
		print(-1)
		continue
	abs_ = string.ascii_lowercase
	for k in range(len(abs_) - 1, -1, -1):
		flag = 0
		f = 0
		j = abs_[k]
		if a == b:
			break
		if j not in c:
			s = []
			for i in range(n):
				if a[i] != b[i] and b[i] == j and (a[i] > j):
					f = 1
					s.append(i)
				if a[i] == j:
					flag = 1
					s.append(i)
			if len(s) != 0:
				count = count + 1
				if len(s) == 1:
					s = []
					count = count - 1
					continue
				if flag == 0 and f == 1 or (flag == 1 and f == 0):
					count = count - 1
					continue
				for i in s:
					a[i] = j
				s_.append(s)
			c.append(j)
	if a != b:
		print(-1)
		continue
	print(count)
	if count != 0:
		for i in s_:
			i = list(map(str, i))
			print(len(i), ' '.join(i))


try:
	import string
	result = string.ascii_lowercase
	t = int(input())

	def solve():
		re = []
		n = int(input())
		a = list(input())
		b = list(input())
		present = [None] * 26
		for i in range(n):
			if a[i] < b[i]:
				print(-1)
				return
		for i in range(n):
			present[ord(a[i]) - ord('a')] = 1
		for i in range(n):
			if present[ord(b[i]) - ord('a')] != 1:
				print(-1)
				return
		for q in result[::-1]:
			w = []
			for i in range(n):
				if a[i] != q and b[i] == q:
					w.append(i)
			if w:
				for i in range(n):
					if a[i] == q:
						w.append(i)
			if w:
				re.append(w)
		print(len(re))
		for i in re:
			i.sort()
			print(len(i), *i)
	for z in range(t):
		solve()
except:
	pass


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	set_a = set(a)
	set_b = set(b)
	if not set_a.issuperset(set_b):
		print(-1)
		continue
	change = defaultdict(list)
	indexes = defaultdict(list)
	f = False
	for (i, (x, y)) in enumerate(zip(a, b)):
		indexes[x].append(i)
		if ord(x) - ord(y) < 0:
			print(-1)
			f = True
			break
		if ord(x) - ord(y):
			change[y].append(i)
	if f:
		continue
	print(len(change))
	start = sorted(list(change.keys()))
	for _ in range(len(start)):
		d = start.pop()
		out = list(change[d] + indexes[d])
		print(len(out), *sorted(out))


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
for __ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	isans = 1
	for i in range(n):
		if a[i] < b[i]:
			isans = 0
			break
		if b[i] not in a:
			isans = 0
			break
	if isans == 0:
		print(-1)
		continue
	else:
		rslt = []
		d = {}
		for i in range(n):
			if b[i] != a[i]:
				d[b[i]] = 1
		for i in range(26, -1, -1):
			ans = []
			if chr(i + 97) in d:
				for j in range(n):
					if b[j] == chr(i + 97) and b[j] != a[j]:
						ans.append(j)
					if a[j] == chr(i + 97):
						ans.append(j)
			if len(ans) != 0:
				rslt.append(ans)
		print(len(rslt))
		for i in range(len(rslt)):
			print(len(rslt[i]), end=' ')
			print(*rslt[i])


from collections import defaultdict
t = int(input())
for test in range(t):
	n = int(input())
	a = input()
	b = input()
	ast = defaultdict(set)
	bst = defaultdict(set)
	for i in range(n):
		ast[a[i]].add(i)
		bst[b[i]].add(i)
	ans = fl = 0
	out = []
	for i in range(97 + 25, 96, -1):
		ch = chr(i)
		if ch in bst:
			if ch not in ast:
				print(-1)
				fl = 1
				break
			else:
				(c, mn) = (0, 'z')
				ind = ast[ch].union(bst[ch])
				for j in ind:
					if a[j] < mn:
						mn = a[j]
					if a[j] != ch:
						c += 1
						ast[a[j]].discard(j)
				if mn < ch:
					print(-1)
					fl = 1
					break
				if c > 0:
					ans += 1
					out.append(list(ind))
	if fl == 0:
		print(ans)
		for i in out:
			print(len(i), *i)


import sys
dry_run = False
if dry_run:
	input_file = open('convert_the_string.txt')
	sys.stdin = input_file
global initial_map, final_map, result
for t in range(int(input())):
	length = int(input())
	initial = input()
	final = input()
	initial_map = dict()
	final_map = dict()
	result = list()
	possible = True
	for index in range(length):
		if initial[index] in initial_map:
			initial_map[initial[index]].add(index)
		else:
			my_set = set()
			my_set.add(index)
			initial_map[initial[index]] = my_set
		if final[index] in final_map:
			final_map[final[index]].add(index)
		else:
			my_set = set()
			my_set.add(index)
			final_map[final[index]] = my_set
		if final[index] > initial[index]:
			possible = False
			break
	if possible:
		for key in final_map:
			if key not in initial_map:
				possible = False
				break
	if possible:
		final_keys = [key for key in final_map]
		final_keys = sorted(final_keys, reverse=True)
		for char in final_keys:
			if char in initial_map and len(initial_map[char]) > 0:
				if not final_map[char].issubset(initial_map[char]):
					temp_set = set()
					temp_set.update(final_map[char])
					temp_set.update(initial_map[char])
					result.append(temp_set)
					for index in final_map[char]:
						initial_map[initial[index]].remove(index)
			else:
				possible = False
				break
	if possible:
		print(len(result))
		for res in result:
			print(len(res), end=' ')
			print(' '.join((str(r) for r in res)))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	A = list(input())
	B = list(input())
	element = sorted(list(set(B)))
	element = element[::-1]
	(flag, flag_) = (True, False)
	count = 0
	l = []
	for b in element:
		i = B.index(b)
		if b not in A:
			print(-1)
			flag = False
			break
		if A[i] >= b:
			s = [A.index(b)]
			j = i
			while j < n:
				if B[j] == b:
					if A[j] < b:
						print(-1)
						flag = False
						break
					elif A[j] > b:
						flag_ = True
					if j not in s:
						s.append(j)
					A[j] = b
				j += 1
			if flag_:
				l.append(s)
				count += 1
				flag_ = False
		else:
			print(-1)
			flag = False
			break
	if flag:
		print(count)
		for i in range(len(l)):
			print(len(l[i]), ' '.join(list(map(str, l[i]))))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().rstrip()
	b = input().rstrip()
	curr = {}
	L = []
	for i in range(n):
		if a[i] not in L:
			L.append(a[i])
			curr[a[i]] = []
		curr[a[i]].append(i)
	L.sort()
	to = {}
	flag = 0
	for i in range(n):
		if b[i] not in L:
			flag = 1
			break
		if a[i] != b[i]:
			if a[i] > b[i]:
				if b[i] not in to:
					to[b[i]] = []
				to[b[i]].append(i)
			else:
				flag = 1
				break
	if flag == 1:
		print(-1)
	else:
		ans = []
		while len(L) > 0:
			ch = L.pop(-1)
			if ch in to:
				li = curr[ch]
				for i in to[ch]:
					li.append(i)
				li.sort()
				ans.append(li)
		print(len(ans))
		for i in ans:
			print(len(i), end=' ')
			print(*i)


from sys import stdin, stdout
from collections import *
import re
t = int(stdin.readline().strip())
while t:
	t -= 1
	n = int(stdin.readline().strip())
	s1 = stdin.readline().strip()
	s2 = stdin.readline().strip()
	flag = True
	s1_dict = defaultdict(set)
	s2_dict = defaultdict(set)
	for (i, ch1, ch2) in zip(range(n), s1, s2):
		if ord(ch1) < ord(ch2):
			flag = False
			break
		s1_dict[ch1].add(i)
		if ch1 != ch2:
			s2_dict[ch2].add(i)
	if not flag or set(s2_dict) - set(s1_dict):
		print(-1)
		continue
	start = ord('z') + 1
	end = ord('a')
	step_cnt = 0
	steps = []
	while start > end:
		start -= 1
		ch = chr(start)
		if ch not in s2_dict:
			continue
		if s1_dict[ch] == s2_dict[ch]:
			continue
		step_cnt += 1
		all_val = s1_dict[ch] | s2_dict[ch]
		steps.append(all_val)
	print(step_cnt)
	for step in steps:
		print(len(step), ' '.join(map(str, sorted(step))))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a1 = set(a)
	flag = 0
	for i in range(n):
		if a[i] < b[i] or b[i] not in a1:
			flag = 1
			break
	if flag == 1:
		print(-1)
	else:
		a = list(a)
		b = list(b)
		d = {}
		for i in range(26):
			d[chr(ord('a') + i)] = 0
		l2 = []
		count1 = 0
		b1 = list(set(b))
		b1.sort(reverse=True)
		for c in b1:
			for i in range(n):
				l1 = [0]
				count = 0
				if b[i] == c and a[i] != c:
					if d[b[i]] == 0:
						count1 += 1
						d[b[i]] = 1
					for j in range(n):
						if a[j] == b[i] or b[j] == b[i]:
							l1.append(j)
							count += 1
							a[j] = b[i]
					l1.sort()
					l1[0] = count
					l2.append(l1)
		print(count1)
		for i in l2:
			print(*i)


def valid(s1, s2, n):
	for i in range(n):
		if s1[i] < s2[i]:
			print(-1)
			return
	temp = [0] * 26
	for i in range(n):
		temp[ord(s1[i]) - ord('a')] = 1
	for i in range(n):
		if temp[ord(s2[i]) - ord('a')] == 0:
			print(-1)
			return
	a = 'abcdefghijklmnopqrstuvwxyz'
	ans = []
	for i in range(25, -1, -1):
		f = 0
		temp = []
		for j in range(n):
			if s1[j] == a[i] or s2[j] == a[i]:
				if s1[j] != a[i]:
					f = 1
				temp.append(j)
		for j in temp:
			s1[j] = a[i]
		if f:
			ans.append(temp)
	print(len(ans))
	for i in ans:
		print(len(i), *i)
	return
t = int(input())
while t:
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	valid(s1, s2, n)
	t -= 1