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: interview

Starter code:

Solutions:
for _ in range(int(input())):
 n=int(input())
 a=input()
 b=input()
 l=[]
 flag=0
 for i in range(n):
  if b[i]!=a[i]:
   if b[i] in a and b[i]<a[i]:
    l.append(b[i])
   else:
    flag=1
    break
 if flag==1:
  print(-1)
 else:
  if l==[]:
   print(0)
  else:
   l = sorted(list(set(l)), reverse = True)
   print(len(l))
   for i in range(len(l)):
    q=[]
    r=[]
    for j in range(len(a)):
     if l[i]==b[j]:
      q.append(j)
      r.append(a[j])
    if l[i] not in r:
     for k in range(len(a)):
      if a[k]==l[i]:
       q.append(k)
    print(len(q),*q)
   


# cook your dish here
t = int(input())
for _ in range(t):
 n = int(input())
 a = input()
 b = input()
 a = list(a)
 b = list(b)
 l = []
 f = 1
 for i in range(n):
  if b[i]!=a[i]:
   if b[i] in a and b[i]<a[i]:
    l.append(b[i])
   else:
    f = 0
    break
 if f==0:
  print(-1)
 else:
  if l == []:
   print(0)
  else:
   l = sorted(list(set(l)), reverse = True)
   print(len(l))
   for i in range(len(l)):
    Q=[]
    R=[]
    for j in range(len(a)):
     if b[j]==l[i]:
      Q.append(j)
      R.append(a[j])
    if l[i] not in R:
     for k in range(n):
      if a[k]==l[i]:
       Q.append(k)
       break
    print(len(Q),*Q)

from collections import deque
t = int(input())
while t>0:
 t -= 1
 n = int(input())
 a = input()
 b = input()
 amap = {}
 bmap = {}
 for i, char in enumerate(a):
  if char in amap:
   amap[char].append(i)
  else:
   amap[char] = [i]
 for i, char in enumerate(b):
  if char in bmap:
   bmap[char].append(i)
  else:
   bmap[char] = [i]
 ans = []
 flag = False
 for letter in range(25, -1, -1):
  char = chr(ord('a')+letter)
  if char in bmap:
   if char not in amap:
    flag = True
    break
   else:
    ans.append([])
    for ind in bmap[char]:
     if a[ind] < char:
      flag = True
      break
     elif a[ind] == char:
      pass
     else:
      ans[-1].append(ind)
    if len(ans[-1]):
     ans[-1].append(amap[char][0])
    else:
     ans.pop()
  if flag:
   break
 if flag:
  print(-1)
 else:
  print(len(ans))
  for item in ans:
   print(len(item), end=' ')
   print(*item)

t = int(input())

for i in range(t):
 n = int(input())
 A = list(input())
 B = list(input())
 flag = 0
 if(A == B):
  print(0)
 else:

  for i in range(n):
   if(B[i] not in A or ord(A[i]) < ord(B[i])):
    print(-1)
    flag = 1
    break
  
  



  if(flag == 0):            
   count = 0
   small_ele = list(set(B))
   seti = []
   

   for j in small_ele:
    temp = []
    ind = A.index(j)
    if(A != B):
     temp.append(ind)
     for k in range(n):
      if(B[k] == j and A[k] != j):
       A[k] = j
       temp.append(k)
     count = count + 1
     seti.append(temp)
    else:
     break
   
   print(count)
   for i in seti:
    d = len(i)
    print(d,end=" ")
    for j in range(d):
     print(i[j],end=" ")
    print(end="\n")
   
  



 



t = int(input())

for i in range(t):
 n = int(input())
 A = list(input())
 B = list(input())
 flag = 0
 if(A == B):
  print(0)
 else:

  for i in range(n):
   if(B[i] not in A or ord(A[i]) < ord(B[i])):
    print(-1)
    flag = 1
    break
  
  



  if(flag == 0):            
   count = 0
   small_ele = list(set(B))
   seti = []
   small_ele.sort()
   small_ele.reverse()

   for j in small_ele:
    temp = []
    ind = A.index(j)
    if(A != B):
     temp.append(ind)
     for k in range(n):
      if(B[k] == j and A[k] != j):
       A[k] = j
       temp.append(k)
     count = count + 1
     seti.append(temp)
    else:
     break
   
   print(count)
   for i in seti:
    d = len(i)
    print(d,end=" ")
    for j in range(d):
     print(i[j],end=" ")
    print(end="\n")
   
  



 



