#include <bits/stdc++.h>
using namespace std;
long long n, dp[200000 + 10][5];
char s[200000 + 10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> (s + 1);
  long long put = 1;
  for (long long i = 1; i <= n; i++) {
    if (s[i] == '?') {
      dp[i][0] = (dp[i - 1][0] * 3 + put) % 1000000007;
      dp[i][1] = (dp[i - 1][1] * 3 + dp[i - 1][0]) % 1000000007;
      dp[i][2] = (dp[i - 1][2] * 3 + dp[i - 1][1]) % 1000000007;
      put = put * 3 % 1000000007;
    } else if (s[i] == 'a') {
      dp[i][0] = (dp[i - 1][0] + put) % 1000000007;
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = dp[i - 1][2];
    } else if (s[i] == 'b') {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = (dp[i - 1][1] + dp[i - 1][0]) % 1000000007;
      dp[i][2] = dp[i - 1][2];
    } else {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = (dp[i - 1][1] + dp[i - 1][2]) % 1000000007;
    }
  }
  cout << dp[n][2] << '\n';
  return 0;
}
