#include <bits/stdc++.h>
using namespace std;
int n;
string s;
long long dp[200011];
const long long Mod = 1e9 + 7;
long long f[200011][3];
long long power(long long x, long long n) {
  if (n < 0) return 0;
  if (n == 0) return 1;
  if (n % 2 == 0) return power(x * x % Mod, n / 2);
  return x * power(x * x % Mod, n / 2) % Mod;
}
int main() {
  cin >> n;
  cin >> s;
  s = '.' + s;
  int c = 0;
  for (int i = n; i >= 1; i--) {
    if (s[i] == '?') c++;
  }
  long long cnt1 = 0;
  long long cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'b') {
      f[i][0] += cnt1;
      f[i][1] += cnt2;
    }
    if (s[i] == '?') {
      f[i][1] += cnt1;
      f[i][2] += cnt2;
    }
    if (s[i] == 'a') {
      cnt1++;
    }
    if (s[i] == '?') cnt2++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 2; j++) (f[i][j] += f[i - 1][j]) %= Mod;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'c') {
      ans += f[i - 1][0] * power(3, c);
      ans %= Mod;
      ans += f[i - 1][1] * power(3, c - 1);
      ans %= Mod;
      ans += f[i - 1][2] * power(3, c - 2);
      ans %= Mod;
    }
    if (s[i] == '?') {
      ans += f[i - 1][0] * power(3, c - 1);
      ans %= Mod;
      ans += f[i - 1][1] * power(3, c - 2);
      ans %= Mod;
      ans += f[i - 1][2] * power(3, c - 3);
      ans %= Mod;
    }
  }
  cout << ans;
  return 0;
}
