#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
char F[200];
inline void out(long long x) {
  if (x == 0) return (void)(putchar('0'));
  long long tmp = x > 0 ? x : -x;
  if (x < 0) putchar('-');
  int cnt = 0;
  while (tmp > 0) {
    F[cnt++] = tmp % 10 + '0';
    tmp /= 10;
  }
  while (cnt > 0) putchar(F[--cnt]);
}
long long ksm(long long a, long long b, long long p) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return res;
}
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5 + 7, N = 1e7 + 10;
const double PI = atan(1.0) * 4;
const double eps = 1e-6;
char s[maxn];
long long dp[maxn][4];
int main() {
  int n;
  long long tmp = 1;
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'a') {
      dp[i][1] = (dp[i - 1][1] + tmp) % mod;
      dp[i][2] = (dp[i - 1][2]) % mod;
      dp[i][3] = (dp[i - 1][3]) % mod;
    } else if (s[i] == 'b') {
      dp[i][1] = (dp[i - 1][1]) % mod;
      dp[i][2] = (dp[i - 1][2] + dp[i - 1][1]) % mod;
      dp[i][3] = (dp[i - 1][3]) % mod;
    } else if (s[i] == 'c') {
      dp[i][1] = (dp[i - 1][1]) % mod;
      dp[i][2] = (dp[i - 1][2]) % mod;
      dp[i][3] = (dp[i - 1][3] + dp[i - 1][2]) % mod;
    } else if (s[i] == '?') {
      dp[i][1] = (dp[i - 1][1] * 3 + tmp) % mod;
      dp[i][2] = (dp[i - 1][2] * 3 + dp[i - 1][1]) % mod;
      dp[i][3] = (dp[i - 1][3] * 3 + dp[i - 1][2]) % mod;
      tmp = tmp * 3 % mod;
    }
  }
  out(dp[n][3]);
  return 0;
}
