There are $n$ left boots and $n$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $l$ and $r$, both of length $n$. The character $l_i$ stands for the color of the $i$-th left boot and the character $r_i$ stands for the color of the $i$-th right boot.

A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.

For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').

Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.

Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair.


-----Input-----

The first line contains $n$ ($1 \le n \le 150000$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots).

The second line contains the string $l$ of length $n$. It contains only lowercase Latin letters or question marks. The $i$-th character stands for the color of the $i$-th left boot.

The third line contains the string $r$ of length $n$. It contains only lowercase Latin letters or question marks. The $i$-th character stands for the color of the $i$-th right boot.


-----Output-----

Print $k$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors.

The following $k$ lines should contain pairs $a_j, b_j$ ($1 \le a_j, b_j \le n$). The $j$-th of these lines should contain the index $a_j$ of the left boot in the $j$-th pair and index $b_j$ of the right boot in the $j$-th pair. All the numbers $a_j$ should be distinct (unique), all the numbers $b_j$ should be distinct (unique).

If there are many optimal answers, print any of them.


-----Examples-----
Input
10
codeforces
dodivthree

Output
5
7 8
4 9
2 2
9 10
3 1

Input
7
abaca?b
zabbbcc

Output
5
6 5
2 3
4 6
7 4
1 2

Input
9
bambarbia
hellocode

Output
0

Input
10
code??????
??????test

Output
10
6 2
1 6
7 3
3 5
4 8
9 7
5 1
2 4
10 9
8 10

Difficulty: introductory

Starter code:

Solutions:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

from collections import defaultdict as dd

n = ii()
a, b = input().strip(), input().strip()
da, db = dd(list), dd(list)
qa, qb = [], []
for i in range(n):
    if a[i] == '?':
        qa.append(i)
    else:
        da[a[i]].append(i)
    if b[i] == '?':
        qb.append(i)
    else:
        db[b[i]].append(i)

ans = []
for c in 'abcdefghijklmnopqrstuvwxyz':
    u, v = da[c], db[c]
    while u and v:
        ans.append((u.pop(), v.pop()))
    while u and qb:
        ans.append((u.pop(), qb.pop()))
    while v and qa:
        ans.append((qa.pop(), v.pop()))
while qa and qb:
    ans.append((qa.pop(), qb.pop()))

print(len(ans))
print(*('%d %d' % (i + 1, j + 1) for i, j in ans), sep='\n')

import string
def ind(x):
  sample=list(string.ascii_lowercase)
  if x=="?":
    return 26
  else:
    return sample.index(x)
def main():
  n=int(input())
  l=input()
  r=input()
  l_arr=[[] for x in range(27)]
  r_arr=[[] for x in range(27)]

  for x in range(n):
    l_arr[ind(l[x])].append(x+1)
    r_arr[ind(r[x])].append(x+1)
  count=0
  pair=[]
  for x in range(26):
    while len(l_arr[x])!=0 and len(r_arr[x])!=0:
      pair.append((l_arr[x][-1],r_arr[x][-1]))
      del l_arr[x][-1]
      del r_arr[x][-1]
      count+=1
  for x in range(26):
    while len(l_arr[-1])!=0 and len(r_arr[x])!=0:
      pair.append((l_arr[-1][-1],r_arr[x][-1]))
      del l_arr[-1][-1]
      del r_arr[x][-1]
      count+=1
  for x in range(26):
    while len(l_arr[x])!=0 and len(r_arr[-1])!=0:
      pair.append((l_arr[x][-1],r_arr[-1][-1]))
      del l_arr[x][-1]
      del r_arr[-1][-1]
      count+=1
  for x in range(26):
    while len(l_arr[-1])!=0 and len(r_arr[-1])!=0:
      pair.append((l_arr[-1][-1],r_arr[-1][-1]))
      del l_arr[-1][-1]
      del r_arr[-1][-1]
      count+=1
  print(count)
  for x in range(count):
    print(pair[x][0],end=" ")
    print(pair[x][1])
  
      
main()


n = int(input())
l = input()
r = input()
rr = {'?':[]}
for i in range(n):
    if r[i] in rr:
        rr[r[i]].append(i)
    else:
        rr[r[i]] = [i]
ll = []
for i in range(n):
    if l[i] == '?':
        ll.append(i)
q = []
res = []
for i in range(n):
    c = l[i]
    if c != '?':
        if c in rr and len(rr[c]):
            res.append([i, rr[c].pop()])
        else:
            if len(rr['?']):
                res.append([i, rr['?'].pop()])
for i in rr:
    for j in rr[i]:
        if len(ll):
            res.append([ll.pop(), j])
print(len(res))
for i in res:
    a, b = i
    print(a + 1, b + 1)


n = int(input())

l = input()
r = input()

l = sorted(enumerate(l), key=lambda x: x[1])
l_ = []
lq = []
for pos, c in l:
	if c=="?":
		lq.append(pos)
	else:
		l_.append((pos, c))

r = sorted(enumerate(r), key=lambda x: x[1])
r_ = []
rq = []
for pos, c in r:
	if c=="?":
		rq.append(pos)
	else:
		r_.append((pos, c))