for _ in range(int(input())):
 N = int(input())
 c_str = str(input())
 target_str = str(input())
 no_match = False

 for i in range(N):

  if c_str[i] < target_str[i]: 
   no_match = True
   break 
  
  if target_str[i] not in c_str : 
   no_match = True
   break
 
 if no_match : 
  print(-1)
 
 else:
  indices = {char : index for index, char in enumerate(c_str)}
  m_match = {}
  for i in range(N):
   # c_str[i] is greater than target_str[i]
   if c_str[i] != target_str[i] : 
    if m_match.get(target_str[i]) : 
     m_match[target_str[i]].append(str(i))
    
    else : 
     m_match[target_str[i]] = [str(i)]
   
  
  print(len(m_match))

  for i in sorted(m_match.keys(), reverse=True):

   print(len(m_match[i])+1," ".join(m_match[i]), indices[i])

for _ in range(int(input())):
 N = int(input())
 c_str = str(input())
 target_str = str(input())
 no_match = False

 for i in range(N):

  if c_str[i] < target_str[i]: 
   no_match = True
   break 
  
  if target_str[i] not in c_str : 
   no_match = True
   break
 
 if no_match : 
  print(-1)
 
 else:
  indices = {char : index for index, char in enumerate(c_str)}
  m_match = {}
  for i in range(N):
   # c_str[i] is greater than target_str[i]
   if c_str[i] != target_str[i] : 
    if m_match.get(target_str[i]) : 
     m_match[target_str[i]].append(str(i))
    
    else : 
     m_match[target_str[i]] = [str(i)]
   
  
  print(len(m_match))

  for i in sorted(m_match.keys(), reverse=True):

   print(len(m_match[i])+1," ".join(m_match[i]), indices[i])

for _ in range(int(input())):
 N = int(input())
 c_str = str(input())
 target_str = str(input())
 no_match = False

 for i in range(N):

  if c_str[i] < target_str[i]: 
   no_match = True
   break 
  
  if target_str[i] not in c_str : 
   no_match = True
   break
 
 if no_match : 
  print(-1)
 
 else:
  indices = {char : index for index, char in enumerate(c_str)}
  m_match = {}
  for i in range(N):
   # c_str[i] is greater than target_str[i]
   if c_str[i] != target_str[i] : 
    if m_match.get(target_str[i]) : 
     m_match[target_str[i]].append(str(i))
    
    else : 
     m_match[target_str[i]] = [str(i)]
   
  
  print(len(m_match))

  for i in sorted(m_match.keys(), reverse=True):

   print(len(m_match[i])+1," ".join(m_match[i]), indices[i])

# cook your dish here
def conv(a, b):
 stop = 0
 n = len(a)
 for i in range(0,n):
  if ord(a[i]) - ord(b[i]) < 0:
   print(-1)
   stop = 1 
   
 if stop == 0:
  for i in range (0,n):
   flag =0
   for j in range (0,n):
    if b[i] == a[j]:
     flag = 1
     break
   if flag == 0:
    print(-1)
    stop = 1 
    break
 if stop ==0:
  distinctArr = []
  for i in range (0,n):
   dontAdd = 0
   if a[i] != b[i]:
    for j in range (0,len(distinctArr)):
     if b[i] == distinctArr[j]:
      dontAdd = 1
    if dontAdd == 0:
     distinctArr.append(b[i])
  distinctArr.sort(reverse = True)
  print(len(distinctArr))
  
  for i in range (0,len(distinctArr)):
   arr = []
   for j in range(0,n):
    if distinctArr[i]==b[j] and b[j]!=a[j]:
     arr.append(j)
   for j in range (0,n):
    if distinctArr[i] == a[j]:
     arr.append(j)
     break
   arr.sort()
   print(len(arr), end =" ")
   for k in range (0,len(arr)):
    if k == len(arr)-1:
     print(arr[k])
    else:
     print(arr[k], end=" ")
  #print(distinctArr)
     
t = int(input())
for i in range (0,t):
 n = int(input())
 a = input()
 b = input()
 arr1 = list(a)
 arr2 = list(b)
 conv(arr1, arr2)
 
 
 
 
 
 
  
  
  
  
  
  
  
  
  

