#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 0x3f3f3f3f, mod = 1000000007;
long long qmod(long long a, long long b, long long mod) {
  long long ans = 1;
  a = a % mod;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
char s[maxn];
long long dp[maxn][4];
signed main(signed argc, char const *argv[]) {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, cnt = 0;
  cin >> n >> s + 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'a') {
      dp[i][0] = dp[i - 1][0] + qmod(3, cnt, mod);
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = dp[i - 1][2];
    } else 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];
    } else 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][0] = dp[i - 1][0] * 3 + qmod(3, cnt, mod);
      dp[i][1] = dp[i - 1][1] * 3 + dp[i - 1][0];
      dp[i][2] = dp[i - 1][2] * 3 + dp[i - 1][1];
      cnt++;
    }
    for (int j = 0; j < 4; j++) dp[i][j] %= mod;
  }
  cout << dp[n][2] << endl;
  return 0;
}
