import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_q = new ArrayList<>();
        ArrayList<Integer> r_q = new ArrayList<>();
        ArrayList<Pair> l_u = new ArrayList<>();
        ArrayList<Pair> r_u = new ArrayList<>();
        ArrayList<Pair> l = new ArrayList<>();
        ArrayList<Pair> r = new ArrayList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        while (l.size() > 0 && r.size() > 0) {

            if(r.size() == 0 || l.get(0).key < r.get(0).key){
                if(r_q.size() > 0) res.put(l.remove(0).value, r_q.remove(0));
                else l_u.add(l.remove(0));
            } else if(l.get(0).key == r.get(0).key){
                res.put(l.remove(0).value, r.remove(0).value);
            } else {
                if(l_q.size() > 0) res.put(l_q.remove(0), r.remove(0).value);
                else r_u.add(r.remove(0));
            }
        }

        while (l_q.size() > 0 && r.size() > 0) {
            res.put(l_q.remove(0), r.remove(0).value);
        }

        while(l.size() > 0 && r_q.size() > 0){
            res.put(l.remove(0).value, r_q.remove(0));
        }

        while (l_q.size() > 0 && r_q.size() > 0){
            res.put(l_q.remove(0), r_q.remove(0));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.println(i);
            System.out.println(res.get(i));
        }
    }
}


import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        LinkedList<Integer> l_q = new LinkedList<>();
        LinkedList<Integer> r_q = new LinkedList<>();
        LinkedList<Pair> l = new LinkedList<>();
        LinkedList<Pair> r = new LinkedList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        while (l.size() > 0 && r.size() > 0) {

            if(l.get(0).key < r.get(0).key){
                if(r_q.size() > 0) res.put(l.remove(0).value, r_q.remove(0));
                else l.remove(0);
            } else if(l.get(0).key == r.get(0).key){
                res.put(l.remove(0).value, r.remove(0).value);
            } else {
                if(l_q.size() > 0) res.put(l_q.remove(0), r.remove(0).value);
                else r.remove(0);
            }
        }

        while (l_q.size() > 0 && r.size() > 0) {
            res.put(l_q.remove(0), r.remove(0).value);
        }

        while(l.size() > 0 && r_q.size() > 0){
            res.put(l.remove(0).value, r_q.remove(0));
        }

        while (l_q.size() > 0 && r_q.size() > 0){
            res.put(l_q.remove(0), r_q.remove(0));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.println(i);
            System.out.println(res.get(i));
        }
    }
}


import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_q = new ArrayList<>();
        ArrayList<Integer> r_q = new ArrayList<>();
        ArrayList<Pair> l = new ArrayList<>();
        ArrayList<Pair> r = new ArrayList<>();

        int numres = 0;
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        int il = 0;
        int ilq = 0;
        int ir = 0;
        int irq = 0;

        while(il < l.size() && ir < r.size()){

            if(l.get(il).key < r.get(ir).key){
                if(irq < r_q.size()) {
                    numres++;
                    sb.append(l.get(il).value);
                    sb.append(" ");
                    sb.append(r_q.get(irq++));
                    sb.append("\n");
                }
                il++;
            } else if (l.get(il).key == r.get(ir).key){
                numres++;
                sb.append(l.get(il++).value);
                sb.append(" ");
                sb.append(r.get(ir++).value);
                sb.append("\n");
            } else {
                if(ilq < l_q.size()) {
                    numres++;
                    sb.append(l_q.get(ilq++));
                    sb.append(" ");
                    sb.append(r.get(ir).value);
                    sb.append("\n");
                }
                ir++;
            }

        }

        while (il < l_q.size() && ir < r.size()) {
            numres++;
            sb.append(l_q.get(ilq++));
            sb.append(" ");
            sb.append(r.get(ir++).value);
            sb.append("\n");
        }

        while(il < l.size() && irq < r_q.size()){
            numres++;
            sb.append(l.get(il++).value);
            sb.append(" ");
            sb.append(r_q.get(irq++));
            sb.append("\n");
        }

        while (ilq < l_q.size() && irq < r_q.size()) {
            numres++;
            sb.append(l_q.get(ilq++));
            sb.append(" ");
            sb.append(r_q.get(irq++));
            sb.append("\n");
        }

        System.out.println(numres);
        System.out.println(sb);
    }
}


import java.util.*;

public class Colored_Boots {

    static StringBuilder sb = new StringBuilder();

    static int numres = 0;
    static void add(int i, int k){
        numres++;
        sb.append(i);
        sb.append(" ");
        sb.append(k);
        sb.append("\n");
    }

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_q = new ArrayList<>();
        ArrayList<Integer> r_q = new ArrayList<>();
        ArrayList<Pair> l = new ArrayList<>();
        ArrayList<Pair> r = new ArrayList<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        int il = 0;
        int ilq = 0;
        int ir = 0;
        int irq = 0;

        while(il < l.size() && ir < r.size()){

            if(l.get(il).key < r.get(ir).key){
                if(irq < r_q.size()) add(l.get(il).value, r_q.get(irq++));
                il++;
            } else if (l.get(il).key == r.get(ir).key) {
                add(l.get(il++).value, r.get(ir++).value);
            } else {
                if(ilq < l_q.size()) add(l_q.get(ilq++), r.get(ir).value);
                ir++;
            }

        }

        while (il < l_q.size() && ir < r.size()) add(l_q.get(ilq++), r.get(ir++).value);

        while(il < l.size() && irq < r_q.size()) add(l.get(il++).value, r_q.get(irq++));

        while (ilq < l_q.size() && irq < r_q.size()) add(l_q.get(ilq++), r_q.get(irq++));

        System.out.println(numres);
        System.out.println(sb);
    }
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Colored_Boots {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        char[] l = scanner.next().toCharArray();
        char[] r = scanner.next().toCharArray();

        ArrayList<Integer> indef = new ArrayList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < l.length; i++) {
            char c = l[i];
            if (c == '?') indef.add(i);

            else {
                for (int k = 0; k < n; k++) {
                    if (r[k] == c) {
                        r[k] = '0';
                        res.put(i, k);
                        break;
                    }
                }
            }
        }

        for (int i = 0; i < r.length; i++) {
            if (indef.size() == 0) break;
            if (r[i] != '0') res.put(indef.remove(0), i);
        }

        System.out.println(res.size());
        for (int i : res.keySet()) System.out.println((i + 1) + " " + (res.get(i) + 1));
    }
}


import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_q = new ArrayList<>();
        ArrayList<Integer> r_q = new ArrayList<>();
        ArrayList<Pair> l_u = new ArrayList<>();
        ArrayList<Pair> r_u = new ArrayList<>();
        ArrayList<Pair> l = new ArrayList<>();
        ArrayList<Pair> r = new ArrayList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        while (l.size() > 0 || r.size() > 0) {

            if(r.size() == 0 || l.get(0).key < r.get(0).key){
                if(r_q.size() > 0) res.put(l.remove(0).value, r_q.remove(0));
                else l_u.add(l.remove(0));
            } else if(l.get(0).key == r.get(0).key){
                res.put(l.remove(0).value, r.remove(0).value);
            } else {
                if(l_q.size() > 0) res.put(l_q.remove(0), r.remove(0).value);
                else r_u.add(r.remove(0));
            }
        }

        while (l_q.size() > 0 && r_q.size() > 0){
            res.put(l_q.remove(0), r_q.remove(0));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.println(i);
            System.out.println(res.get(i));
        }
    }
}


import java.util.*;

public class Colored_Boots {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_indef = new ArrayList<>();
        ArrayList<Integer> r_indef = new ArrayList<>();
        HashMap<Character, ArrayList<Integer>> l = new HashMap<>();
        HashMap<Character, ArrayList<Integer>> r = new HashMap<>();

        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            char cl = tmp_l[i];
            char cr = tmp_r[i];