T = int(input())
for _ in range(T):
 N = int(input())
 A = list(input())
 B = list(input())
 if(not set(B).issubset(set(A))):
  print(-1)
 else:
  l1 = []
  flag = 1
  for (i,(x,y)) in enumerate(list(zip(A,B))):
   if(y>x):
    flag = 0
    break
   elif(y==x):
    pass
   else:
    l1.append((i,(x,y)))
  if(flag):
   s = set(list(reversed(list(sorted([y for i,(x,y) in l1])))))
   number_of_ops = len(s)
   print(number_of_ops)
   for char in s:
    answer = []
    for item in l1:
     if(char == item[1][1]):
      answer.append(item[0])
    answer.append(list(A).index(char))
    answer.insert(0,len(answer))
    print(' '.join(list(map(str,answer))))
  else:
   print(-1)
    
  
    


'''for _ in range(int(input())):
    N = int(input())
    a = list(input())
    b = list(input())
    aset = set(a)
    bset = set(b)
    if(a == b):
     print(0)

    elif(bset.issubset(aset)):
     d = {}
     wr = {}
     f = 0
     for i in range(N):
      if(a[i] != b[i]):
       if b[i] in d:
        d[b[i]].append(i)
        wr[b[i]].append(a[i])
       else:
        d[b[i]] = []
        wr[b[i]] = []
        d[b[i]].append(i)
        wr[b[i]].append(a[i])
     #print(wr,d)

     for k,v in sorted(wr.items(),reverse=True):
      # print(k,v)
      for i in v:
       # print(k,i)
       if ord(k)>ord(i):
        f=1
        break
      if f==1:
       break
     # print(flag)
     if f==1:
      print(-1)
     else:
      print(len(d))
      for k,v in sorted(d.items(),reverse=True):
       print(len(d[k])+1,end=" ")
       print(d[k],a.index(k))



    else:
     print(-1)''' 


for _ in range(int(input())):
 n=int(input())
 
 a=list(input())
 
 b=list(input())
 if(a==b):
  print(0)
 else:
  l=[]
  c=0
  for i in range(n):
   if(b[i] not in l):
    if(b[i] not in a):
     c=1
     break
    l.append(b[i])
  if(c):
   print(-1)
  else:
   l.sort()
   l.reverse()
   truthy=0
   list1=[]
   for i in range(len(l)):
    current=l[i]
    posb=[]
    one=None
    for j in range(n):
     if(one==None):
      if(a[j]==current):
       one=j
     if(b[j]==current):
      posb.append(j)
    for j in range(len(posb)):
     if(a[posb[j]]<current):
      truthy=1
      break
    if(truthy==1):
     break
    else:
     
     if(one not in posb):
      posb.append(one)
     qq=0
     for j in range(len(posb)):
      if(a[posb[j]]!=current):
       qq=1
     if(qq):
      for j in range(len(posb)):
       a[posb[j]]=current
      list1.append(posb)
   if(truthy):
    print(-1)
   else:
    print(len(list1))
    for i in range(len(list1)):
     print(len(list1[i]),end=" ")
     for j in range(len(list1[i])):
      print(list1[i][j],end=" ")
     print("\n")

import string

ASCII_ASC = string.ascii_lowercase
ASCII_DSC = sorted(ASCII_ASC, reverse=True)

def int_input():
 return int(input())

def array_input(data_type=int):
 if data_type != str:
  return list(map(data_type, input().split("")))
 else:
  return list(map(str, input()))

def solve():
 N = int_input()
 A = array_input(data_type=str)
 B = array_input(data_type=str)
 for i in range(N):
  if A[i] < B[i]:
   print(-1)
   return
 res = []
 for ch in ASCII_DSC:
  idx_pos = []
  chk = False

  for i in range(0, N):
   if B[i] == ch and A[i] != ch:
    # print("ch",ch)
    idx_pos.append(i)
  # print("idx_pos", idx_pos)
  if chk is False and len(idx_pos):
   for i in range(0, N):
    if A[i] == ch:
     # print("setting chk = True")
     chk = True
     idx_pos.append(i)
  # print("now idx_pos",idx_pos)
  if chk is False and len(idx_pos):
   print(-1)
   return
  if len(idx_pos):
   res.append(idx_pos)
  for idx in idx_pos:
   A[idx] = ch
 print(len(res))
 for arr in res:
  print(len(arr), " ".join(map(str, arr)))


  
t = int_input()
while t > 0:
 t -= 1
 solve()


