#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int P = 1e9 + 7;
char s[N + 10];
int dp[N + 10][4];
int main() {
  int n;
  cin >> n >> (s + 1);
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] != '?') {
      memcpy(dp[i], dp[i - 1], sizeof(dp[i]));
      (dp[i][s[i] - 'a' + 1] += dp[i - 1][s[i] - 'a']) %= P;
    } else {
      memcpy(dp[i], dp[i - 1], sizeof(dp[i]));
      dp[i][0] = 3ll * dp[i][0] % P;
      for (int j = 1; j <= 3; j++) {
        dp[i][j] = (3ll * dp[i][j] + dp[i - 1][j - 1]) % P;
      }
    }
  }
  cout << dp[n][3];
}