            if (cl == '?') l_indef.add(i + 1);
            else {
                if (!l.containsKey(tmp_l[i])) l.put(tmp_l[i], new ArrayList<>());
                l.get(tmp_l[i]).add(i + 1);
            }
            if (cr == '?') r_indef.add(i + 1);
            else {
                if (!r.containsKey(tmp_r[i])) r.put(tmp_r[i], new ArrayList<>());
                r.get(tmp_r[i]).add(i + 1);
            }
        }

        for (int i = 0; i < tmp_l.length; i++) {
            char c = tmp_l[i];
            if (c == '?') continue;

            int i_l = l.get(c).remove(0);
            if (r.containsKey(c) && r.get(c).size() > 0) {
                res.put(i_l, r.get(c).remove(0));
                if (r.get(c).size() == 0) res.remove(c);
            } else if (r_indef.size() > 0) {
                res.put(i_l, r_indef.remove(0));
            }
        }

        for (char c : r.keySet()) {
            if (l_indef.size() == 0) break;
            for (int i : r.get(c)) res.put(l_indef.remove(0), i);
        }

        while (r_indef.size() > 0 && l_indef.size() > 0) {
            res.put(l_indef.remove(0), r_indef.remove(0));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.println(i + " " + res.get(i));
        }
    }
}


import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        LinkedList<Integer> l_q = new LinkedList<>();
        LinkedList<Integer> r_q = new LinkedList<>();
        LinkedList<Pair> l_u = new LinkedList<>();
        LinkedList<Pair> r_u = new LinkedList<>();
        LinkedList<Pair> l = new LinkedList<>();
        LinkedList<Pair> r = new LinkedList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        while (l.size() > 0 && r.size() > 0) {

            if(l.get(0).key < r.get(0).key){
                if(r_q.size() > 0) res.put(l.remove(0).value, r_q.remove(0));
                else l_u.add(l.remove(0));
            } else if(l.get(0).key == r.get(0).key){
                res.put(l.remove(0).value, r.remove(0).value);
            } else {
                if(l_q.size() > 0) res.put(l_q.remove(0), r.remove(0).value);
                else r_u.add(r.remove(0));
            }
        }

        while (l_q.size() > 0 && r.size() > 0) {
            res.put(l_q.remove(0), r.remove(0).value);
        }

        while(l.size() > 0 && r_q.size() > 0){
            res.put(l.remove(0).value, r_q.remove(0));
        }

        while (l_q.size() > 0 && r_q.size() > 0){
            res.put(l_q.remove(0), r_q.remove(0));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.println(i);
            System.out.println(res.get(i));
        }
    }
}


import java.util.*;

public class Colored_Boots {

    public static class Pair {
        Character key;
        Integer value;

