#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
long long dp[maxn][5];
char str[maxn];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", str + 1);
  int h = strlen(str + 1);
  long long cnt = 1;
  for (int i = 1; i <= h; i++) {
    if (str[i] == 'a') {
      dp[i][0] = (dp[i - 1][0] + cnt) % mod;
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = dp[i - 1][2];
    }
    if (str[i] == 'b') {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = (dp[i - 1][1] + dp[i - 1][0]) % mod;
      dp[i][2] = dp[i - 1][2];
    }
    if (str[i] == 'c') {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = (dp[i - 1][2] + dp[i - 1][1]) % mod;
    }
    if (str[i] == '?') {
      dp[i][0] = (dp[i - 1][0] * 3 + cnt) % mod;
      dp[i][1] = (dp[i - 1][1] * 3 + dp[i - 1][0]) % mod;
      dp[i][2] = (dp[i - 1][2] * 3 + dp[i - 1][1]) % mod;
      cnt = (cnt * 3) % mod;
    }
  }
  printf("%lld\n", dp[n][2]);
}
