#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1000000007;
int64_t power(int x, int p) {
  if (p == 0) return 1;
  return (x * power(x, p - 1)) % mod;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int K = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '?') K++;
  }
  int64_t dp[n + 1][4][4];
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= 3; ++j) {
      for (int k = 0; k <= 3; ++k) {
        dp[i][j][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 3; ++j) {
      for (int k = 0; k <= j; ++k) {
        dp[i][j][k] += dp[i - 1][j][k];
        dp[i][j][k] = dp[i][j][k] % mod;
        if (s[i - 1] - 'a' + 1 == j) {
          dp[i][j][k] += dp[i - 1][j - 1][k];
        } else if (s[i - 1] == '?' && k > 0) {
          dp[i][j][k] += dp[i - 1][j - 1][k - 1];
        }
        dp[i][j][k] = dp[i][j][k] % mod;
      }
    }
  }
  int64_t ans = 0;
  for (int k = 0; k <= 3 && k <= K; ++k) {
    ans += (((dp[n][3][k]) % mod) * (power(3, K - k))) % mod;
    ans = ans % mod;
  }
  cout << ans;
  return 0;
}