        public Pair(Character key, Integer value) {
            this.key = key;
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        scanner.nextInt();
        char[] tmp_l = scanner.next().toCharArray();
        char[] tmp_r = scanner.next().toCharArray();

        ArrayList<Integer> l_q = new ArrayList<>();
        ArrayList<Integer> r_q = new ArrayList<>();
        ArrayList<Pair> l = new ArrayList<>();
        ArrayList<Pair> r = new ArrayList<>();
        HashMap<Integer, Integer> res = new HashMap<>();

        for (int i = 0; i < tmp_l.length; i++) {
            if (tmp_l[i] == '?') l_q.add(i + 1);
            else l.add(new Pair(tmp_l[i], i + 1));
            if (tmp_r[i] == '?') r_q.add(i + 1);
            else r.add(new Pair(tmp_r[i], i + 1));
        }

        l.sort(Comparator.comparingInt(x -> x.key));
        r.sort(Comparator.comparingInt(x -> x.key));

        int il = 0;
        int ilq = 0;
        int ir = 0;
        int irq = 0;

        while(il < l.size() && ir < r.size()){

            if(l.get(il).key < r.get(ir).key){
                if(r_q.size() > 0) res.put(l.get(il).value, r_q.get(irq++));
                il++;
            } else if (l.get(il).key == r.get(ir).key){
                res.put(l.get(il++).value, r.get(ir++).value);
            } else {
                if(l_q.size() > 0) res.put(l_q.get(ilq++), r.get(ir).value);
                ir++;
            }

        }

        while (il < l_q.size() && ir < r.size()) {
            res.put(l_q.remove(ilq++), r.remove(ir++).value);
        }

        while(il < l.size() && irq < r_q.size()){
            res.put(l.remove(il++).value, r_q.remove(irq++));
        }

        while (ilq < l_q.size() && irq < r_q.size()){
            res.put(l_q.remove(ilq++), r_q.remove(irq++));
        }

        System.out.println(res.size());
        for (int i : res.keySet()) {
            System.out.print(i+ " ");
            System.out.println(res.get(i));
        }
    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author NamBC
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
//        InputStream inputStream = new FileInputStream("sample-A.2.in");
//        OutputStream outputStream = new FileOutputStream("sample-A.2.ou");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    public static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String a = in.nextLine();
            String b = in.nextLine();
            boolean[] matchA = new boolean[n];
            boolean[] matchB = new boolean[n];
            for (int i = 0; i < n; i++) {
                matchA[i] = false;
                matchB[i] = false;
            }
            Map<Integer, Integer> sol = new HashMap<>();
            int qma = 0, qmb = 0;
            for (int i = 0; i < n; i++) {
                char ai = a.charAt(i);
                qmb = -1;
                if (ai == '?') {
                    continue;
                }
                for (int j = 0; j < n; j++) {
                    char bj = b.charAt(j);
                    if (bj == '?' && !matchB[j] && qmb == -1) {
                        qmb = j;
                    }
                    if (ai == bj && !matchB[j]) {
                        matchA[i] = true;
                        matchB[j] = true;
                        sol.put(i, j);
                        break;
                    }
                }
                if (matchA[i]) {
                    continue;
                }
                matchA[i] = true;
                if (qmb != -1) {
                    matchB[qmb] = true;
                    sol.put(i, qmb);
                }
            }
            for (int i = 0; i < n; i++) {
                if (matchA[i]) {
                    continue;
                }
                for (int j = 0; j < n; j++) {
                    if (!matchB[j]) {
                        matchA[i] = true;
                        matchB[j] = true;
                        sol.put(i, j);
                        break;
                    }
                }

            }
            System.out.println(sol.size());
            for (Integer key : sol.keySet()) {
                System.out.println((key + 1) + " " + (1 + sol.get(key)));
            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author NamBC
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
//        InputStream inputStream = new FileInputStream("sample-A.2.in");
//        OutputStream outputStream = new FileOutputStream("sample-A.2.ou");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    public static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String a = in.nextLine();
            String b = in.nextLine();
            ArrayList<Integer>[] aa = new ArrayList[256];
            ArrayList<Integer>[] ba = new ArrayList[256];
            ArrayList<Integer> aq = new ArrayList();
            ArrayList<Integer> bq = new ArrayList();
            HashMap<Integer, Integer> sol = new HashMap<>();
            for (int i = 97; i < 123; i++) {
                aa[i] = new ArrayList<>();
                ba[i] = new ArrayList<>();
            }
            for (int i = 0; i < n; i++) {
                char c = a.charAt(i);
                if (c != '?') {
                    aa[c].add(i);
                } else {
                    aq.add(i);
                }
                c = b.charAt(i);
                if (c != '?') {
                    ba[c].add(i);
                } else {
                    bq.add(i);
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!aa[i].isEmpty() && !ba[i].isEmpty()) {
                    sol.put(aa[i].get(0), ba[i].get(0));
                    aa[i].remove(0);
                    ba[i].remove(0);
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!aa[i].isEmpty() && !bq.isEmpty()) {
                    sol.put(aa[i].get(0), bq.get(0));
                    aa[i].remove(0);
                    bq.remove(0);
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!ba[i].isEmpty() && !aq.isEmpty()) {
                    sol.put(aq.get(0), ba[i].get(0));
                    ba[i].remove(0);
                    aq.remove(0);
                }
            }
            while (!aq.isEmpty() && !bq.isEmpty()) {
                sol.put(aq.get(0), bq.get(0));
                aq.remove(0);
                bq.remove(0);
            }

            System.out.println(sol.size());
            for (Integer key : sol.keySet()) {
                System.out.println((key + 1) + " " + (sol.get(key) + 1));

            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }

}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author NamBC
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
        // TODO code application logic here
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
//        InputStream inputStream = new FileInputStream("sample.in");
//        OutputStream outputStream = new FileOutputStream("sample.ou");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    public static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String a = in.nextLine();
            String b = in.nextLine();
            LinkedList<Integer>[] aa = new LinkedList[256];
            LinkedList<Integer>[] ba = new LinkedList[256];
            LinkedList<Integer> aq = new LinkedList();
            LinkedList<Integer> bq = new LinkedList();
            HashMap<Integer, Integer> sol = new HashMap<>();
            for (int i = 97; i < 123; i++) {
                aa[i] = new LinkedList<>();
                ba[i] = new LinkedList<>();
            }
            for (int i = 0; i < n; i++) {
                char c = a.charAt(i);
                if (c != '?') {
                    aa[c].push(i);
                } else {
                    aq.push(i);
                }
                c = b.charAt(i);
                if (c != '?') {
                    ba[c].push(i);
                } else {
                    bq.push(i);
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!aa[i].isEmpty() && !ba[i].isEmpty()) {
                    sol.put(aa[i].pop(), ba[i].pop());
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!aa[i].isEmpty() && !bq.isEmpty()) {
                    sol.put(aa[i].pop(), bq.pop());
                }
            }
            for (int i = 97; i < 123; i++) {
                while (!ba[i].isEmpty() && !aq.isEmpty()) {
                    sol.put(aq.pop(), ba[i].pop());
                }
            }
            while (!aq.isEmpty() && !bq.isEmpty()) {
                sol.put(aq.pop(), bq.pop());
            }

            out.println(sol.size());
            for (Integer key : sol.keySet()) {
                out.println((key + 1) + " " + (sol.get(key) + 1));

            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }

}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class D{
	static Scanner fr = new Scanner(System.in);

	public static void main(String args[]){
		int n = fr.nextInt();
		String s1 = fr.next();
		String s2 = fr.next();
		HashMap<Character, LinkedList<Integer>> hm = new HashMap<>();

		for(int i=0;i<n;i++){
			char c = s1.charAt(i);
			LinkedList<Integer> ll;
			if(hm.containsKey(c)){
				ll = hm.get(c);
			}else{
				ll = new LinkedList<>();
			}

			ll.add(i);
			hm.put(c, ll);
		}

		int val = 0;
		ArrayList<Integer> ans = new ArrayList<>();
		for(int i=0;i<n;i++){
			char c = s2.charAt(i);
			if(c == '?'){
				continue;
			}

			if(hm.containsKey(c) && !hm.get(c).isEmpty()){
				LinkedList<Integer> ll = hm.get(c);
				int j = ll.removeLast();
				ans.add(j+1);
				ans.add(i+1);
				val++;
				if(ll.isEmpty()){
					hm.remove(c);
				}
			}else if(!hm.containsKey(c) && hm.containsKey('?')){
				LinkedList<Integer> ll = hm.get('?');
				if(ll.isEmpty()){
					hm.remove('?');
				}else{
					int j = ll.removeLast();
					ans.add(i+1);
					ans.add(j+1);
					val++;
				}
			}
		}

		for(int i=0;i<n;i++){
			char c = s2.charAt(i);
			if(c == '?'){
				for(char ch: hm.keySet()){
					LinkedList<Integer> ll = hm.get(ch);
					if(!ll.isEmpty()){
						int j = ll.removeLast();
						ans.add(j+1);
						ans.add(i+1);
						val ++;
						if(ll.isEmpty()){
							hm.remove(ch);
						}
						break;
					}
				}
			}
		}

		System.out.println(val);
		for(int i=0;i<2*val;i+=2){
			System.out.println(ans.get(i) + " " + ans.get(i+1));
		}
	}

	static int[] nextArray(int n){
		int arr[] = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = fr.nextInt();
		}
		return arr;
	}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class D{
	static Scanner fr = new Scanner(System.in);

	public static void main(String args[]){
		int n = fr.nextInt();
		String s1 = fr.next();
		String s2 = fr.next();
		HashMap<Character, LinkedList<Integer>> hm = new HashMap<>();

		for(int i=0;i<n;i++){
			char c = s1.charAt(i);
			LinkedList<Integer> ll;
			if(hm.containsKey(c)){
				ll = hm.get(c);
			}else{
				ll = new LinkedList<>();
			}

			ll.add(i);
			hm.put(c, ll);
		}

		int val = 0;
		ArrayList<Integer> ans = new ArrayList<>();
		for(int i=0;i<n;i++){
			char c = s2.charAt(i);
			if(c == '?'){
				continue;
			}

			if(hm.containsKey(c) && !hm.get(c).isEmpty()){
				LinkedList<Integer> ll = hm.get(c);
				int j = ll.removeLast();
				ans.add(j+1);
				ans.add(i+1);
				val++;
				if(ll.isEmpty()){
					hm.remove(c);
				}
			}else if(!hm.containsKey(c) && hm.containsKey('?')){
				LinkedList<Integer> ll = hm.get('?');
				if(ll.isEmpty()){
					hm.remove('?');
				}else{
					int j = ll.removeLast();
					ans.add(j+1);
					ans.add(i+1);
					val++;
				}
			}
		}

		for(int i=0;i<n;i++){
			char c = s2.charAt(i);
			if(c == '?'){
				for(char ch: hm.keySet()){
					LinkedList<Integer> ll = hm.get(ch);
					if(!ll.isEmpty()){
						int j = ll.removeLast();
						ans.add(j+1);
						ans.add(i+1);
						val ++;
						if(ll.isEmpty()){
							hm.remove(ch);
						}
						break;
					}
				}
			}
		}

		System.out.println(val);
		for(int i=0;i<2*val;i+=2){
			System.out.println(ans.get(i) + " " + ans.get(i+1));
		}
	}

	static int[] nextArray(int n){
		int arr[] = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = fr.nextInt();
		}
		return arr;
	}
}


//package Contest547_div3;

import java.io.PrintWriter;
import java.util.*;

public class mainD {
    public static Scanner enter = new Scanner(System.in);
    public static Random random = new Random();
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        int n=enter.nextInt();
        String l=enter.next();
        String r=enter.next();
        HashMap<Character, LinkedList<Integer>> hm1=new HashMap<>(10000);
        HashMap<Character, LinkedList<Integer>> hm2=new HashMap<>(10000);
        for (int i = 0; i <l.length() ; i++) {
            if(hm1.get(l.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm1.put(l.charAt(i),ll);
            }
            else{
                hm1.get(l.charAt(i)).addLast(i+1);
            }

            if(hm2.get(r.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm2.put(r.charAt(i),ll);
            }
            else{
                hm2.get(r.charAt(i)).addLast(i+1);
            }
        }
        int ans=0;
        ArrayList<points> arr=new ArrayList<points>(10000);

        for (Character i:hm1.keySet()) {
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get(tmp)==null) continue;
            while(hm2.get(tmp).size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm1.get(tmp).pollLast(),hm2.get(tmp).pollLast()));
            }
        }
        for (Character i:hm2.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm1.get('?')==null) break;
            //if(hm2.get(tmp)==null) continue;
            while(hm1.get('?').size()>0 && hm2.get(tmp).size()>0){
                arr.add(new points(hm1.get('?').pollLast(),hm2.get(tmp).pollLast()));
            }
        }

        for (Character i:hm1.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get('?')==null) break;
            //if(hm1.get(tmp)==null) continue;
            while(hm2.get('?').size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm1.get(tmp).pollLast(),hm2.get('?').pollLast()));
            }
        }
       if(hm2.get('?')!=null && hm1.get('?')!=null){
           while(hm2.get('?').size()>0 && hm1.get('?').size()>0){
               arr.add(new points(hm1.get('?').pollLast(),hm2.get('?').pollLast()));
           }
       }

        out.println(arr.size());
        for (int i = 0; i <arr.size(); i++) {
            out.println(arr.get(i).n1+" "+arr.get(i).n2);
        }
        out.close();

    }
}
class points{
    int n1,n2;

