#include <bits/stdc++.h>
using namespace std;
const int maxx = 15e4 + 7;
const int Inf = 1 << 30;
const long long INF = 1ll << 60;
int n;
char S[maxx], T[maxx];
int s[maxx], t[maxx];
int tot[maxx];
int pos[30][maxx];
bool vis[maxx];
bool visT[maxx];
queue<int> qua;
queue<int> que;
int ans;
struct PP {
  int ss, tt;
} f[maxx];
int main() {
  scanf("%d %s %s", &n, S + 1, T + 1);
  for (int i = 1; i <= n; i++) {
    if (S[i] != '?') s[i] = S[i] - 'a' + 1;
  }
  for (int i = 1; i <= n; i++) {
    if (T[i] != '?')
      t[i] = T[i] - 'a' + 1;
    else
      qua.push(i);
  }
  for (int i = 1; i <= 26; i++) {
    for (int j = 1; j <= n; j++) {
      if (t[j] == i) {
        tot[i]++;
        pos[i][tot[i]] = j;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (tot[s[i]]) {
      ans++;
      f[ans].ss = i;
      f[ans].tt = pos[s[i]][tot[s[i]]];
      vis[f[ans].ss] = 1;
      visT[f[ans].tt] = 1;
      tot[s[i]]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      if (S[i] != '?') {
        if (!qua.empty()) {
          ans++;
          f[ans].ss = i;
          f[ans].tt = qua.front();
          visT[f[ans].tt] = 1;
          qua.pop();
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!visT[i]) que.push(i);
  }
  for (int i = 1; i <= n; i++) {
    if (S[i] == '?') {
      if (!que.empty()) {
        ans++;
        f[ans].ss = i;
        f[ans].tt = que.front();
        que.pop();
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= ans; i++) printf("%d %d\n", f[i].ss, f[i].tt);
  return 0;
}
