#include <bits/stdc++.h>
using namespace std;
const long long int mo = 1e9 + 7;
long long int binpow(long long int a, long long int b, long long int m) {
  if (b < 0) return 0;
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int q1 = 0, a = 0, q2 = 0, c = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '?') q2++;
    if (s[i] == 'c') c++;
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == '?') q2--;
    if (s[i] == '?' || s[i] == 'b') {
      long long int te1 =
          ((a * binpow(3, q1, mo)) % mo + (q1 * binpow(3, q1 - 1, mo)) % mo) %
          mo;
      long long int te2 =
          ((c * binpow(3, q2, mo)) % mo + (q2 * binpow(3, q2 - 1, mo)) % mo) %
          mo;
      ans = (ans + (te1 * te2) % mo) % mo;
    }
    if (s[i] == '?') q1++;
    if (s[i] == 'a') a++;
    if (s[i] == 'c') c--;
  }
  cout << ans;
}
