#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, j, k;
  string s;
  cin >> n >> s;
  long long dp[n + 1][4][4];
  for (i = 0; i <= n; i++) {
    for (j = 0; j < 4; ++j) {
      for (k = 0; k < 4; ++k) dp[i][j][k] = 0;
    }
  }
  for (i = 0; i <= n; i++) {
    dp[i][0][0] = 1;
  }
  for (i = 1; i <= n; i++) {
    if (s[i - 1] == '?') {
      dp[i][0][0] = (3 * dp[i - 1][0][0]) % mod;
      dp[i][1][1] = (dp[i - 1][0][0] + 3 * dp[i - 1][1][1]) % mod;
      dp[i][2][2] = (dp[i - 1][1][1] + 3 * dp[i - 1][2][2]) % mod;
      dp[i][3][3] = (dp[i - 1][2][2] + 3 * dp[i - 1][3][3]) % mod;
    } else {
      if (s[i - 1] == 'a') {
        dp[i][1][1] = (dp[i - 1][0][0] + dp[i - 1][1][1]) % mod;
        dp[i][0][0] = dp[i - 1][0][0];
        dp[i][2][2] = dp[i - 1][2][2];
        dp[i][3][3] = dp[i - 1][3][3];
      } else if (s[i - 1] == 'b') {
        dp[i][2][2] = (dp[i - 1][1][1] + dp[i - 1][2][2]) % mod;
        dp[i][0][0] = dp[i - 1][0][0];
        dp[i][1][1] = dp[i - 1][1][1];
        dp[i][3][3] = dp[i - 1][3][3];
      } else {
        dp[i][3][3] = (dp[i - 1][2][2] + dp[i - 1][3][3]) % mod;
        dp[i][0][0] = dp[i - 1][0][0];
        dp[i][1][1] = dp[i - 1][1][1];
        dp[i][2][2] = dp[i - 1][2][2];
      }
    }
  }
  cout << dp[n][3][3];
}