    public points(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
}


//package Contest547_div3;

import java.io.PrintWriter;
import java.util.*;

public class mainD {
    public static Scanner enter = new Scanner(System.in);
    public static Random random = new Random();
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        int n=enter.nextInt();
        String l=enter.next();
        String r=enter.next();
        HashMap<Character, LinkedList<Integer>> hm1=new HashMap<>(10000);
        HashMap<Character, LinkedList<Integer>> hm2=new HashMap<>(10000);
        for (int i = 0; i <l.length() ; i++) {
            if(hm1.get(l.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm1.put(l.charAt(i),ll);
            }
            else{
                hm1.get(l.charAt(i)).addLast(i+1);
            }

            if(hm2.get(r.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm2.put(r.charAt(i),ll);
            }
            else{
                hm2.get(r.charAt(i)).addLast(i+1);
            }
        }
        int ans=0;
        ArrayList<points> arr=new ArrayList<points>(10000);

        for (Character i:hm1.keySet()) {
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get(tmp)==null) continue;
            while(hm2.get(tmp).size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm1.get(tmp).pollLast(),hm2.get(tmp).pollLast()));
            }
        }
        for (Character i:hm2.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm1.get('?')==null) break;
            //if(hm2.get(tmp)==null) continue;
            while(hm1.get('?').size()>0 && hm2.get(tmp).size()>0){
                arr.add(new points(hm1.get('?').pollLast(),hm2.get(tmp).pollLast()));
            }
        }

        for (Character i:hm1.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get('?')==null) break;
            //if(hm1.get(tmp)==null) continue;
            while(hm2.get('?').size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm2.get('?').pollLast(),hm1.get(tmp).pollLast()));
            }
        }
       if(hm2.get('?')!=null && hm1.get('?')!=null){
           while(hm2.get('?').size()>0 && hm1.get('?').size()>0){
               arr.add(new points(hm2.get('?').pollLast(),hm1.get('?').pollLast()));
           }
       }

        out.println(arr.size());
        for (int i = 0; i <arr.size(); i++) {
            out.println(arr.get(i).n1+" "+arr.get(i).n2);
        }
        out.close();

    }
}
class points{
    int n1,n2;

    public points(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
}


//package Contest547_div3;

import java.io.PrintWriter;
import java.util.*;

public class mainD {
    public static Scanner enter = new Scanner(System.in);
    public static Random random = new Random();
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        int n=enter.nextInt();
        String l=enter.next();
        String r=enter.next();
        HashMap<Character, LinkedList<Integer>> hm1=new HashMap<>(10000);
        HashMap<Character, LinkedList<Integer>> hm2=new HashMap<>(10000);
        for (int i = 0; i <l.length() ; i++) {
            if(hm1.get(l.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm1.put(l.charAt(i),ll);
            }
            else{
                hm1.get(l.charAt(i)).addLast(i+1);
            }

            if(hm2.get(r.charAt(i))==null){
                LinkedList<Integer> ll=new LinkedList<>();
                ll.addLast(i+1);
                hm2.put(r.charAt(i),ll);
            }
            else{
                hm2.get(r.charAt(i)).addLast(i+1);
            }
        }
        int ans=0;
        ArrayList<points> arr=new ArrayList<points>(10000);

        for (Character i:hm1.keySet()) {
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get(tmp)==null) continue;
            while(hm2.get(tmp).size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm1.get(tmp).pollLast(),hm2.get(tmp).pollLast()));
            }
        }
        for (Character i:hm2.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm1.get('?')==null) break;
            //if(hm2.get(tmp)==null) continue;
            while(hm1.get('?').size()>0 && hm2.get(tmp).size()>0){
                arr.add(new points(hm1.get('?').pollLast(),hm2.get(tmp).pollLast()));
            }
        }

        for (Character i:hm1.keySet()){
            char tmp=i;
            if(tmp=='?') continue;
            if(hm2.get('?')==null) break;
            //if(hm1.get(tmp)==null) continue;
            while(hm2.get('?').size()>0 && hm1.get(tmp).size()>0){
                arr.add(new points(hm1.get('?').pollLast(),hm2.get(tmp).pollLast()));
            }
        }
       if(hm2.get('?')!=null && hm1.get('?')!=null){
           while(hm2.get('?').size()>0 && hm1.get('?').size()>0){
               arr.add(new points(hm1.get('?').pollLast(),hm2.get('?').pollLast()));
           }
       }

        out.println(arr.size());
        for (int i = 0; i <arr.size(); i++) {
            out.println(arr.get(i).n1+" "+arr.get(i).n2);
        }
        out.close();

    }
}
class points{
    int n1,n2;

