#include <bits/stdc++.h>
const long double C = 0.57721566490153286060651209;
const long long N = 1000000007;
using namespace std;
long long gcd(long long a, long long b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
long long qsm(long long a, long long b) {
  long long res = 1;
  long long x = a % N;
  while (b) {
    if (b & 1) res = res % N * x % N;
    x = x * x % N;
    b >>= 1;
  }
  return res;
}
long long cntb[200005];
long long cntm[200005];
long long cnta[200005];
long long cntc[200005];
long long dp[200005];
char s[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cin >> s + 1;
  int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'b') c1++;
    if (s[i] == '?') c2++;
    if (s[i] == 'a') c3++;
    if (s[i] == 'c') c4++;
    cntb[i] = c1;
    cntm[i] = c2;
    cnta[i] = c3;
    cntc[i] = c4;
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    if (s[i] == 'b') {
      dp[i] += cnta[i - 1] * (c4 - cntc[i]) % N * qsm(3, c2) % N;
      dp[i] %= N;
      dp[i] += cnta[i - 1] * (c2 - cntm[i]) % N * qsm(3, max(c2 - 1, 0)) % N;
      dp[i] %= N;
      dp[i] += cntm[i - 1] * (c4 - cntc[i]) % N * qsm(3, max(c2 - 1, 0)) % N;
      dp[i] %= N;
      dp[i] += cntm[i - 1] * (c2 - cntm[i]) % N * qsm(3, max(c2 - 2, 0)) % N;
      dp[i] %= N;
    } else if (s[i] == '?') {
      dp[i] += cnta[i - 1] * (c4 - cntc[i]) % N * qsm(3, max(c2 - 1, 0)) % N;
      dp[i] %= N;
      dp[i] += cnta[i - 1] * (c2 - cntm[i]) % N * qsm(3, max(c2 - 2, 0)) % N;
      dp[i] %= N;
      dp[i] += cntm[i - 1] * (c4 - cntc[i]) % N * qsm(3, max(c2 - 2, 0)) % N;
      dp[i] %= N;
      dp[i] += cntm[i - 1] * (c2 - cntm[i]) % N * qsm(3, max(c2 - 3, 0)) % N;
      dp[i] %= N;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
