#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1000005;
const double eps = 1e-8;
const int mod = 1e9 + 7;
int n, m;
long long a[N];
long long f1[N], f2[N], f3[N];
int main() {
  int i, j;
  cin >> n;
  a[0] = 1;
  for (i = 1; i <= n; i++) {
    a[i] = a[i - 1] * 3 % mod;
  }
  string s;
  cin >> s;
  int flag = 0;
  for (i = 1; i <= s.size(); i++) {
    char c = s[i - 1];
    if (c == 'a') {
      f1[i] = (f1[i - 1] + a[flag]) % mod;
      f2[i] = f2[i - 1];
      f3[i] = f3[i - 1];
    } else if (c == 'b') {
      f1[i] = f1[i - 1];
      f2[i] = (f2[i - 1] + f1[i - 1]) % mod;
      f3[i] = f3[i - 1];
    } else if (c == 'c') {
      f1[i] = f1[i - 1];
      f2[i] = f2[i - 1];
      f3[i] = (f3[i - 1] + f2[i - 1]) % mod;
    } else if (c == '?') {
      f1[i] = (f1[i - 1] * 3 + a[flag]) % mod;
      f2[i] = (f2[i - 1] * 3 + f1[i - 1]) % mod;
      f3[i] = (f3[i - 1] * 3 + f2[i - 1]) % mod;
      flag++;
    }
  }
  cout << f3[n] << endl;
  return 0;
}
