#include <bits/stdc++.h>
using namespace std;
const long long oo = int(1e9);
const long long N = 2 * int(1e5) + 5;
const long long mod = oo + 7;
long long n, f[4], pow3[N], dem;
char a[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> a + 1;
  pow3[0] = 1;
  for (long long i = 1; i <= n; i++) pow3[i] = pow3[i - 1] * 3 % mod;
  dem = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 'a')
      f[1] = (f[1] + pow3[dem]) % mod;
    else if (a[i] == 'b')
      f[2] = (f[2] + f[1]) % mod;
    else if (a[i] == 'c')
      f[3] = (f[3] + f[2]) % mod;
    else if (a[i] == '?') {
      f[3] = (f[3] * 3 % mod + f[2]) % mod;
      f[2] = (f[2] * 3 % mod + f[1]) % mod;
      f[1] = (f[1] * 3 % mod + pow3[dem]) % mod;
      dem++;
    }
  }
  cout << f[3];
}