for _ in range (int(input())):
 n=int(input())
 a1=input()
 b1=input()
 a=[]
 b=[]
 for i in a1:
  a.append(ord(i)-97)
 for i in b1:
  b.append(ord(i)-97)
 ind = [-1]*26
 for i in range (n):
  ind[a[i]]=i
 ans=[]
 temp = 0
 for i in range(n):
  if b[i]>a[i]:
   temp = 1
   break
 for i in range (n):
  if ind[b[i]]==-1:
   temp = 1
 for i in range (24,-1,-1):
  ans.append([])
  ans[-1].append(ind[i])
  for j in range (n):
   if a[j]>i and b[j]==i and ind[i]!=-1:
    ans[-1].append(j)
  if temp == 1:
   break
 if temp == 1:
  print(-1)
 else:
  l = 0
  for i in ans:
   if len(i)!=1:
    l+=1
  print(l)
  for i in ans:
   if len(i)!=1:
    print(len(i),end=" ")
    print(*i)


from collections import defaultdict
def fn(a,b,n):
 l=[]
 da=defaultdict(lambda:[])
 db=defaultdict(lambda:[])
 idx=jdx=0
 for i,j in zip(a,b):
  if i<j or j not in a:
   print(-1)
   return
  da[i].append(idx)
  db[j].append(jdx)
  idx+=1
  jdx+=1
 c=0
 #print(b)
 while a!=b:
  mx=max(db)
  tc=[]
  for i in db[mx]:
   if a[i]!=b[i]:
    tc.append(i)
    da[a[i]].remove(i)
    a[i]=mx
    da[mx].append(i)
  
  for i in da[mx]:
   if a[i]==mx:
    tc.append(i)
    break

  del db[mx]
  #print(a)
  l.append(tc)
  c+=1
 print(c)
 for i in range(c):
  print(len(l[i]),end=' ')
  for j in l[i]:
   print(j,end=' ')
  print()




t=int(input())
for i in range(t):
 n=int(input())
 a=input()
 a=[i for i in a]
 b=input()
 b=[i for i in b]
 fn(a,b,n)


from collections import defaultdict
def fn(a,b,n):
 l=[]
 da=defaultdict(lambda:[])
 db=defaultdict(lambda:[])
 idx=jdx=0
 for i,j in zip(a,b):
  if i<j or j not in a:
   print(-1)
   return
  da[i].append(idx)
  db[j].append(jdx)
  idx+=1
  jdx+=1
 c=0
 #print(b)
 while a!=b:
  mx=max(db)
  tc=[da[mx][0]]
  for i in db[mx]:
   if a[i]!=b[i]:
    tc.append(i)
    da[a[i]].remove(i)
    a[i]=mx
    da[mx].append(i)

  del db[mx]
  #print(a)
  l.append(tc)
  c+=1
 print(c)
 for i in range(c):
  print(len(l[i]),end=' ')
  for j in l[i]:
   print(j,end=' ')
  print()




t=int(input())
for i in range(t):
 n=int(input())
 a=input()
 a=[i for i in a]
 b=input()
 b=[i for i in b]
 fn(a,b,n)


from collections import defaultdict
def fn(a,b,n):
 l=[]
 da=defaultdict(lambda:[])
 db=defaultdict(lambda:[])
 idx=jdx=0
 for i,j in zip(a,b):
  if i<j or j not in a:
   print(-1)
   return
  da[i].append(idx)
  db[j].append(jdx)
  idx+=1
  jdx+=1
 c=0
 #print(b)
 while a!=b:
  mx=max(db)
  tc=[da[mx][0]]
  for i in db[mx]:
   if a[i]!=b[i]:
    tc.append(i)
    a[i]=mx
  del db[mx]
  #print(a)
  l.append(tc)
  c+=1
 print(c)
 for i in range(c):
  print(len(l[i]),end=' ')
  for j in l[i]:
   print(j,end=' ')
  print()




t=int(input())
for i in range(t):
 n=int(input())
 a=input()
 a=[i for i in a]
 b=input()
 b=[i for i in b]
 fn(a,b,n)


for _ in range(int(input())):
 n = int(input())
 a = input()
 b = input()
 flag = 1
 for i in range(n):
  if a[i] < b[i]:
   flag = 0
   break
  if b[i] not in set(a):
   flag = 0
   break
 
 if flag == 1:
  d = {}
  for i in range(n):
   if a[i]!=b[i]:
    if b[i] not in d:
     d[b[i]]=[0]
    d[b[i]][0] += 1 
    d[b[i]] += [i]
  # print(d)
    
  cov = sorted(d,reverse=True)
  # print(cov)
  ans = []
  opr = len(cov)
  for i in cov:
   t = [d[i][0]+1]+[a.index(i)]+d[i][1:]
   # print(i)
   # print(t)
   ans.append(t)
  print(opr)
  for i in ans:
   print(*i, sep=' ')
 else:
  print(-1)