pairs = []
i = j = 0
while i < len(l_) and j < len(r_):
	posl, cl = l_[i]
	posr, cr = r_[j]

	if cl == cr:
		pairs.append((posl, posr))
		i+=1
		j+=1
	elif cl < cr:
		if rq:
			pairs.append((posl, rq.pop(0)))
		i += 1
	else:
		if lq:
			pairs.append((lq.pop(0), posr))
		j += 1

while i < len(l_) and rq:
	posl, cl = l_[i]
	pairs.append((posl, rq.pop(0)))
	i+=1

while j < len(r_) and lq:
	posr, cr = r_[j]
	pairs.append((lq.pop(0), posr))
	j+=1

for posl, posr in zip(lq, rq):
	pairs.append((posl, posr))

print(len(pairs))
for posl, posr in pairs:
	print(posl+1, posr+1)

import sys
from math import *

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

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

n = mint()
l = [[] for i in range(27)]
r = [[] for i in range(27)]
s = minp()
for i in range(n):
	if s[i] == '?':
		l[26].append(i)
	else:
		l[ord(s[i])-ord('a')].append(i)
s = minp()
for i in range(n):
	if s[i] == '?':
		r[26].append(i)
	else:
		r[ord(s[i])-ord('a')].append(i)
res = [0]*n
rp = 0
best = 0
for i in range(26):
	for j in range(min(len(l[i]),len(r[i]))):
		res[rp] = (l[i].pop()+1, r[i].pop()+1)
		rp += 1
		best += 1
for i in range(26):
	while len(l[i]) > 0 and len(r[26]) > 0:
		res[rp] = (l[i].pop()+1, r[26].pop()+1)
		rp += 1
		best += 1
for i in range(26):
	while len(r[i]) > 0 and len(l[26]) > 0:
		res[rp] = (l[26].pop()+1, r[i].pop()+1)
		rp += 1
		best += 1
i = 0
j = 0
while i < 27 or j < 27:
	if i < 27 and len(l[i]) == 0:
		i += 1
	elif j < 27 and len(r[j]) == 0:
		j += 1
	else:
		if i == j or i == 26 or j == 26:
			best += 1
			res[rp] = (l[i].pop()+1, r[j].pop()+1)
			rp += 1
		else:
			l[i].pop()+1
			r[j].pop()+1
print(best)
for i in range(rp):
	print(*res[i])


n=int(input())
l=input()
r=input()

l2=[[l[i],i+1] for i in range(n)]
r2=[[r[i],i+1] for i in range(n)]

l2.sort(reverse=True)
r2.sort(reverse=True)

l_i=0
r_i=0

ANS=[]

check_l=[0]*n
check_r=[0]*n
while l_i<n and r_i<n and l2[l_i][0]!="?" and r2[r_i][0]!="?":
    if l2[l_i][0]==r2[r_i][0]:
        ANS.append([l2[l_i][1],r2[r_i][1]])
        check_l[l_i]=1
        check_r[r_i]=1
        l_i+=1
        r_i+=1
    elif l2[l_i][0]>r2[r_i][0]:
        l_i+=1
    elif l2[l_i][0]<r2[r_i][0]:
        r_i+=1

j=0    
for i in range(n-1,-1,-1):
    if l2[i][0]!="?":
        break
    if check_l[i]==1:
        continue
    while check_r[j]==1:
        j+=1
    ANS.append([l2[i][1],r2[j][1]])
    check_l[i]=1
    check_r[j]=1

j=0    
for i in range(n-1,-1,-1):
    if r2[i][0]!="?":
        break
    if check_r[i]==1:
        continue
    while check_l[j]==1:
        j+=1
    ANS.append([l2[j][1],r2[i][1]])
    check_l[j]=1
    check_r[i]=1

print(len(ANS))
for ans in ANS:
    print(*ans)
    


n = int(input())
l = input().strip()
r = input().strip()

cntl = [[] for x in range(27)]
cntr = [[] for x in range(27)]

for i in range(n):
  if l[i] == '?':
    cntl[26].append(i)
  else:
    cntl[ord(l[i])-ord('a')].append(i)

for i in range(n):
  if r[i] == '?':
    cntr[26].append(i)
  else:
    cntr[ord(r[i])-ord('a')].append(i)

ovrL = []
ovrR = []
r = []

for i in range(26):
  to = min(len(cntl[i]), len(cntr[i]))
  for j in range(min(len(cntl[i]), len(cntr[i]))):
    r.append((cntl[i][j], cntr[i][j]))
  ovrL[len(ovrL):] = cntl[i][to:]
  ovrR[len(ovrR):] = cntr[i][to:]

for i in range(min(len(ovrL), len(cntr[26]))):
  r.append((ovrL[i], cntr[26].pop()))

for i in range(min(len(ovrR), len(cntl[26]))):
  r.append((cntl[26].pop(), ovrR[i]))

for i in range(min(len(cntl[26]), len(cntr[26]))):
  r.append((cntl[26][i], cntr[26][i]))

