#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int oo = 1e9 + 7;
char a[N];
int cnt[N][4];
long long m3[N];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", a + 1);
  m3[0] = 1;
  for (int i = 1; i <= n; ++i) {
    m3[i] = m3[i - 1] * 3 % oo;
    cnt[i][0] = cnt[i - 1][0] + (a[i] == '?');
    cnt[i][1] = cnt[i - 1][1] + (a[i] == 'a');
    cnt[i][2] = cnt[i - 1][2] + (a[i] == 'b');
    cnt[i][3] = cnt[i - 1][3] + (a[i] == 'c');
  }
  long long ans = 0;
  for (int i = 2; i < n; ++i) {
    if (a[i] != '?' && a[i] != 'b') continue;
    long long front_a = cnt[i - 1][1], back_c = cnt[n][3] - cnt[i][3];
    long long front_q = cnt[i - 1][0], back_q = cnt[n][0] - cnt[i][0];
    ans += front_a * back_c % oo * m3[front_q] % oo * m3[back_q] % oo;
    if (back_q > 0)
      ans += front_a * back_q % oo * m3[front_q] % oo * m3[back_q - 1] % oo;
    if (front_q > 0)
      ans += back_c * front_q % oo * m3[front_q - 1] % oo * m3[back_q] % oo;
    if (front_q > 0 && back_q > 0)
      ans += front_q * back_q % oo * m3[front_q - 1] % oo * m3[back_q - 1] % oo;
    if (0) printf("%d: %lld\n", i, ans);
  }
  ans %= oo;
  printf("%lld\n", ans);
  return 0;
}