    public points(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class q5 {

	public static void main(String[] args) throws IOException {

		Reader.init(System.in);
		StringBuffer output=new StringBuffer("");
		PrintWriter out=new PrintWriter(System.out);
		int n=Reader.nextInt();
		int[] lcount=new int[27];
		int[] rcount=new int[27];
		ArrayList<NoD> arr1=new ArrayList<NoD>();
		ArrayList<NoD> arr2=new ArrayList<NoD>();
		String s=Reader.next();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='?') {
				lcount[26]++;
				arr1.add(new NoD(26,(i+1)));
			}
			else {
				int v=s.charAt(i)-97;
				arr1.add(new NoD(v,(i+1)));
				lcount[v]++;
			}
		}
		s=Reader.next();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='?') {
				rcount[26]++;
				arr2.add(new NoD(26,(i+1)));
			}
			else {
				int v=s.charAt(i)-97;
				arr2.add(new NoD(v,(i+1)));
				rcount[v]++;
			}
		}
		Collections.sort(arr1,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				return a.val-b.val;
			}
		});
		Collections.sort(arr2,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				return a.val-b.val;
			}
		});
		int ans=0;
		int[] visited1=new int[n+1];
		int[] visited2=new int[n+1];
		ArrayList<NoD> ans3=new ArrayList<NoD>();
		int i1=0,i2=0;
		while(i1<n && i2<n) {
			if(arr1.get(i1).val==arr2.get(i2).val && arr1.get(i1).val!=26) {
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				visited1[arr1.get(i1).index]=1;
				visited2[arr2.get(i2).index]=1;
				i1++;i2++;
			}
			else if(arr1.get(i1).val==26) {

				break;
			}
			else if(arr2.get(i2).val==26) {

				break;
			}
			else {
				if(arr1.get(i1).val<arr2.get(i2).val) {
					i1++;
				}
				else i2++;
			}
		}
		i1=n-1;i2=0;
		while(i1>=0 && i2<n) {
			if(arr1.get(i1).val==26 && arr2.get(i2).val!=26) {
				if(visited1[arr1.get(i1).index]==0 && visited2[arr2.get(i2).index]==0)
				{
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				visited1[arr1.get(i1).index]=1;
				visited2[arr2.get(i2).index]=1;
				i1--;
				}
				i2++;
			}
			else break;

		}
		i1=0;i2=n-1;
		while(i1<n && i2>=0) {
			if(arr1.get(i1).val!=26 && arr2.get(i2).val==26) {
				if(visited1[arr1.get(i1).index]==0 && visited2[arr2.get(i2).index]==0) {
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				visited1[arr1.get(i1).index]=1;
				visited2[arr2.get(i2).index]=1;
				i2--;
				}
				i1++;
			}
			else break;
		}
		i1=n-1;i2=n-1;
		while(i1>=0 && i2>=0) {
			if(arr1.get(i1).val==26 && arr2.get(i2).val==26) {
				if(visited1[arr1.get(i1).index]==0 && visited2[arr2.get(i2).index]==0)
				{
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				visited1[arr1.get(i1).index]=1;
				visited2[arr2.get(i2).index]=1;

				i1--;i2--;
				}
				else if(visited1[arr1.get(i1).index]==0) {
					i2--;
				}
				else if(visited2[arr2.get(i2).index]==0) {
					i1--;
				}
				else {
					i1--;i2--;
				}

			}
			else break;

		}
		output.append(ans);
		output.append("\n");
		for(int i=0;i<ans3.size();i++) {
			output.append(ans3.get(i).val);output.append(" ");
			output.append(ans3.get(i).index);output.append("\n");
		}
		out.write(output.toString());
		out.flush();

	}
}
class NoD{
	int val;
	int index;
	NoD(int v,int i){
		val=v;index=i;
	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class q5 {

	public static void main(String[] args) throws IOException {

		Reader.init(System.in);
		StringBuffer output=new StringBuffer("");
		PrintWriter out=new PrintWriter(System.out);
		int n=Reader.nextInt();
		int[] lcount=new int[27];
		int[] rcount=new int[27];
		ArrayList<NoD> arr1=new ArrayList<NoD>();
		ArrayList<NoD> arr2=new ArrayList<NoD>();
		String s=Reader.next();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='?') {
				lcount[26]++;
				arr1.add(new NoD(26,(i+1)));
			}
			else {
				int v=s.charAt(i)-97;
				arr1.add(new NoD(v,(i+1)));
				lcount[v]++;
			}
		}
		s=Reader.next();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='?') {
				rcount[26]++;
				arr2.add(new NoD(26,(i+1)));
			}
			else {
				int v=s.charAt(i)-97;
				arr2.add(new NoD(v,(i+1)));
				rcount[v]++;
			}
		}
		Collections.sort(arr1,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				return a.val-b.val;
			}
		});
		Collections.sort(arr2,new Comparator<NoD>() {
			public int compare(NoD a,NoD b) {
				return a.val-b.val;
			}
		});
		int ans=0;
		ArrayList<NoD> ans3=new ArrayList<NoD>();
		int i1=0,i2=0;
		while(i1<n && i2<n) {
			if(arr1.get(i1).val==arr2.get(i2).val) {
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				i1++;i2++;
			}
			else if(arr1.get(i1).val==26) {
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				i1++;i2++;
			}
			else if(arr2.get(i2).val==26) {
				ans++;
				lcount[arr1.get(i1).val]--;
				rcount[arr1.get(i1).val]--;
				ans3.add(new NoD(arr1.get(i1).index,arr2.get(i2).index));
				i1++;i2++;
			}
			else {
				if(arr1.get(i1).val<arr2.get(i2).val) {
					i1++;
				}
				else i2++;
			}
		}
		output.append(ans);
		output.append("\n");
		for(int i=0;i<ans3.size();i++) {
			output.append(ans3.get(i).val);output.append(" ");
			output.append(ans3.get(i).index);output.append("\n");
		}
		out.write(output.toString());
		out.flush();

	}
}
class NoD{
	int val;
	int index;
	NoD(int v,int i){
		val=v;index=i;
	}
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.io.*;
import java.util.*;

public class Task {

    public static void main(String[] args) throws IOException {

        new Task().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Task() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    int[] a;
    ArrayList<Integer>[] g;
    void solve() throws IOException {

        int n = in.nextInt();
        String l = in.next();
        String r = in.next();
        LinkedList<Integer> cl = new LinkedList<>();
        LinkedList<Integer> cr = new LinkedList<>();
        int al = 0;
        int ar = 0;
        LinkedList<Integer>[] cntl = new LinkedList[26];
        LinkedList<Integer>[] cntr = new LinkedList[26];

        for (int i = 0; i < 26; i++) {
            cntl[i] = new LinkedList<>();
            cntr[i] = new LinkedList<>();
        }

        for (int i = 0; i < n; i++) {
            if (l.charAt(i) == '?')
                cl.add(i);
            else
                cntl[l.charAt(i) - 'a'].add(i);

            if (r.charAt(i) == '?')
                cr.add(i);
            else
                cntr[r.charAt(i) - 'a'].add(i);
        }

        ArrayList<Pair> ans = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            while (cntl[i].size() > 0 && cntr[i].size() > 0) {
                int x = cntl[i].poll() + 1;
                int y = cntr[i].poll() + 1;
                ans.add(new Pair(x, y));
            }
            al += cntl[i].size();
            ar += cntr[i].size();
        }

        for (int i = 0; i < 26; i++) {

            while (cl.size() > 0 && cntr[i].size() > 0) {
                int x = cl.poll() + 1;
                int y = cntr[i].poll() + 1;
                ans.add(new Pair(x, y));
            }

            while (cr.size() > 0 && cntl[i].size() > 0) {
                int x = cr.poll() + 1;
                int y = cntl[i].poll() + 1;
                ans.add(new Pair(x, y));
            }
        }

        while (cl.size() > 0 && cr.size() > 0) {
            int x = cl.poll() + 1;
            int y = cr.poll() + 1;
            ans.add(new Pair(x, y));
        }

        out.println(ans.size());
        for (Pair p : ans)
            out.println(p.a + " " + p.b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {
            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        ArrayList<Integer>[] nextGraph(int n, int m) throws IOException {
            ArrayList<Integer>[] g = new ArrayList[n];
            for (int i = 0; i < n; i++)
                g[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int x = nextInt() - 1;
                int y = nextInt() - 1;
                g[x].add(y);
                g[y].add(x);
            }

            return g;
        }

    }

}


import java.io.*;
import java.util.*;

public class Task {

    public static void main(String[] args) throws IOException {

        new Task().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Task() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    int[] a;
    ArrayList<Integer>[] g;
    void solve() throws IOException {

        int n = in.nextInt();
        String l = in.next();
        String r = in.next();
        LinkedList<Integer> cl = new LinkedList<>();
        LinkedList<Integer> cr = new LinkedList<>();
        LinkedList<Integer>[] cntl = new LinkedList[26];
        LinkedList<Integer>[] cntr = new LinkedList[26];

        for (int i = 0; i < 26; i++) {
            cntl[i] = new LinkedList<>();
            cntr[i] = new LinkedList<>();
        }

        for (int i = 0; i < n; i++) {
            if (l.charAt(i) == '?')
                cl.add(i);
            else
                cntl[l.charAt(i) - 'a'].add(i);

            if (r.charAt(i) == '?')
                cr.add(i);
            else
                cntr[r.charAt(i) - 'a'].add(i);
        }

        ArrayList<Pair> ans = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            while (cntl[i].size() > 0 && cntr[i].size() > 0) {
                int x = cntl[i].poll() + 1;
                int y = cntr[i].poll() + 1;
                ans.add(new Pair(x, y));
            }
        }

        for (int i = 0; i < 26; i++) {

            while (cl.size() > 0 && cntr[i].size() > 0) {
                int x = cl.poll() + 1;
                int y = cntr[i].poll() + 1;
                ans.add(new Pair(x, y));
            }

            while (cr.size() > 0 && cntl[i].size() > 0) {
                int y = cr.poll() + 1;
                int x = cntl[i].poll() + 1;
                ans.add(new Pair(x, y));
            }
        }

        while (cl.size() > 0 && cr.size() > 0) {
            int x = cl.poll() + 1;
            int y = cr.poll() + 1;
            ans.add(new Pair(x, y));
        }

        out.println(ans.size());
        for (Pair p : ans)
            out.println(p.a + " " + p.b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {
            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (b > p.b) return 1;
            if (b < p.b) return -1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        ArrayList<Integer>[] nextGraph(int n, int m) throws IOException {
            ArrayList<Integer>[] g = new ArrayList[n];
            for (int i = 0; i < n; i++)
                g[i] = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int x = nextInt() - 1;
                int y = nextInt() - 1;
                g[x].add(y);
                g[y].add(x);
            }

            return g;
        }

    }

}


import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	static LinkedList<Integer>[] left;
	static LinkedList<Integer>[] right;
	private static StringBuilder sb;
	private static int count;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] l = sc.next().toCharArray();
		char[] r = sc.next().toCharArray();
		left = new LinkedList[27];
		right = new LinkedList[27];
		sb = new StringBuilder();
		for (int i = 0; i < 27; i++) {
			left[i] = new LinkedList<>();
			right[i] = new LinkedList<>();
		}
		for (int i = 0; i < n; i++) {
			if (l[i] == '?') {
				left[26].add(i + 1);
			} else {
				left[l[i] - 'a'].add(i + 1);
			}
			if (r[i] == '?') {
				right[26].add(i + 1);
			} else {
				right[r[i] - 97].add(i + 1);
			}
		}
		for (int i = 0; i < 26; i++) {
			f(i, i);
			f(i, 26);
			f(26, i);
		}
		f(26, 26);
		System.out.println(count);
		System.out.println(sb);
	}

