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