#include <bits/stdc++.h>
using namespace std;
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  string sec;
  cin >> sec;
  map<char, vector<long long int>> c1, c2;
  vector<long long int> cnt1, cnt2;
  vector<pair<long long int, long long int>> p;
  long long int cnt = 0;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] != '?') {
      c1[s[i]].push_back(i + 1);
    } else {
      cnt1.push_back(i + 1);
    }
  }
  for (long long int i = 0; i < sec.length(); i++) {
    if (sec[i] != '?') {
      c2[sec[i]].push_back(i + 1);
    } else {
      cnt2.push_back(i + 1);
    }
  }
  vector<long long int> mark1(n), mark2(n);
  for (long long int i = 0; i < 26; i++) {
    char ch = 'a' + i;
    for (long long int j = 0; j < min(c1[ch].size(), c2[ch].size()); j++) {
      p.push_back(make_pair(c1[ch][j], c2[ch][j]));
      mark1[c1[ch][j] - 1] = 1;
      mark2[c2[ch][j] - 1] = 1;
    }
  }
  for (long long int i = 0; i < cnt1.size(); i++) {
    mark1[cnt1[i] - 1] = 1;
  }
  for (long long int i = 0; i < cnt2.size(); i++) {
    mark2[cnt2[i] - 1] = 1;
  }
  long long int k1 = 0;
  for (long long int i = 0; i < mark1.size(); i++) {
    if (!mark1[i] && k1 < cnt2.size()) {
      p.push_back(make_pair(i + 1, cnt2[k1++]));
    }
  }
  long long int k2 = 0;
  for (long long int i = 0; i < mark2.size(); i++) {
    if (!mark2[i] && k2 < cnt1.size()) {
      p.push_back(make_pair(cnt1[k2++], i + 1));
    }
  }
  for (; k1 < cnt2.size() && k2 < cnt1.size();) {
    p.push_back(make_pair(cnt1[k2++], cnt2[k1++]));
  }
  cout << p.size() << "\n";
  for (long long int i = 0; i < p.size(); i++) {
    cout << p[i].first << " " << p[i].second << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