	private static void f(int i, int j) {
		while (!left[i].isEmpty() && !right[j].isEmpty()) {
			sb.append(left[i].getFirst() + " " + right[j].getFirst() + '\n');
			count++;
			left[i].removeFirst();
			right[j].removeFirst();
		}
	}
}


import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] l = sc.next().toCharArray();
		char[] r = sc.next().toCharArray();
		LinkedList<Integer>[] left = new LinkedList[27];
		LinkedList<Integer>[] right = new LinkedList[27];
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 27; i++) {
			left[i] = new LinkedList<>();
			right[i] = new LinkedList<>();
		}
		for (int i = 0; i < n; i++) {
			if (l[i] == '?') {
				left[26].add(i + 1);
			} else {
				left[l[i] - 'a'].add(i + 1);
			}
			if (r[i] == '?') {
				right[26].add(i + 1);
			} else {
				right[r[i] - 97].add(i + 1);
			}
		}
		int count = 0;
		for (int i = 0; i < 26; i++) {
			while (!left[i].isEmpty() && !right[i].isEmpty()) {
				sb.append(left[i].getFirst() + " " + right[i].getFirst() + '\n');
				count++;
				left[i].removeFirst();
				right[i].removeFirst();
			}
			while (!left[i].isEmpty() && !right[26].isEmpty()) {
				sb.append(left[i].getFirst() + " " + right[26].getFirst() + '\n');
				count++;
				left[i].removeFirst();
				right[26].removeFirst();
			}
			while (!left[26].isEmpty() && !right[i].isEmpty()) {
				sb.append(left[26].getFirst() + " " + right[i].getFirst() + '\n');
				count++;
				left[26].removeFirst();
				right[i].removeFirst();
			}
		}
		while (!left[26].isEmpty() && !right[26].isEmpty()) {
			sb.append(left[26].getFirst() + " " + right[26].getFirst() + '\n');
			count++;
			left[26].removeFirst();
			right[26].removeFirst();
		}
		System.out.println(count);
		System.out.println(sb);
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	//static final long MOD = 998244353;
	static final long MOD = 1000000007;
	static final int INF = 1000000007;
	static boolean[] visited;
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        String L = sc.next();
        String R = sc.next();
        HashSet<Integer>[] left = new HashSet[26];
        HashSet<Integer> lQs = new HashSet<Integer>();
        HashSet<Integer>[] right = new HashSet[26];
        HashSet<Integer> rQs = new HashSet<Integer>();
        for (int i = 0; i < 26; i++) {
        	left[i] = new HashSet<Integer>();
        	right[i] = new HashSet<Integer>();
        }
        for (int i = 0; i < N; i++) {
        	if (L.charAt(i) == '?')
        		lQs.add(i);
        	else
        		left[L.charAt(i)-'a'].add(i);
        }
        for (int i = 0; i < N; i++) {
        	if (R.charAt(i) == '?')
        		rQs.add(i);
        	else
        		right[R.charAt(i)-'a'].add(i);
        }
        int ans = 0;
        int[][] pairs = new int[N][2];
        for (int i = 0; i < 26; i++) {
        	while (left[i].size() > 0 && right[i].size() > 0) {
        		for (int first: left[i]) {
        			pairs[ans][0] = first;
        			left[i].remove(first);
        			break;
        		}
        		for (int first: right[i]) {
        			pairs[ans][1] = first;
        			right[i].remove(first);
        			break;
        		}
        		ans++;
        	}
        	while (left[i].size() > 0 && rQs.size() > 0) {
        		for (int first: left[i]) {
        			pairs[ans][0] = first;
        			left[i].remove(first);
        			break;
        		}
        		for (int first: rQs) {
        			pairs[ans][1] = first;
        			rQs.remove(first);
        			break;
        		}
        		ans++;
        	}
        	while (lQs.size() > 0 && right[i].size() > 0) {
        		for (int first: lQs) {
        			pairs[ans][0] = first;
        			lQs.remove(first);
        			break;
        		}
        		for (int first: right[i]) {
        			pairs[ans][1] = first;
        			right[i].remove(first);
        			break;
        		}
        		ans++;
        	}
        }
    	while (lQs.size() > 0 && rQs.size() > 0) {
    		for (int first: lQs) {
    			pairs[ans][0] = first;
    			lQs.remove(first);
    			break;
    		}
    		for (int first: rQs) {
    			pairs[ans][1] = first;
    			rQs.remove(first);
    			break;
    		}
    		ans++;
    	}
    	System.out.println(ans);
    	StringBuilder print = new StringBuilder();
    	for (int i = 0; i < ans; i++) {
    		print.append((pairs[i][0]+1) + " " + (pairs[i][1]+1) + "\n");
    	}
    	System.out.print(print);
    }

    public static long power(long x, long y, long p) {
        // Initialize result
        long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }

    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }

    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  if (arr1[1] != arr2[1])
					  return arr1[1]-arr2[1];
				  else if (arr1[2] != arr2[2])
					  return arr1[2]-arr2[2];
				  else
					  return arr1[3]-arr2[3];
	          }
		});
		return array;
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	//static final long MOD = 998244353;
	static final long MOD = 1000000007;
	static final int INF = 1000000007;
	static boolean[] visited;
    public static void main(String[] args) throws IOException {
    	FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        String L = sc.next();
        String R = sc.next();
        Stack<Integer>[] left = new Stack[26];
        Stack<Integer> lQs = new Stack<Integer>();
        Stack<Integer>[] right = new Stack[26];
        Stack<Integer> rQs = new Stack<Integer>();
        for (int i = 0; i < 26; i++) {
        	left[i] = new Stack<Integer>();
        	right[i] = new Stack<Integer>();
        }
        for (int i = 0; i < N; i++) {
        	if (L.charAt(i) == '?')
        		lQs.push(i);
        	else
        		left[L.charAt(i)-'a'].push(i);
        }
        for (int i = 0; i < N; i++) {
        	if (R.charAt(i) == '?')
        		rQs.push(i);
        	else
        		right[R.charAt(i)-'a'].push(i);
        }
        int ans = 0;
        int[][] pairs = new int[N][2];
        for (int i = 0; i < 26; i++) {
        	while (!left[i].isEmpty() && !right[i].isEmpty()) {
    			pairs[ans][0] = left[i].pop();
    			pairs[ans][1] = right[i].pop();
        		ans++;
        	}
        	while (!left[i].isEmpty() && !rQs.isEmpty()) {
    			pairs[ans][0] = left[i].pop();
    			pairs[ans][1] = rQs.pop();
        		ans++;
        	}
        	while (!lQs.isEmpty() && !right[i].isEmpty()) {
    			pairs[ans][0] = lQs.pop();
    			pairs[ans][1] = right[i].pop();
        		ans++;
        	}
        }
    	while (!lQs.isEmpty() && !rQs.isEmpty()) {
			pairs[ans][0] = lQs.pop();
			pairs[ans][1] = rQs.pop();
    		ans++;
    	}
    	System.out.println(ans);
    	StringBuilder print = new StringBuilder();
    	for (int i = 0; i < ans; i++) {
    		print.append((pairs[i][0]+1) + " " + (pairs[i][1]+1) + "\n");
    	}
    	System.out.print(print);
    }

    public static long power(long x, long y, long p) {
        // Initialize result
        long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }

    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }

    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  return arr1[0]-arr2[0];
	          }
		});
		return array;
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	//static final long MOD = 998244353;
	static final long MOD = 1000000007;
	static final int INF = 1000000007;
	static boolean[] visited;
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        String L = sc.next();
        String R = sc.next();
        HashSet<Integer>[] left = new HashSet[26];
        HashSet<Integer> lQs = new HashSet<Integer>();
        HashSet<Integer>[] right = new HashSet[26];
        HashSet<Integer> rQs = new HashSet<Integer>();
        for (int i = 0; i < 26; i++) {
        	left[i] = new HashSet<Integer>();
        	right[i] = new HashSet<Integer>();
        }
        for (int i = 0; i < N; i++) {
        	if (L.charAt(i) == '?')
        		lQs.add(i);
        	else
        		left[L.charAt(i)-'a'].add(i);
        }
        for (int i = 0; i < N; i++) {
        	if (R.charAt(i) == '?')
        		rQs.add(i);
        	else
        		right[R.charAt(i)-'a'].add(i);
        }
        int ans = 0;
        int[][] pairs = new int[N][2];
        for (int i = 0; i < 26; i++) {
        	while (left[i].size() > 0 && right[i].size() > 0) {
        		for (int first: left[i]) {
        			pairs[ans][0] = first;
        			left[i].remove(first);
        			break;
        		}
        		for (int first: right[i]) {
        			pairs[ans][1] = first;
        			right[i].remove(first);
        			break;
        		}
        		ans++;
        	}
        	while (left[i].size() > 0 && rQs.size() > 0) {
        		for (int first: left[i]) {
        			pairs[ans][0] = first;
        			left[i].remove(first);
        			break;
        		}
        		for (int first: rQs) {
        			pairs[ans][1] = first;
        			rQs.remove(first);
        			break;
        		}
        		ans++;
        	}
        	while (right[i].size() > 0 && lQs.size() > 0) {
        		for (int first: right[i]) {
        			pairs[ans][0] = first;
        			right[i].remove(first);
        			break;
        		}
        		for (int first: lQs) {
        			pairs[ans][1] = first;
        			lQs.remove(first);
        			break;
        		}
        		ans++;
        	}
        }
    	while (lQs.size() > 0 && rQs.size() > 0) {
    		for (int first: lQs) {
    			pairs[ans][0] = first;
    			lQs.remove(first);
    			break;
    		}
    		for (int first: rQs) {
    			pairs[ans][1] = first;
    			rQs.remove(first);
    			break;
    		}
    		ans++;
    	}
    	System.out.println(ans);
    	StringBuilder print = new StringBuilder();
    	for (int i = 0; i < ans; i++) {
    		print.append((pairs[i][0]+1) + " " + (pairs[i][1]+1) + "\n");
    	}
    	System.out.print(print);
    }

    public static long power(long x, long y, long p) {
        // Initialize result
        long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }

    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }

    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  if (arr1[1] != arr2[1])
					  return arr1[1]-arr2[1];
				  else if (arr1[2] != arr2[2])
					  return arr1[2]-arr2[2];
				  else
					  return arr1[3]-arr2[3];
	          }
		});
		return array;
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1141D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         char[] left = infile.readLine().toCharArray();
         char[] right = infile.readLine().toCharArray();
         ArrayList<Integer> res = new ArrayList<Integer>();
         ArrayList<Integer>[] freq1 = new ArrayList[27];
         ArrayList<Integer>[] freq2 = new ArrayList[27];
         for(int i=0; i < 27; i++)
         {
            freq1[i] = new ArrayList<Integer>();
            freq2[i] = new ArrayList<Integer>();
         }
         for(int i=0; i < N; i++)
         {
            char c = left[i];
            if(c == '?')
               freq1[26].add(i);
            else
               freq1[c-'a'].add(i);
         }
         for(int i=0; i < N; i++)
         {
            char c = right[i];
            if(c == '?')
               freq2[26].add(i);
            else
               freq2[c-'a'].add(i);
         }
         //solve
         ArrayList<Integer> extra1 = new ArrayList<Integer>();
         ArrayList<Integer> extra2 = new ArrayList<Integer>();
         for(int i=0; i < 26; i++)
         {
            if(freq1[i].size() >= freq2[i].size())
            {
               for(int a=0; a < freq2[i].size(); a++)
               {
                  res.add(freq1[i].get(a));
                  res.add(freq2[i].get(a));
               }
               for(int a=freq2[i].size(); a < freq1[i].size(); a++)
                  extra1.add(freq1[i].get(a));
            }
            else
            {
               for(int a=0; a < freq1[i].size(); a++)
               {
                  res.add(freq1[i].get(a));
                  res.add(freq2[i].get(a));
               }
               for(int a=freq1[i].size(); a < freq2[i].size(); a++)
                  extra2.add(freq2[i].get(a));
            }
         }
         int a = 0;
         for(int i=0; i < Math.min(extra1.size(), freq2[26].size()); i++)
         {
            res.add(extra1.get(a));
            res.add(freq2[26].get(a));
            a++;
         }
         int b = 0;
         for(int i=0; i < Math.min(extra2.size(), freq1[26].size()); i++)
         {
            res.add(freq1[26].get(b));
            res.add(extra2.get(b));
            b++;
         }
         while(a < freq1[26].size() && b < freq2[26].size())
         {
            res.add(freq1[26].get(a++));
            res.add(freq2[26].get(b++));
         }
         System.out.println(res.size()/2);
         StringBuilder sb = new StringBuilder();
         for(int i=0; i < res.size(); i+=2)
         {
            sb.append((1+res.get(i))+" "+(1+res.get(i+1)));
            sb.append("\n");
         }
         System.out.print(sb);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1141D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         char[] left = infile.readLine().toCharArray();
         char[] right = infile.readLine().toCharArray();
         ArrayList<Integer> res = new ArrayList<Integer>();
         ArrayList<Integer>[] freq1 = new ArrayList[27];
         ArrayList<Integer>[] freq2 = new ArrayList[27];
         for(int i=0; i < 27; i++)
         {
            freq1[i] = new ArrayList<Integer>();
            freq2[i] = new ArrayList<Integer>();
         }
         for(int i=0; i < N; i++)
         {
            char c = left[i];
            if(c == '?')
               freq1[26].add(i);
            else
               freq1[c-'a'].add(i);
         }
         for(int i=0; i < N; i++)
         {
            char c = right[i];
            if(c == '?')
               freq2[26].add(i);
            else
               freq2[c-'a'].add(i);
         }
         //solve
         ArrayList<Integer> extra1 = new ArrayList<Integer>();
         ArrayList<Integer> extra2 = new ArrayList<Integer>();
         for(int i=0; i < 26; i++)
         {
            if(freq1[i].size() >= freq2[i].size())
            {
               for(int a=0; a < freq2[i].size(); a++)
               {
                  res.add(freq1[i].get(a));
                  res.add(freq2[i].get(a));
               }
               for(int a=freq2[i].size(); a < freq1[i].size(); a++)
                  extra1.add(freq1[i].get(a));
            }
            else
            {
               for(int a=0; a < freq1[i].size(); a++)
               {
                  res.add(freq1[i].get(a));
                  res.add(freq2[i].get(a));
               }
               for(int a=freq1[i].size(); a < freq2[i].size(); a++)
                  extra2.add(freq2[i].get(a));
            }
         }
         int a = 0;
         for(int i=0; i < Math.min(extra1.size(), freq2[26].size()); i++)
         {
            res.add(extra1.get(a));
            res.add(freq2[26].get(a));
            a++;
         }
         int b = 0;
         for(int i=0; i < Math.min(extra2.size(), freq1[26].size()); i++)
         {
            res.add(extra2.get(b));
            res.add(freq1[26].get(b));
            b++;
         }
         while(a < freq1[26].size() && b < freq2[26].size())
         {
            res.add(freq1[26].get(a++));
            res.add(freq2[26].get(b++));
         }
         System.out.println(res.size()/2);
         StringBuilder sb = new StringBuilder();
         for(int i=0; i < res.size(); i+=2)
         {
            sb.append((1+res.get(i))+" "+(1+res.get(i+1)));
            sb.append("\n");
         }
         System.out.print(sb);
      }
   }