r = [str(a+1) + " " + str(b+1) for a,b in r]
print(len(r))
print("\n".join(r))


n = int(input())
s = input()
t = input()
letter_index_s = {}
letter_index_t = {}
base_s = set()
base_t = set()
for i in set(s):
    letter_index_s[i] = set()
for i in set(t):
    letter_index_t[i] = set()
ans = []
for i in range(n):
    if s[i] != '?':
        letter_index_s[s[i]].add(i + 1)
    else:
        base_s.add(i + 1)
    if t[i] != '?':
        letter_index_t[t[i]].add(i + 1)
    else:
        base_t.add(i + 1)
for i in letter_index_s:
    if i in letter_index_t:
        while len(letter_index_s[i]) and len(letter_index_t[i]):
            z1 = letter_index_s[i].pop()
            z2 = letter_index_t[i].pop()
            ans.append((z1, z2))
for i in letter_index_s:
    for z in letter_index_s[i]:
        if base_t != set():
            ans.append((z, base_t.pop()))
        else:
            break
for i in letter_index_t:
    for z in letter_index_t[i]:
        if base_s != set():
            ans.append((base_s.pop(), z))
        else:
            break
for a in base_s:
    if base_t != set():
        ans.append((a, base_t.pop()))
    else:
        break
print(len(ans))
for i in ans:
    print(i[0], i[1])

# alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 998244353 
INF = 100_000_000
# from heapq import heappush, heappop
from collections import defaultdict
t = 1#int(input())
# from math import sqrt


for test in range(t):
    n = int(input())
    # n,m = (map(int, input().split()))
    # a = []
    # for i in range(n):
    l = input()
    r = input()
    # q = (list((map(int, input().split()))))
    L = defaultdict(list)
    usedL = [False for i in range(n)]
    usedR = [False for i in range(n)]

    quesL = []
    quesR = []
    for i in range(n):
        if l[i]=="?":
            quesL.append(i)
            usedL[i] = True
        else:
            L[l[i]].append(i)

    ans = []
    for i in range(n):
        if r[i]=="?":
            quesR.append(i)
            usedR[i] = True
        else:
            if len(L[r[i]])>0:
                tmp = L[r[i]].pop()
                ans.append((tmp+1, i+1))
                usedL[tmp] = True
                usedR[i] = True

    usedL2 = []
    usedR2 = []
    for i in range(n):
        if not usedL[i]:
            usedL2.append(i)
        if not usedR[i]:
            usedR2.append(i)

    while len(quesL)>0 and len(usedR2)>0:
        ans.append((quesL.pop()+1, usedR2.pop()+1))
    
    while len(quesR)>0 and len(usedL2)>0:
        ans.append((usedL2.pop()+1, quesR.pop()+1))

    while len(quesL)>0 and len(quesR)>0:
        ans.append((quesL.pop()+1, quesR.pop()+1))
    
    print(len(ans))
    for i in ans:
        print(i[0], i[1])

from collections import defaultdict
n = int(input())
s = input()
t = input()
col1 = defaultdict(list)
col2 = defaultdict(list)
any1 = []
any2 = []
a = ord('a')
for i in range(n):
    if s[i] == '?':
        any1 .append(i)
    else:
        col1[ord(s[i]) - a].append(i)

for i in range(n):
    if t[i] == '?':
        any2 .append(i)
    else:
        col2[ord(t[i]) - a].append(i)

rec = []
mo1 = []
mo2 = []
for i in range(26):
    for j in range(max(len(col1[i]), len(col2[i]))):
        if j < min(len(col1[i]), len(col2[i])):
            rec.append((col1[i][j], col2[i][j]))
        else:
            if len(col1[i]) > len(col2[i]):
                mo1.append(col1[i][j])
            else:
                mo2.append(col2[i][j])

while len(mo1) > 0 and len(any2) > 0:
    a, b = mo1.pop(), any2.pop()
    rec.append((a, b))

while len(mo2) > 0 and len(any1) > 0:
    a, b = any1.pop(), mo2.pop()
    rec.append((a, b))

for i in range(min(len(any1), len(any2))):
    rec.append((any1[i], any2[i]))

print(len(rec))
for i, j in rec:
    print(i + 1, j + 1)

n = int(input())
l = input()
r = input()
li = [0] * 27
li2 = [[] for i in range(27)]
ri = [0] * 27
ri2 = [[] for i in range(27)]
alth = "qwertyuiopasdfghjklzxcvbnm?"
for i in range(n):
    i1 = alth.find(l[i])
    i2 = alth.find(r[i])
    li[i1] += 1
    ri[i2] += 1
    li2[i1] += [i]
    ri2[i2] += [i]
    
for i in range(27):
    li2[i] += [len(li2[i]) - 1]
    ri2[i] += [len(ri2[i]) - 1]

ans = [0] * n
num = 0
for i in range(26):
    while li2[i][-1] > -1 and ri2[i][-1] > -1:
        ans[num] = [li2[i][li2[i][-1]],ri2[i][ri2[i][-1]]]
        num += 1
        li2[i][-1] -= 1
        ri2[i][-1] -= 1
        
