#include <bits/stdc++.h>
using namespace std;
int read() {
  int tot = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    tot = tot * 10 + c - '0';
    c = getchar();
  }
  return tot * fh;
}
void getstr(char *a) {
  char c = getchar();
  int len = 0;
  while (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
           (c >= '0' && c <= '9') || (c == '?')))
    c = getchar();
  while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
         (c >= '0' && c <= '9') || (c == '?')) {
    a[++len] = c;
    c = getchar();
  }
}
const int maxn = 200010;
const int mo = 1000000007;
int n;
long long num, ans[5];
char s[maxn];
int main() {
  n = read();
  getstr(s);
  num = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'c') ans[3] = (ans[3] + ans[2]) % mo;
    if (s[i] == 'b') ans[2] = (ans[2] + ans[1]) % mo;
    if (s[i] == 'a') ans[1] = (ans[1] + num) % mo;
    if (s[i] == '?') {
      ans[3] = (ans[3] * 3ll % mo + ans[2] % mo) % mo;
      ans[2] = (ans[2] * 3ll % mo + ans[1] % mo) % mo;
      ans[1] = (ans[1] * 3ll + num) % mo;
      num = num * 3ll % mo;
    }
  }
  cout << ans[3] << endl;
  return 0;
}
