#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[200010][5][5];
int main() {
  int n;
  cin >> n;
  string x;
  cin >> x;
  vector<long long> pow3;
  pow3.push_back(1);
  for (int i = 1; i <= 200000; i++) {
    long long aux = (pow3[i - 1] * (long long)3) % mod;
    pow3.push_back(aux);
  }
  int q = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == '?') q++;
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k <= 3; k++) {
        if (!dp[i][j][k]) continue;
        dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod;
        if (j < 3 && (x[i] == '?' || x[i] == j + 'a')) {
          int nk;
          if (x[i] == '?') {
            nk = k + 1;
          } else {
            nk = k;
          }
          dp[i + 1][j + 1][nk] = (dp[i + 1][j + 1][nk] + dp[i][j][k]) % mod;
        }
      }
    }
  }
  long long res = 0;
  for (int i = 0; i <= 3; i++) {
    if (q >= i) {
      res += (dp[n][3][i] * pow3[q - i]) % mod;
      res %= mod;
    }
  }
  cout << res << endl;
}