for i in range(26):
    while li2[i][-1] > -1 and ri2[-1][-1] > -1:
        ans[num] = [li2[i][li2[i][-1]],ri2[-1][ri2[-1][-1]]]
        num += 1
        li2[i][-1] -= 1
        ri2[-1][-1] -= 1

for i in range(26):
    while li2[-1][-1] > -1 and ri2[i][-1] > -1:
        ans[num] = [li2[-1][li2[-1][-1]],ri2[i][ri2[i][-1]]]
        num += 1
        li2[-1][-1] -= 1
        ri2[i][-1] -= 1
while li2[-1][-1] > -1 and ri2[-1][-1] > -1:
        ans[num] = [li2[-1][li2[-1][-1]],ri2[-1][ri2[-1][-1]]]
        num += 1
        li2[-1][-1] -= 1
        ri2[-1][-1] -= 1
print(num)
for i in range(num):
    print(ans[i][0] + 1, ans[i][1] + 1)


n = int(input())

left = [[] for _ in range(27)]
right = [[] for _ in range(27)]

for i, c in enumerate(input().strip()):
    if c == '?':
        left[26].append(i + 1)
    else:
        left[ord(c) - ord('a')].append(i + 1)
for i, c in enumerate(input().strip()):
    if c == '?':
        right[26].append(i + 1)
    else:
        right[ord(c) - ord('a')].append(i + 1)

result = []
for i in range(26):
    count = min(len(left[i]), len(right[i]))
    for j in range(count):
        result.append((left[i][j], right[i][j]))

i = 0
left_q = 0
while True:
    if left_q == len(left[26]) or i == 26:
        break
    for j in range(len(left[i]), len(right[i])):
        result.append((left[26][left_q], right[i][j]))
        left_q += 1
        if left_q == len(left[26]):
            break
    i += 1

i = 0
right_q = 0
while True:
    if right_q == len(right[26]) or i == 26:
        break
    for j in range(len(right[i]), len(left[i])):
        result.append((left[i][j], right[26][right_q]))
        right_q += 1
        if right_q == len(right[26]):
            break
    i += 1

while left_q < len(left[26]) and right_q < len(right[26]):
    result.append((left[26][left_q], right[26][right_q]))
    left_q += 1
    right_q += 1

print(len(result))
for i, j in result:
    print(i, j)


''' CODED WITH LOVE BY SATYAM KUMAR '''

from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27)  # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys

class merge_find:
    def __init__(self,n):
        self.parent = list(range(n))
        self.size = [1]*n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]
    def find(self,a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]
    def merge(self,a,b):
        a = self.find(a)
        b = self.find(b)
        if a==b:
            return
        if self.size[a]<self.size[b]:
            a,b = b,a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
    def set_size(self, a):
        return self.size[self.find(a)]
    def __len__(self):
        return self.num_sets

def display(string_to_print):
    stdout.write(str(string_to_print) + "\n")

def primeFactors(n): #n**0.5 complex 
    factors = dict()
    for i in range(2,math.ceil(math.sqrt(n))+1):  
        while n % i== 0: 
            if i in factors:
                factors[i]+=1
            else: factors[i]=1
            n = n // i 
    if n>2:
        factors[n]=1
    return (factors)

def fibonacci_modP(n,MOD):
    if n<2: return 1
    #print (n,MOD)
    return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n , p): 
    if (p <= n): 
        return 0
    res = (p - 1) 
    for i in range (n + 1, p): 
        res = (res * cached_fn(InverseEuler,i, p)) % p 
    return res 

def binary(n,digits = 20):
    b = bin(n)[2:]
    b = '0'*(20-len(b))+b
    return b

def isprime(n):
    """Returns True if n is prime."""
    if n < 4:
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True
factorial_modP = []
def warm_up_fac(MOD):
    nonlocal factorial_modP,fac_warmup
    if fac_warmup: return
    factorial_modP= [1 for _ in range(fac_warmup_size+1)]
    for i in range(2,fac_warmup_size):
        factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
    fac_warmup = True

def InverseEuler(n,MOD):
    return pow(n,MOD-2,MOD)

def nCr(n, r, MOD):
    nonlocal fac_warmup,factorial_modP
    if not fac_warmup:
        warm_up_fac(MOD)
        fac_warmup = True
    return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD

def test_print(*args):
    if testingMode:
        print(args)

def display_list(list1, sep=" "):
    stdout.write(sep.join(map(str, list1)) + "\n")

def display_2D_list(li):
    for i in li:
        print(i)

def get_int():
    return int(stdin.readline().strip())

def get_tuple():
    return map(int, stdin.readline().split())

def get_list():
    return list(map(int, stdin.readline().split()))
import heapq,itertools
pq = []                         # list of entries arranged in a heap
entry_finder = {}               # mapping of tasks to entries
REMOVED = '<removed-task>' 
def add_task(task, priority=0):
    'Add a new task or update the priority of an existing task'
    if task in entry_finder:
        remove_task(task)
    count = next(counter)
    entry = [priority, count, task]
    entry_finder[task] = entry
    heapq.heappush(pq, entry)

