#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  map<char, vector<int> > m;
  for (int i = 0; i < n; i++) {
    m[a[i]].push_back(i);
  }
  vector<pair<int, int> > v;
  vector<int> left;
  bool visited[n];
  for (int i = 0; i < n; i++) visited[i] = false;
  for (int i = 0; i < n; i++) {
    char c = b[i];
    if (c == '?') {
      left.push_back(i);
      continue;
    }
    if (m[c].size() != 0) {
      v.push_back(make_pair(m[c].at(m[c].size() - 1), i));
      visited[m[c].at(m[c].size() - 1)] = true;
      m[c].pop_back();
    } else if (m['?'].size() != 0) {
      v.push_back(make_pair(m['?'].at(m['?'].size() - 1), i));
      visited[m['?'].at(m['?'].size() - 1)] = true;
      m['?'].pop_back();
    }
  }
  for (int i = 0; i < n && left.size() != 0; i++) {
    if (!visited[i]) {
      v.push_back(make_pair(i, left.at(left.size() - 1)));
      left.pop_back();
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
  }
  return 0;
}
