#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
void setIO(string name, int submit) {
  if (submit) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  } else {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
}
long long dp[200001][4][4];
long long exp(int a, int b) {
  long long res = 1;
  while (b-- > 0) {
    res *= a;
    res %= MOD;
  }
  return res % MOD;
}
int main() {
  setIO("", 0);
  int N;
  cin >> N;
  string s = " ";
  string temp;
  cin >> temp;
  s += temp;
  string abc = "abc";
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++) {
    if (s[i] != '?') {
      int cc = s[i] - 'a';
      for (int j = 0; j < 3; j++) {
        dp[i][cc + 1][j] += dp[i - 1][cc][j];
        dp[i][cc + 1][j] %= MOD;
      }
    }
    if (s[i] == '?') {
      for (int cc = 0; cc < 3; cc++) {
        for (int j = 0; j < 3; j++) {
          dp[i][cc + 1][j + 1] += dp[i - 1][cc][j];
          dp[i][cc + 1][j + 1] %= MOD;
        }
      }
    }
    for (int cc = 0; cc < 4; cc++) {
      for (int j = 0; j < 4; j++) {
        dp[i][cc][j] += dp[i - 1][cc][j];
        dp[i][cc][j] %= MOD;
      }
    }
  }
  long long ans = 0;
  int qmarks = 0;
  for (int i = 0; i <= N; i++) {
    if (s[i] == '?') qmarks++;
  }
  for (int i = 0; i <= 3; i++) {
    ans += dp[N][3][i] * exp(3, qmarks - i);
    ans %= MOD;
  }
  cout << ans % MOD << "\n";
  return 0;
}