def remove_task(task):
    'Mark an existing task as REMOVED.  Raise KeyError if not found.'
    entry = entry_finder.pop(task)
    entry[-1] = REMOVED

def pop_task():
    'Remove and return the lowest priority task. Raise KeyError if empty.'
    while pq:
        priority, count, task = heapq.heappop(pq)
        if task is not REMOVED:
            del entry_finder[task]
            return task
    raise KeyError('pop from an empty priority queue')
memory = dict()
def clear_cache():
    nonlocal memory
    memory = dict()
def cached_fn(fn, *args):
    nonlocal memory
    if args in memory:
        return memory[args]
    else:
        result = fn(*args)
        memory[args] = result
        return result

def ncr (n,r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
def binary_serach(i,li):
    #print("Search for ",i)
    fn = lambda x: li[x]-x//i
    x = -1
    b = len(li)
    while b>=1:
        #print(b,x)
        while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like
            x+=b
        b=b//2
    return x

# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = True #Can not be used clubbed with TestCases
from math import factorial

def main():
    n = get_int()
    s1 = list(input())
    s2 = list(input())
    li = [[] for _ in range(27)]
    lj=[[] for _ in range(27)]
    for index,i in enumerate(s1):
        if i=='?':
            li[0].append(index)
        else:
            li[ord(i)-ord('a')+1].append(index)
    for index,i in enumerate(s2):
        if i=='?':
            lj[0].append(index)
        else:
            lj[ord(i)-ord('a')+1].append(index)
    #display_2D_list(li)
    #display_2D_list(lj)
    res = []
    for i in range(1,27):
        while len(li[i])>0 and len(lj[i])>0:
            #print(li[i],lj[i],i)
            res.append([li[i].pop()+1,lj[i].pop()+1])
        if len(li[i])>0:
            while len(li[i])>0 and len(lj[0])>0:
               res.append([li[i].pop()+1,lj[0].pop()+1]) 
        elif len(lj[i])>0:
            while len(lj[i])>0 and len(li[0])>0:
               res.append([li[0].pop()+1,lj[i].pop()+1])
    while len(li[0])>0 and len(lj[0])>0:
        res.append([li[0].pop()+1,lj[0].pop()+1])
    print(len(res))
    for li in res:
        display_list(li)

         




# --------------------------------------------------------------------- END=


if TestCases: 
    for _ in range(get_int()): 
        cProfile.run('main()') if testingMode else main() 
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()

n = int(input())

l = [x for x in input()]
r = [x for x in input()]
L = {}
R = {}

for i, e in enumerate(l):
    i += 1
    if e in L:
        L[e].append(i)
    else:
        L[e] = [i]

for i, e in enumerate(r):
    i += 1
    if e in R:
        R[e].append(i)
    else:
        R[e] = [i]



res = []

q = '?'

for e in L:
    if e == q:
        continue

    if e in R:
        while len(R[e]) and len(L[e]):
            res.append((L[e].pop(), R[e].pop()))


if q in L:
    for e in R:
        if e == q:
            continue
        while L[q] and R[e]:
            res.append((L[q].pop(), R[e].pop()))

if q in R:
    for e in L:
        while L[e] and R[q]:
            res.append((L[e].pop(), R[q].pop()))


print(len(res))
for e in res:
    print(*e)


n = int(input())
s1 = input()
s2 = input()
a1 = [0 for i in range(26)]
b1 = [[] for i in range(26)]
a2 = [0 for i in range(26)]
b2 = [[] for i in range(26)]
v1 = []
v2 = []
cntv1 = 0
for i in range(n):
    if s1[i] == '?':
        cntv1 += 1
        v1.append(i)
    else:
        a1[ord(s1[i]) - 97] += 1
        b1[ord(s1[i]) - 97].append(i)
cntv2 = 0
for i in range(n):
    if s2[i] == '?':
        cntv2 += 1
        v2.append(i)
    else:
        a2[ord(s2[i]) - 97] += 1
        b2[ord(s2[i]) - 97].append(i)
cnt = 0
c = []

for i in range(26):
    while a1[i] > 0 and a2[i] > 0:
        cnt += 1
        a1[i] -= 1
        a2[i] -= 1
        c.append([b1[i].pop() + 1, b2[i].pop() + 1])
for i in range(26):
    while a1[i] > 0 and cntv2 > 0:
        cntv2 -= 1
        a1[i] -= 1
        cnt += 1
        c.append([b1[i].pop() + 1, v2.pop() + 1])
for i in range(26):
    while a2[i] > 0 and cntv1 > 0:
        cntv1 -= 1
        a2[i] -= 1
        cnt += 1
        c.append([v1.pop() + 1, b2[i].pop() + 1])
if cntv2 != 0 and cntv1 != 0:
    while cntv2 > 0 and cntv1 > 0:
        cnt += 1
        cntv1 -= 1
        cntv2 -= 1
        c.append([v1.pop() + 1, v2.pop() + 1])
print(cnt)
for i in range(len(c)):
    print(*c[i])


l = int(input())
le = input().strip()
ri = input().strip()
la = list(sorted(((y, x) for x, y in enumerate(le)), reverse=True))
lb = list(sorted(((y, x) for x, y in enumerate(ri)), reverse=True))
# print(la)
# print(lb)
i,j = 0,0
res = 0
resp = []
ui, ul = l-1, l-1
while i<=ui and j<=ul:
	ai, aa = la[i]
	bi, bb = lb[j]
	# print(ai, bi, i, j)
	if ai == bi or ai == '?' or bi == '?':
		resp.append("{} {}".format(aa+1, bb+1))
		i+=1
		j+=1
	elif ai > bi:
		i+=1
		if lb[ul][0] == '?':
			resp.append("{} {}".format(aa+1, lb[ul][1]+1))
			ul -= 1
	else:
		j+=1
		if la[ui][0] == '?':
			resp.append("{} {}".format(la[ui][1]+1, bb+1))
			ui -= 1

print(len(resp))
for r in resp:
	print(r)


import string


n = int(input())

l = input()
r = input()
lefts = [[] for _ in range(256)]
rights = [[] for _ in range(256)]

oq = ord('?')

pairs = []

for i in range(n):
    lefts[ord(l[i])].append(i+1)
    rights[ord(r[i])].append(i+1)

q_store = [lefts[oq], rights[oq]]
q_used = [0, 0]
for c in string.ascii_lowercase:
    oc = ord(c)
    same_pairs = min(len(lefts[oc]), len(rights[oc]))
    for i in range(same_pairs):
        pairs.append((lefts[oc][i], rights[oc][i]))

    if same_pairs == len(rights[oc]):
        extras = lefts[oc]
        q_idx = 1
    else:
        extras = rights[oc]
        q_idx = 0

    for i in range(same_pairs, len(extras)):
        if q_used[q_idx] >= len(q_store[q_idx]):
            break
        if q_idx == 0:
            pairs.append((q_store[q_idx][q_used[q_idx]], extras[i]))
        else:
            pairs.append((extras[i], q_store[q_idx][q_used[q_idx]]))
        q_used[q_idx] += 1

while q_used[0] < len(q_store[0]) and q_used[1] < len(q_store[1]):
    pairs.append((q_store[0][q_used[0]], q_store[1][q_used[1]]))
    q_used[0] += 1
    q_used[1] += 1

print(len(pairs))
for pair in pairs:
    print(*pair)


from collections import deque
n = int(input())
l = input()
r = input()
a = [0 for i in range(0,ord('z')+1)]
b = [0 for i in range(0,ord('z')+1)]
c = [deque() for i in range(0,ord('z')+1)]
d = [deque() for i in range(0,ord('z')+1)]
for i in range(len(l)):
	if l[i]=='?':
		a[0]+=1
		c[0].append(i+1)
	else:
		a[ord(l[i])]+=1
		c[ord(l[i])].append(i+1)
for i in range(len(l)):
	if r[i]=='?':
		b[0]+=1
		d[0].append(i+1)
	else:
		b[ord(r[i])]+=1
		d[ord(r[i])].append(i+1)
vopra = a[0]
voprb = b[0]
sch = 0
out = []
for i in range(1,len(a)):
	sch+=min(a[i],b[i])
	sch+=min(voprb,a[i]-min(a[i],b[i]))
	for j in range(min(a[i],b[i])):
		if min(a[i],b[i])>0:
			out.append([c[i].popleft(),d[i].popleft()])
	for j in range(min(voprb,a[i]-min(a[i],b[i]))):
		if (min(voprb,a[i]-min(a[i],b[i])))>0:
			out.append([c[i].popleft(),d[0].popleft()])
	voprb-=min(voprb,a[i]-min(a[i],b[i]))
	sch+=min(vopra,b[i]-min(a[i],b[i]))
	for j in range(min(vopra,b[i]-min(a[i],b[i]))):
		if (min(vopra,b[i]-min(a[i],b[i])))>0:
			out.append([c[0].popleft(),d[i].popleft()])
	vopra-=min(vopra,b[i]-min(a[i],b[i]))
	
if vopra>0 and voprb>0:
	sch+=min(vopra,voprb)
	for j in range(min(vopra,voprb)):
		if min(vopra,voprb)>0:
			out.append([c[0].popleft(),d[0].popleft()])
print(sch)
for i in out:
	print(*i)

	

	


n = int(input())
a = list(input())
b = list(input())
l = dict()
r = dict()
for i in range(n):
    if a[i] in l:
        l[a[i]].append(i + 1)
    else:
        l[a[i]] = [i + 1]

    if b[i] in r:
        r[b[i]].append(i + 1)
    else:
        r[b[i]] = [i + 1]

# print(l)
# print(r)

ans = []
for i in list(l.keys()):
    if i in r and i != '?':
        for j in range(min(len(l[i]), len(r[i]))):
            ans.append(str(l[i].pop()) + ' ' + str(r[i].pop()))

p1 = []
for i in list(l.keys()):
    if i != '?':
        for el in l[i]:
            p1.append(el)
p2 = []
for i in list(r.keys()):
    if i != '?':
        for el in r[i]:
            p2.append(el)

if '?' in l:
    for i in range(min(len(p2), len(l['?']))):
        ans.append(str(l['?'].pop()) + ' ' + str(p2.pop()))
if '?' in r:
    for i in range(min(len(p1), len(r['?']))):
        ans.append(str(p1.pop()) + ' ' + str(r['?'].pop()))
if '?' in r and '?' in l:
    for i in range(min(len(l['?']), len(r['?']))):
        ans.append(str(l['?'].pop()) + ' ' + str(r['?'].pop()))

print(len(ans))
print('\n'.join(ans))


n = int(input())
l = input()
r = input()
lc = [[] for i in range(27)]
rc = [[] for i in range(27)]
x = 0
for i in l:
    if i == '?':
        lc[26].append(x)
    else:
        lc[ord(i) - 97].append(x)
    x += 1
x = 0
for i in r:
    if i == '?':
        rc[26].append(x)
    else:
        rc[ord(i) - 97].append(x)
    x += 1
ans = []
ql = []
qr = []
for i in range(26):
    if len(lc[i]) > len(rc[i]):
        for t in range(len(lc[i]) - len(rc[i])):
            ql.append(lc[i].pop())
    else:
        for t in range(len(rc[i]) - len(lc[i])):
            qr.append(rc[i].pop())
    for j in range(len(lc[i])):
        ans.append([lc[i].pop(), rc[i].pop()])
for i in range(min(len(ql), len(rc[26]))):
    ans.append([ql.pop(), rc[26].pop()])
for i in range(min(len(qr), len(lc[26]))):
    ans.append([lc[26].pop(), qr.pop()])
for i in range(min(len(lc[26]), len(rc[26]))):
    ans.append([lc[26].pop(), rc[26].pop()])
print(len(ans))
for i in ans:
    print(i[0] + 1, i[1] + 1)


"""
NTC here
"""
from sys import setcheckinterval,stdin
setcheckinterval(1000)

from collections import defaultdict

iin=lambda :int(stdin.readline())
lin=lambda :list(map(int,stdin.readline().split()))

n=iin()
a=input()
b=input()
l=defaultdict(list)
cntl=defaultdict(int)
for i in range(n):
    l[a[i]].append(i+1)
cl=len(l['?'])
left=defaultdict(list)
ans=[]
for i in range(n):
    if b[i]=='?':left['?'].append(i+1);continue
    if b[i] in l:
        if l[b[i]]:
            ans.append((l[b[i]].pop(),i+1))
        else:
            left[b[i]].append(i+1)
    else:
        left[b[i]].append(i+1)
cr=len(left['?'])
if cl!=0:
    for i in left:
        if i=='?':continue
        if cl<=0:break
        while left[i] and cl>0:
            ans.append((l['?'].pop(),left[i].pop()))
            cl-=1
if cr!=0:
    for i in l:
        if l[i]:
            while l[i] and cr>0:
                ans.append((l[i].pop(),left['?'].pop()))
                cr-=1
print(len(ans))
for i,j in ans:
    print(i,j)




n=int(input())
l=list(input())
r=list(input())
la=[[] for i in range(26)]
ra=[[] for i in range(26)]
ir=[]
il=[]
for i in range(n):
    if l[i]!='?':
        la[ord(l[i])-ord('a')].append(i)
    else:
        il.append(i)
for i in range(n):
    if r[i]!='?':
        ra[ord(r[i])-ord('a')].append(i)
    else:
        ir.append(i)
ans=[]
for i in range(26):
    while len(la[i])>0 and len(ra[i])>0:
        x,y=la[i].pop(),ra[i].pop()
        ans.append([x+1,y+1])
for i in range(26):
    while len(ir)>0 and len(la[i])>0:
        x,y=la[i].pop(),ir.pop()
        ans.append([x+1,y+1])
for i in range(26):
    while len(il)>0 and len(ra[i])>0:
        x,y=il.pop(),ra[i].pop()
        ans.append([x+1,y+1])
while len(il)>0 and len(ir)>0:
    x,y=il.pop(),ir.pop()
    ans.append([x+1,y+1])
print(len(ans))
for i in ans:
    print(*i)

n = int(input())
a = list(input())
b = list(input())

cnt_a = 0
cnt_b = 0
for i in range(n):
    if a[i] != "?":
        a[i] = [ord(a[i]), i + 1]
    else:
        a[i] = [1000, i + 1]
        cnt_a += 1
    if b[i] != "?":
        b[i] = [ord(b[i]), i + 1]
    else:
        b[i] = [1000, i + 1]
        cnt_b += 1

a.sort()
b.sort()
ans = 0
# print(a)
# print(b)

j = 0
i = 0
used_a = [0] * n
used_b = [0] * n
ans_m = []
while i < n and j < n:
    if a[i][0] == b[j][0] and a[i][0] != 1000 and used_a[i] == 0 and used_b[j] == 0:
        ans_m.append([a[i][1], b[j][1]])
        used_a[i] = 1
        used_b[j] = 1
        ans += 1
        j += 1
        i += 1
    elif a[i][0] > b[j][0]:
        j += 1
    else:
        i += 1

# print(used_a, used_b)

# print(a)
# print(b)
print(min(n, ans + cnt_a + cnt_b))
for q in range(ans):
    print(ans_m[q][0], ans_m[q][1])
j = 0

for i in range(n):
    if a[i][0] == 1000 and used_a[i] == 0:
        while used_b[j] == 1 and j < n:
            j += 1
            if j == n:
                break
        if j == n:
            break
        if used_b[j] == 0 and used_a[i] == 0:
            print(a[i][1], b[j][1])
            used_a[i] = 1
            used_b[j] = 1

j = 0
# print(used_a)
# print(used_b)
for i in range(n):
    if b[i][0] == 1000 and used_b[i] == 0:
        while used_a[j] == 1 and j < n:
            j += 1
            if j == n:
                break
        if j == n:
            break
        if used_a[j] == 0 and used_b[i] == 0:
            print(a[j][1], b[i][1])
            used_a[j] = 1
            used_b[i] = 1


n = int(input())
l = input()
r = input()

s = "abcdefghijklmnopqrstuvwxyz"

d1 = {}
d2 = {}

for c in s:
    d1[c] = []
    d2[c] = []

d1['?'] = []
d2['?'] = []

for i in range(n):
    d1[l[i]].append(i)
    d2[r[i]].append(i)

ansleft = []
ansright = []

checkedleft = [0 for i in range(n)]
checkedright = [0 for j in range(n)]


for j in range(26):
    let = s[j]

    l1 = list(d1[let])
    l2 = list(d2[let])

    c1 = len(l1)
    c2 = len(l2)

    cnt = min(c1,c2)

    i = 0
    while(i < cnt):
        ansleft.append(l1[i])
        ansright.append(l2[i])
        checkedright[l2[i]] = 1
        checkedleft[l1[i]] = 1
        i+=1


nonques1 = []
nonques2 = []
ques1 = list(d1['?'])
ques2 = list(d2['?'])

for i in range(n):
    if l[i] != '?' and checkedleft[i] == 0:
        nonques1.append(i)
    if r[i] != '?' and checkedright[i] == 0:
        nonques2.append(i)

j = 0
k = 0
for i in range(len(ques1)):
    if(ques1[i] != -1):
        if(j < len(nonques2)):
            ansleft.append(ques1[i])
            ansright.append(nonques2[j])
            nonques2[j] = -1
            j+=1
            ques1[i] = -1
        elif(k < len(ques2)):
            ansleft.append(ques1[i])
            ansright.append(ques2[k])
            ques2[k] = -1
            k+=1
            ques1[i] = -1

j = 0
k = 0
for i in range(len(ques2)):
    if(ques2[i] != -1):
        if(j < len(nonques1)):
            ansright.append(ques2[i])
            ansleft.append(nonques1[j])
            nonques1[j] = -1
            j+=1
            ques2[i] = -1
        elif(k < len(ques1)):
            ansright.append(ques2[i])
            ansleft.append(ques1[k])
            ques1[k] = -1
            k+=1
            ques2[i] = -1

print(len(ansleft))
for i in range(len(ansleft)):
    print(ansleft[i]+1,ansright[i]+1)

def main():
  n = int(input())
  l = input().strip()
  r = input().strip()
  pairs = solve(n, l, r)
  print(len(pairs))
  print("\n".join(" ".join(str(xx) for xx in x) for x in pairs))

def solve(n, l, r):
  from collections import deque
  answer = deque()

  l_enum_by_color = count([x for x in enumerate(l)])
  r_enum_by_color = count([x for x in enumerate(r)])

  l_q_list = l_enum_by_color.pop("?") if "?" in l_enum_by_color else deque()
  r_q_list = r_enum_by_color.pop("?") if "?" in r_enum_by_color else deque()

  for key in l_enum_by_color:
    if key not in r_enum_by_color:
      continue
    to_take_count = min(len(l_enum_by_color[key]), len(r_enum_by_color[key]))
    for _ in range(to_take_count):
      answer.append((l_enum_by_color[key].popleft(), r_enum_by_color[key].popleft()))

  for key in l_enum_by_color:
    if len(l_enum_by_color[key]) == 0:
      continue
    to_take_count = min(len(l_enum_by_color[key]), len(r_q_list))
    for _ in range(to_take_count):
      answer.append((l_enum_by_color[key].popleft(), r_q_list.popleft()))

  for key in r_enum_by_color:
    if len(r_enum_by_color[key]) == 0:
      continue
    to_take_count = min(len(r_enum_by_color[key]), len(l_q_list))
    for _ in range(to_take_count):
      answer.append((l_q_list.popleft(), r_enum_by_color[key].popleft()))

  for _ in range(min(len(l_q_list), len(r_q_list))):
    answer.append((l_q_list.popleft(), r_q_list.popleft()))

  return answer

def count(it):
  from collections import deque
  d = {}
  for a in it:
    if a[1] in d:
      d[a[1]].append(a[0]+1)
    else:
      d[a[1]] = deque([a[0]+1])
  return d


main()