#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
map<long long, int> mp;
int n;
long long dp[N][3];
char s[N];
int main() {
  long long sza = 1;
  cin >> n;
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] != '?') {
      if (s[i] == 'a') {
        dp[i][0] = dp[i - 1][0] + sza;
        dp[i][1] = dp[i - 1][1];
        dp[i][2] = dp[i - 1][2];
      }
      if (s[i] == 'b') {
        dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
        dp[i][0] = dp[i - 1][0];
        dp[i][2] = dp[i - 1][2];
      }
      if (s[i] == 'c') {
        dp[i][2] = dp[i - 1][2] + dp[i - 1][1];
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = dp[i - 1][1];
      }
    } else {
      dp[i][2] = dp[i - 1][2] * 3 + dp[i - 1][1];
      dp[i][1] = dp[i - 1][1] * 3 + dp[i - 1][0];
      dp[i][0] = dp[i - 1][0] * 3 + sza;
      sza *= 3;
    }
    dp[i][0] %= mod;
    dp[i][1] %= mod;
    dp[i][2] %= mod;
    sza %= mod;
  }
  cout << dp[n][2] << endl;
}
