#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
long long fpow(long long a, long long b) {
  long long ret = 1;
  for (a %= mod; b; b >>= 1, a = a * a % mod)
    if (b & 1) ret = ret * a % mod;
  return ret;
}
inline void solve() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  long long cnt = count(str.begin(), str.end(), '?'), sum = 0;
  vector<long long> a(3, 0), b(3, 0);
  for (const auto& i : str) {
    switch (i) {
      case 'a':
        a[0]++;
        break;
      case 'b':
        for (int j = 0; j != 3; j++) b[j] += a[j], b[j] %= mod;
        break;
      case 'c':
        for (int j = 0; j < 3; j++)
          sum += b[j] * fpow(3, max(0ll, cnt - j)), sum %= mod;
        break;
      case '?':
        for (int j = 0; j < 3; j++)
          sum += b[j] * fpow(3, max(0ll, cnt - j - 1)), sum %= mod;
        sum %= mod;
        for (int j = 1; j < 3; j++) b[j] += a[j - 1], b[j] %= mod;
        a[1]++;
        break;
    }
  }
  cout << sum << '\n';
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
