#include <bits/stdc++.h>
using namespace std;
void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
long long n;
string s;
long long dp[3][200005];
int main() {
  Fast_IO();
  cin >> n >> s;
  for (long long i = (long long)0; i <= (long long)2; i++)
    for (long long j = (long long)0; j <= (long long)n; j++) dp[i][j] = 0;
  long long adder[n];
  for (long long i = (long long)0; i <= (long long)n - 1; i++) adder[i] = 0;
  long long assign = 1;
  for (long long i = (long long)n - 1; i >= (long long)0; i--) {
    adder[i] = assign;
    if (s[i] == '?') {
      assign *= 3;
      assign %= 1000000007;
    }
  }
  for (long long i = (long long)n - 1; i >= (long long)0; i--) {
    if (s[i] != '?') {
      dp[0][i] += dp[0][i + 1];
      dp[0][i] %= 1000000007;
      dp[1][i] += dp[1][i + 1];
      dp[1][i] %= 1000000007;
      dp[2][i] += dp[2][i + 1];
      dp[2][i] %= 1000000007;
      if (s[i] == 'a') dp[0][i] = (dp[0][i] + dp[1][i + 1]) % 1000000007;
      if (s[i] == 'b') dp[1][i] = (dp[1][i] + dp[2][i + 1]) % 1000000007;
      if (s[i] == 'c') dp[2][i] = (dp[2][i] + adder[i]) % 1000000007;
    } else {
      dp[0][i] += 3 * dp[0][i + 1];
      dp[0][i] %= 1000000007;
      dp[1][i] += 3 * dp[1][i + 1];
      dp[1][i] %= 1000000007;
      dp[2][i] += 3 * dp[2][i + 1];
      dp[2][i] %= 1000000007;
      dp[0][i] = (dp[0][i] + dp[1][i + 1]) % 1000000007;
      dp[1][i] = (dp[1][i] + dp[2][i + 1]) % 1000000007;
      dp[2][i] = (dp[2][i] + adder[i]) % 1000000007;
    }
  }
  cout << dp[0][0];
  return 0;
}
