#include <bits/stdc++.h>
using namespace std;
vector<pair<char, long long int> > v1, v2, v3, v4, fa, ra, bi;
vector<pair<long long int, long long int> > vec;
map<char, long long int> Mp1, Mp2;
vector<long long int> A1, A2;
long long int visited1[150005];
long long int visited2[150005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  string a, b, s = "abcdefghijklmnopqrstuvwxyz";
  cin >> a >> b;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == '?')
      a[i] = '{';
    else
      Mp1[a[i]]++;
  }
  for (long long int i = 0; i < n; i++) {
    if (b[i] == '?')
      b[i] = '{';
    else
      Mp2[b[i]]++;
  }
  for (long long int i = 0; i < n; i++) {
    fa.push_back(make_pair(a[i], i));
  }
  for (long long int i = 0; i < n; i++) {
    ra.push_back(make_pair(b[i], i));
  }
  v1 = fa;
  v2 = ra;
  sort(fa.begin(), fa.end());
  sort(ra.begin(), ra.end());
  for (int i = 0; i < 26; i++) {
    if (Mp1[s[i]] > 0 && Mp2[s[i]] > 0) {
      bi.push_back(make_pair(s[i], min(Mp1[s[i]], Mp2[s[i]])));
    }
  }
  for (long long int k = 0; k < bi.size(); k++) {
    long long int cnt = 0;
    for (long long int i = 0; i < n; i++) {
      if (bi[k].first == fa[i].first && bi[k].second > cnt) {
        A1.push_back(fa[i].second);
        cnt++;
      }
    }
  }
  for (long long int k = 0; k < bi.size(); k++) {
    long long int cnt = 0;
    for (long long int i = 0; i < n; i++) {
      if (bi[k].first == ra[i].first && bi[k].second > cnt) {
        A2.push_back(ra[i].second);
        cnt++;
      }
    }
  }
  memset(visited1, 0, sizeof visited1);
  memset(visited2, 0, sizeof visited2);
  for (long long int i = 0; i < A1.size(); i++) {
    visited1[A1[i]] = 1;
    visited2[A2[i]] = 1;
    vec.push_back(make_pair(A1[i], A2[i]));
  }
  for (long long int i = 0; i < n; i++) {
    if (visited1[i] == 0) {
      v3.push_back(make_pair(v1[i].first, v1[i].second));
    }
    if (visited2[i] == 0) {
      v4.push_back(make_pair(v2[i].first, v2[i].second));
    }
  }
  sort(v3.begin(), v3.end());
  sort(v4.rbegin(), v4.rend());
  for (long long int i = 0; i < v3.size(); i++) {
    if (v3[i].first == '{' || v4[i].first == '{') {
      vec.push_back(make_pair(v3[i].second, v4[i].second));
    }
  }
  cout << vec.size() << endl;
  for (long long int i = 0; i < vec.size(); i++) {
    cout << vec[i].first + 1 << " " << vec[i].second + 1 << endl;
  }
  return 0;
}
