#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long inf = 100000000000011;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  set<pair<char, int>> x, y, l, r;
  int cnt1 = 0;
  int cnt2 = 0;
  vector<int> v1, v2;
  for (int i = 0; i < n; i++) {
    if (a[i] != '?') {
      x.insert({a[i], i + 1});
    } else {
      v1.push_back(i + 1);
      cnt1++;
    }
    if (b[i] != '?')
      y.insert({b[i], i + 1});
    else {
      v2.push_back(i + 1);
      cnt2++;
    }
  }
  vector<pair<int, int>> ans;
  while (x.size() > 0 && y.size() > 0) {
    auto it = x.begin();
    auto it1 = y.begin();
    if (it->first == it1->first) {
      ans.push_back({it->second, it1->second});
      x.erase(it);
      y.erase(it1);
    } else if (it->first < it1->first) {
      l.insert({it->first, it->second});
      x.erase(it);
    } else {
      r.insert({it1->first, it1->second});
      y.erase(it1);
    }
  }
  while (x.size() > 0) {
    auto it = x.begin();
    l.insert({it->first, it->second});
    x.erase(it);
  }
  while (y.size() > 0) {
    auto it = y.begin();
    r.insert({it->first, it->second});
    y.erase(it);
  }
  int i = 0;
  auto it = r.begin();
  while (i < v1.size() && it != r.end()) {
    ans.push_back({v1[i], it->second});
    i++;
    it++;
  }
  int j = 0;
  it = l.begin();
  while (j < v2.size() && it != l.end()) {
    ans.push_back({it->second, v2[j]});
    j++;
    it++;
  }
  while (i < v1.size() && j < v2.size()) {
    ans.push_back({v1[i], v2[j]});
    i++;
    j++;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
