#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
char s[N];
int dp[4];
int main() {
  int len;
  scanf("%d%s", &len, s + 1);
  dp[0] = 1;
  for (int i = 1; i <= len; i++) {
    if (s[i] == 'a') {
      dp[1] = (1ll * dp[1] + dp[0]) % mod;
    }
    if (s[i] == 'b') {
      dp[2] = (1ll * dp[2] + dp[1]) % mod;
    }
    if (s[i] == 'c') {
      dp[3] = (1ll * dp[3] + dp[2]) % mod;
    }
    if (s[i] == '?') {
      int t0 = dp[0];
      int t1 = dp[1];
      int t2 = dp[2];
      dp[0] = 3ll * dp[0] % mod;
      dp[1] = (3ll * dp[1] + t0) % mod;
      dp[2] = (3ll * dp[2] + t1) % mod;
      dp[3] = (3ll * dp[3] + t2) % mod;
    }
  }
  std::cout << dp[3];
  return 0;
}
