#include <bits/stdc++.h>
using namespace std;
long long dp[200005][3];
const long long mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  s = '@' + s;
  int a[n + 1];
  int i;
  for (i = 1; i <= n; i++) {
    if (s[i] >= 'a' && s[i] <= 'c')
      a[i] = (s[i] - 'a');
    else
      a[i] = -1;
  }
  long long p = 1;
  for (i = 1; i <= n; i++) {
    if (a[i] == -1) {
      dp[i][0] = ((3 * dp[i - 1][0] % mod) % mod + p) % mod;
      dp[i][1] = dp[i - 1][0];
      dp[i][1] = ((3 * dp[i - 1][1] % mod) % mod + dp[i][1] % mod) % mod;
      dp[i][2] = dp[i - 1][1];
      dp[i][2] = ((3 * dp[i - 1][2] % mod) % mod + dp[i][2] % mod) % mod;
      p = (p % mod * 3 % mod) % mod;
    } else {
      if (a[i] == 0) {
        dp[i][0] = (dp[i - 1][0] % mod + p) % mod;
        dp[i][1] = dp[i - 1][1];
        dp[i][2] = dp[i - 1][2];
      } else if (a[i] == 1) {
        dp[i][1] = dp[i - 1][0];
        dp[i][1] = (dp[i - 1][1] % mod + dp[i][1] % mod) % mod;
        dp[i][0] = dp[i - 1][0];
        dp[i][2] = dp[i - 1][2];
      } else {
        dp[i][2] = dp[i - 1][1];
        dp[i][2] = (dp[i - 1][2] % mod + dp[i][2] % mod) % mod;
        dp[i][1] = dp[i - 1][1];
        dp[i][0] = dp[i - 1][0];
      }
    }
  }
  cout << dp[n][2] << endl;
}
