#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, letter1[270], letter2[270], q1 = 0, q2 = 0;
  cin >> n;
  char s1[150005], s2[150005];
  cin >> s1 >> s2;
  int ar[150005];
  memset(ar, 0, sizeof(ar));
  vector<int> v1[150005];
  vector<int> v2[150005];
  queue<int> qq1;
  queue<int> qq2;
  memset(letter1, 0, sizeof(letter1));
  memset(letter2, 0, sizeof(letter2));
  for (int i = 0; i < n; i++) {
    if (s1[i] >= 'a' and s1[i] <= 'z')
      v1[s1[i]].push_back(i + 1);
    else
      qq1.push(i + 1);
    if (s2[i] >= 'a' and s2[i] <= 'z')
      v2[s2[i]].push_back(i + 1);
    else
      qq2.push(i + 1);
  }
  int cnt = 0;
  queue<pair<int, int> > q;
  cnt = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    for (int j = 0; j < v1[i].size() and j < v2[i].size(); j++) {
      q.push(pair<int, int>(v1[i][j], v2[i][j]));
      s1[v1[i][j] - 1] = '0';
      s2[v2[i][j] - 1] = '0';
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s1[i] >= 'a' and s1[i] <= 'z' and !qq2.empty()) {
      q.push(pair<int, int>(i + 1, qq2.front()));
      s1[i] = '0';
      qq2.pop();
      cnt++;
    } else if (s2[i] >= 'a' and s2[i] <= 'z' and !qq1.empty()) {
      q.push(pair<int, int>(qq1.front(), i + 1));
      s2[i] = '0';
      qq1.pop();
      cnt++;
    }
  }
  while (!qq1.empty() and !qq2.empty()) {
    q.push(pair<int, int>(qq1.front(), qq2.front()));
    qq1.pop();
    qq2.pop();
    cnt++;
  }
  cout << cnt << endl;
  while (!q.empty()) {
    pair<int, int> top = q.front();
    q.pop();
    printf("%d %d\n", top.first, top.second);
  }
  return 0;
}
