#include <bits/stdc++.h>
using namespace std;
long long gi() {
  long long res = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
  return (res * w);
}
const long long Mod = 1e9 + 7;
long long fpow(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % Mod;
    x = 1ll * x * x % Mod;
    y >>= 1;
  }
  return (res);
}
const long long MAX_N = 2e5 + 5;
long long N, cnt;
char s[MAX_N];
long long buc[3];
long long f[MAX_N], g[MAX_N];
signed main() {
  cin >> N;
  scanf("%s", s + 1);
  for (long long i = 1; i <= N; i++) cnt += s[i] == '?';
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    if (s[i] == '?') continue;
    if (s[i] == 'a')
      buc[0]++;
    else if (s[i] == 'b')
      buc[1] += buc[0], buc[1] %= Mod;
    else
      ans = (ans + buc[1]) % Mod;
  }
  ans = 1ll * ans * fpow(3, cnt) % Mod;
  for (long long i = 1; i <= N; i++) f[i] = f[i - 1] + (s[i] == 'a');
  for (long long i = N; i; i--) g[i] = g[i + 1] + (s[i] == 'c');
  long long res = 0;
  for (long long i = 2; i < N; i++)
    if (s[i] == '?') res = (res + 1ll * f[i - 1] * g[i + 1]) % Mod;
  if (cnt) ans = (ans + 1ll * res * fpow(3, cnt - 1)) % Mod;
  buc[0] = buc[1] = buc[2] = res = 0;
  for (long long i = 1; i <= N; i++) {
    if (s[i] == 'a')
      ++buc[0];
    else if (s[i] == 'b')
      buc[1] += buc[0], buc[1] %= Mod;
    if (s[i] == '?') res = (res + buc[1]) % Mod;
  }
  if (cnt) ans = (ans + 1ll * res * fpow(3, cnt - 1)) % Mod;
  buc[0] = buc[1] = buc[2] = res = 0;
  for (long long i = N; i; i--) {
    if (s[i] == 'c')
      ++buc[0];
    else if (s[i] == 'b')
      buc[1] += buc[0], buc[1] %= Mod;
    if (s[i] == '?') res = (res + buc[1]) % Mod;
  }
  if (cnt) ans = (ans + 1ll * res * fpow(3, cnt - 1)) % Mod;
  buc[0] = buc[1] = buc[2] = res = 0;
  for (long long i = 1; i <= N; i++) {
    if (s[i] == '?') ++buc[0];
    if (s[i] == 'c') res = (res + 1ll * buc[0] * (buc[0] - 1) / 2) % Mod;
  }
  if (cnt > 1) ans = (ans + 1ll * res * fpow(3, cnt - 2)) % Mod;
  buc[0] = buc[1] = buc[2] = res = 0;
  for (long long i = N; i; i--) {
    if (s[i] == '?') ++buc[0];
    if (s[i] == 'a') res = (res + 1ll * buc[0] * (buc[0] - 1) / 2) % Mod;
  }
  if (cnt > 1) ans = (ans + 1ll * res * fpow(3, cnt - 2)) % Mod;
  res = 0;
  for (long long i = 1; i <= N; i++) f[i] = f[i - 1] + (s[i] == '?');
  for (long long i = N; i; i--) g[i] = g[i + 1] + (s[i] == '?');
  for (long long i = 1; i <= N; i++)
    if (s[i] == 'b') res = (res + 1ll * f[i - 1] * g[i + 1]) % Mod;
  if (cnt > 1) ans = (ans + 1ll * res * fpow(3, cnt - 2)) % Mod;
  res = 1ll * cnt * (cnt - 1) * (cnt - 2) / 6 % Mod;
  if (cnt > 2) ans = (ans + 1ll * res * fpow(3, cnt - 3)) % Mod;
  cout << ans << endl;
  return (0);
}
