#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  long long dp[3] = {0, 0, 0}, cnt = 1;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'a') {
      dp[0] = (dp[0] + cnt) % M;
    } else if (str[i] == 'b') {
      dp[1] = (dp[0] + dp[1]) % M;
    } else if (str[i] == 'c') {
      dp[2] = (dp[1] + dp[2]) % M;
    } else {
      dp[2] = (dp[2] * 3 + dp[1]) % M;
      dp[1] = (dp[1] * 3 + dp[0]) % M;
      dp[0] = (dp[0] * 3 + cnt) % M;
      cnt = (cnt * 3) % M;
    }
  }
  cout << dp[2] << endl;
  return 0;
}
