#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  string s2 = "abc";
  long long dp[4][n + 1];
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    if (s[i - 1] == '?') {
      dp[0][i] = (3 * dp[0][i - 1]) % 1000000007;
    } else {
      dp[0][i] = dp[0][i - 1];
    }
  }
  for (long long i = 1; i <= 3; i++) {
    dp[i][0] = 0;
  }
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= n; j++) {
      if (s[j - 1] == '?') {
        dp[i][j] = (3 * dp[i][j - 1] + dp[i - 1][j - 1]) % 1000000007;
      } else if (s[j - 1] == s2[i - 1]) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % 1000000007;
      } else {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }
  long long ans = dp[3][n] % 1000000007;
  cout << ans;
  return 0;
}
