#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string l, r;
  cin >> l >> r;
  vector<vector<long long> > posL(26);
  vector<vector<long long> > posR(26);
  vector<long long> posQL;
  vector<long long> posQR;
  for (int i = 0; i < n; i++) {
    if (l[i] == '?') {
      posQL.push_back(i);
    } else {
      posL[l[i] - 'a'].push_back(i);
    }
    if (r[i] == '?') {
      posQR.push_back(i);
    } else {
      posR[r[i] - 'a'].push_back(i);
    }
  }
  vector<pair<long long, long long> > ans;
  for (int chr = 0; chr < 26; chr++) {
    for (int i = 0; i < min(posL[chr].size(), posR[chr].size()); i++) {
      ans.push_back(make_pair(posL[chr][i], posR[chr][i]));
      l[posL[chr][i]] = '.';
      r[posR[chr][i]] = '.';
    }
  }
  long long curR = 0;
  while (!(r[curR] >= 'a' && r[curR] <= 'z')) {
    curR++;
    if (curR == n) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (curR == n) {
      break;
    }
    if (l[i] == '?') {
      ans.push_back(make_pair(i, curR));
      l[i] = '.';
      r[curR] = '.';
      while (!(r[curR] >= 'a' && r[curR] <= 'z')) {
        curR++;
        if (curR == n) {
          break;
        }
      }
      if (curR == n) {
        break;
      }
    }
  }
  long long curL = 0;
  while (!(l[curL] >= 'a' && l[curL] <= 'z')) {
    curL++;
    if (curL == n) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (curL == n) {
      break;
    }
    if (r[i] == '?') {
      ans.push_back(make_pair(curL, i));
      l[curL] = '.';
      r[i] = '.';
      while (!(l[curL] >= 'a' && l[curL] <= 'z')) {
        curL++;
        if (curL == n) {
          break;
        }
      }
      if (curL == n) {
        break;
      }
    }
  }
  curL = 0;
  while (!(l[curL] == '?')) {
    curL++;
    if (curL == n) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (curL == n) {
      break;
    }
    if (r[i] == '?') {
      ans.push_back(make_pair(curL, i));
      l[curL] = '.';
      r[i] = '.';
      while (!(l[curL] == '?')) {
        curL++;
        if (curL == n) {
          break;
        }
      }
      if (curL == n) {
        break;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
  }
}
