#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  int n;
  string s;
  cin >> n >> s;
  long long as = 0, abs = 0, abcs = 0;
  long long all = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') {
      as = (as + all) % MOD;
    } else if (s[i] == 'b') {
      abs = (abs + as) % MOD;
    } else if (s[i] == 'c') {
      abcs = (abcs + abs) % MOD;
    } else if (s[i] == '?') {
      abcs = (3 * abcs + abs) % MOD;
      abs = (3 * abs + as) % MOD;
      as = (3 * as + all) % MOD;
      all = (all * 3) % MOD;
    }
  }
  cout << abcs << '\n';
}
