#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int exp(long long int x, long long int y, long long int mod) {
  long long int res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long int modinverse(long long int x, long long int mod) {
  return exp(x, mod - 2, mod);
}
using namespace std;
const long long int inf = 0x3f3f3f3f3f3f3f3fll;
long long int dp[200010][4][4];
void solve() {
  string s;
  long long int n, cnt = 0, mod = 1e9 + 7;
  cin >> n;
  cin >> s;
  vector<long long int> po3(n + 1);
  po3[0] = 1;
  for (long long int i = 1; i < n + 1; i++) po3[i] = (po3[i - 1] * 3) % mod;
  dp[0][0][0] = 1;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '?') cnt++;
    for (long long int j = 0; j < 4; j++) {
      for (long long int k = 0; k < 4; k++) {
        if (!dp[i][j][k]) continue;
        dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod;
        if (j < 3 && (s[i] == '?' || s[i] - 'a' == j)) {
          long long int kk = (s[i] == '?') ? k + 1 : k;
          dp[i + 1][j + 1][kk] = (dp[i + 1][j + 1][kk] + dp[i][j][k]) % mod;
        }
      }
    }
  }
  long long int res = 0;
  for (long long int i = 0; i < 4; i++) {
    if (cnt >= i) res = (res + (po3[cnt - i] * dp[n][3][i]) % mod) % mod;
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
