#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const long long INF = 2e5 + 5;
char s[INF];
long long dp[INF][4];
int main() {
  int n;
  long long m = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    dp[i][1] = dp[i - 1][1];
    dp[i][2] = dp[i - 1][2];
    dp[i][3] = dp[i - 1][3];
    if (s[i] == 'a') dp[i][1] = (dp[i - 1][1] + m) % Mod;
    if (s[i] == 'b') dp[i][2] = (dp[i - 1][2] + dp[i - 1][1]) % Mod;
    if (s[i] == 'c') dp[i][3] = (dp[i - 1][3] + dp[i - 1][2]) % Mod;
    if (s[i] == '?') {
      dp[i][1] = (dp[i - 1][1] * 3 + m) % Mod;
      m = m * 3 % Mod;
      dp[i][2] = (dp[i - 1][2] * 3 + dp[i - 1][1]) % Mod;
      dp[i][3] = (dp[i - 1][3] * 3 + dp[i - 1][2]) % Mod;
    }
  }
  cout << dp[n][3];
  return 0;
}