//package year2019.month03.cf.round547div3;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class round547div3D {

    boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null);

    public round547div3D() throws IOException {
        InputReader in;
        if (ONLINE_JUDGE) {
            in = new InputReader(System.in);
        } else {
            in = new InputReader(new FileInputStream("/Users/karj/cp/input.txt"));
        }
        PrintWriter out = new PrintWriter(System.out);

        int T = 1;
        for (int caseNo = 1; caseNo <= T; caseNo++) {
            solve(caseNo, in, out);
        }

        out.close();
    }

    private void solve(int caseNo, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        String l = in.nextString();
        String r = in.nextString();
        HashMap<Character, TreeSet<Integer>> lmap = new HashMap<>();
        HashMap<Character, TreeSet<Integer>> rmap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            TreeSet<Integer> s1 = new TreeSet<>();
            if (lmap.containsKey(l.charAt(i))) {
                s1 = lmap.get(l.charAt(i));
            }
            s1.add(i + 1);
            lmap.put(l.charAt(i), s1);

            TreeSet<Integer> s2 = new TreeSet<>();
            if (rmap.containsKey(r.charAt(i))) {
                s2 = rmap.get(r.charAt(i));
            }
            s2.add(i + 1);
            rmap.put(r.charAt(i), s2);
        }
        debug(lmap);
        debug(rmap);
        StringBuilder ans = new StringBuilder("");
        int k = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            TreeSet<Integer> s1 = lmap.getOrDefault(c, new TreeSet<>());
            TreeSet<Integer> s2 = rmap.getOrDefault(c, new TreeSet<>());
