#include <bits/stdc++.h>
using namespace std;
long long const max1 = 3e5 + 5;
long long const mod = 998244353;
long long inf = 1e18;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long tc = 1;
  while (tc--) {
    long long n;
    cin >> n;
    map<char, stack<long long>> left, right;
    string l, r;
    cin >> l >> r;
    char c = '}';
    for (long long i = 0; i < n; i++) {
      if (l[i] == '?') {
        l[i] = c;
      }
      left[l[i]].push(i + 1);
    }
    for (long long i = 0; i < n; i++) {
      if (r[i] == '?') {
        r[i] = c;
      }
      right[r[i]].push(i + 1);
    }
    vector<pair<long long, long long>> ans;
    for (auto &x : left) {
      while (!x.second.empty() && !right[x.first].empty()) {
        long long a, b;
        a = x.second.top();
        b = right[x.first].top();
        ans.push_back({a, b});
        x.second.pop();
        right[x.first].pop();
      }
      while (!x.second.empty() && !right[c].empty()) {
        long long a, b;
        a = x.second.top();
        b = right[c].top();
        ans.push_back({a, b});
        x.second.pop();
        right[c].pop();
      }
    }
    for (auto &x : right) {
      while (!x.second.empty() && !left[x.first].empty()) {
        long long a, b;
        a = x.second.top();
        b = left[x.first].top();
        ans.push_back({b, a});
        x.second.pop();
        left[x.first].pop();
      }
      while (!x.second.empty() && !left[c].empty()) {
        long long a, b;
        a = x.second.top();
        b = left[c].top();
        ans.push_back({b, a});
        x.second.pop();
        left[c].pop();
      }
    }
    cout << ans.size() << "\n";
    for (auto x : ans) {
      cout << x.first << " " << x.second << "\n";
    }
  }
}
