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