//            debug(c, s1, s2);
            int is = min(s1.size(), s2.size());
            for (int i = 0; i < is; i++) {
                ans.append(s1.pollFirst() + " " + s2.pollFirst() + "\n");
                k++;
            }
            if (s1.size() == 0) {
                lmap.remove(c);
            }
            if (s2.size() == 0) {
                rmap.remove(c);
            }
        }
        TreeSet<Integer> lqn = lmap.getOrDefault('?', new TreeSet<>());
        int is = lqn.size();
        for (int i = 0; i < is; i++) {
            for (Map.Entry<Character, TreeSet<Integer>> entry : rmap.entrySet()) {
                int key = entry.getKey();
                TreeSet<Integer> rqq = entry.getValue();
                if (key == '?') {
                    continue;
                }
                debug(lqn, rqq);
                int js = min(lqn.size(), rqq.size());
                for (int j = 0; j < js; j++) {
                    ans.append(lqn.pollFirst() + " " + rqq.pollFirst() + "\n");
                    k++;
                }
                if (lqn.size() == 0) {
                    lmap.remove('?');
                }
                if (rqq.size() == 0) {
                    rmap.remove(key);
                }
            }
        }
        TreeSet<Integer> rqn = rmap.getOrDefault('?', new TreeSet<>());
        is = rqn.size();
        for (int i = 0; i < is; i++) {
            for (Map.Entry<Character, TreeSet<Integer>> entry : lmap.entrySet()) {
                int key = entry.getKey();
                TreeSet<Integer> lqq = entry.getValue();
                if (key == '?') {
                    continue;
                }
                debug(rqn, lqq);
                int js = min(rqn.size(), lqq.size());
                for (int j = 0; j < js; j++) {
                    ans.append(lqq.pollFirst() + " " + rqn.pollFirst() + "\n");
                    k++;
                }
                if (rqn.size() == 0) {
                    rmap.remove('?');
                }
                if (lqq.size() == 0) {
                    lmap.remove(key);
                }
            }
        }
        for (char c = '?'; c <= '?'; c++) {
            TreeSet<Integer> s1 = lmap.getOrDefault(c, new TreeSet<>());
            TreeSet<Integer> s2 = rmap.getOrDefault(c, new TreeSet<>());
//            debug(c, s1, s2);
            is = min(s1.size(), s2.size());
            for (int i = 0; i < is; i++) {
                ans.append(s1.pollFirst() + " " + s2.pollFirst() + "\n");
                k++;
            }
            if (s1.size() == 0) {
                lmap.remove(c);
            }
            if (s2.size() == 0) {
                rmap.remove(c);
            }
        }
        out.println(k);
        if (k > 0) {
            out.print(ans);
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }

        public String next() {
            return nextString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public Long nextLong() {
            return Long.parseLong(nextString());
        }

        public Double nextDouble() {
            return Double.parseDouble(nextString());
        }

        public char nextCharacter() {
            return nextString().charAt(0);
        }

        public int[] nextIntArray(int N) {
            int A[] = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = nextInt();
            }
            return A;
        }

        public long[] nextLongArray(int N) {
            long A[] = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = nextLong();
            }
            return A;
        }

        public double[] nextDoubleArray(int N) {
            double A[] = new double[N];
            for (int i = 0; i < N; i++) {
                A[i] = nextDouble();
            }
            return A;
        }
    }

    int min(int... a) {
        int min = Integer.MAX_VALUE;
        for (int v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    long min(long... a) {
        long min = Long.MAX_VALUE;
        for (long v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    double min(double... a) {
        double min = Double.MAX_VALUE;
        for (double v : a) {
            min = Math.min(min, v);
        }
        return min;
    }

    int max(int... a) {
        int max = Integer.MIN_VALUE;
        for (int v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    long max(long... a) {
        long max = Long.MIN_VALUE;
        for (long v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    double max(double... a) {
        double max = Double.MIN_VALUE;
        for (double v : a) {
            max = Math.max(max, v);
        }
        return max;
    }

    public <A, B> Pair MP(A a, B b) {
        return new Pair<A, B>(a, b);
    }

    class Pair<F, S> {
        public final F f;
        public final S s;

        public Pair(F f, S s) {
            this.f = f;
            this.s = s;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            return Objects.equals(f, pair.f) &&
                    Objects.equals(s, pair.s);
        }

        @Override
        public int hashCode() {

            return Objects.hash(f, s);
        }

        @Override
        public String toString() {
            return f.toString() + " " + s.toString();
        }
    }

    private void debug(Object... o) {
        if (ONLINE_JUDGE) {
            return;
        }
        System.err.println(Arrays.deepToString(o));
    }

    public static void main(String args[]) throws IOException {
        new round547div3D();
    }
}