# cook your dish here
for _ in range(int(input())):
 n = int(input())
 firstString = list(input())
 secondString = list(input())
 firstStringSet = set(firstString)
 secondStringSet = set(secondString)
 if firstString==secondString:
  print(0)
 
 elif secondStringSet.issubset(firstStringSet):
  d={}
  wr = {}
  f=0
  for i in range(n):
   if firstString[i]!=secondString[i]:
    if secondString[i] in d:
     d[secondString[i]].append(i)
     wr[secondString[i]].append(firstString[i])
    else:
     d[secondString[i]]=[]
     wr[secondString[i]]=[]
     d[secondString[i]].append(i)
     wr[secondString[i]].append(firstString[i])

  # print(wr,d)
  for k,v in sorted(wr.items(),reverse=True):
   # print(k,v)
   for i in v:
    # print(k,i)
    if ord(k)>ord(i):
     f=1
     break
   if f==1:
    break
  # print(flag)
  if f==1:
   print(-1)
  else:
   print(len(d))
   for k,v in sorted(d.items(),reverse=True):
    print(len(d[k])+1,end=" ")
    print(*d[k],firstString.index(k))
  
  
 else:
  print(-1)

T=int(input())
for _ in range(T):
 N=int(input())
 A=input()
 B=input()
 dupdel=list(dict.fromkeys(B))
 def notpossible(A,B,dupdel):
  for i in range(len(dupdel)):
   if dupdel[i] not in A:
    return -1
  for i in range(len(A)):
   if A[i]<B[i]:
    return -1
 if notpossible(A,B,dupdel)==-1:
  print(-1)
  continue
 else:
  L=[]
  for i in range(len(A)):
   if A[i]!=B[i]:
    L.append(B[i])
  #print(L)
  P=list(dict.fromkeys(L))
  print(len(P))
  P.sort(reverse=True)
  for i in range(len(P)):
   Q=[]
   R=[]
   for j in range(len(A)):
    if B[j]==P[i]:
     Q.append(j)
     R.append(A[j])
   if P[i] not in R:
    for k in range(N):
     if A[k]==P[i]:
      Q.append(k)
      break
   print(len(Q),*Q)


# cook your dish here
try:
 import string 
 alphabets=string.ascii_lowercase
 test=int(input())
 #ans=[]

 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 i in ans:
   #print(" ".join(map(str,i)))

 for _ in range(test):
  solve()



 
except:
 pass

# -*- s_oding: utf-8 -*-
"""
s_reated on Sat May 30 19:42:30 2020

@author: trinzya
"""

import string


t=int(input())
for i in range(t):
 n=int(input())
 a=list(input())
 b=list(input())
 #print(a,b)
 s=[]
 c=[]
 count=0
 s_=[]
 
 if not set(b).issubset(set(a)):
  #print("okay")
  print(-1)
  continue

 abs_=string.ascii_lowercase


 for k in range(len(abs_)-1,-1,-1):
  #print(count)
  flag=0
  f=0
  j=abs_[k]
  #print(j)
  if a==b:
   break
  if j not in c:
   #print(c)
   s=[]
   for i in range(n):
    #print( j,b[i]==j )
    
    if ((a[i]!=b[i]) and( b[i]==j )and (a[i]>j)):
     f=1
     #print(j)
     s.append(i)
    if a[i]==j:
     flag=1
     s.append(i)
    
   if len(s)!=0:
    count=count+1
    if len(s)==1:
     
     #p#rint("s")
     s=[]
     count=count-1
     continue
    if (flag==0 and f==1 )or( flag==1 and f==0):
     #print("f",f)
     #print("flag",flag)
     
     #print(s)
     count=count-1
     continue
    for i in s:
     #print(i)
     
     
     a[i]=j
     
    s_.append(s)
   c.append(j)
 if a!=b:
  #print(a,b)
  print(-1)
  continue
 
 print(count)
 if count!=0:
  for i in s_:
   i=list(map(str,i))
   print(len(i)," ".join(i))