#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, N = 1e5 + 5;
long long power(long long x, unsigned long long y) {
  long long res = 1;
  x = x % MOD;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % MOD;
    y = y >> 1;
    x = (x * x) % MOD;
  }
  return res;
}
array<long long, 4> find(long long u, vector<array<long long, 4>> &dp,
                         string &s) {
  if (u < 0) return {0, 0, 0, 0};
  array<long long, 4> x, ans;
  x = find(u - 1, dp, s);
  if (s[u] != '?') {
    if (s[u] == 'a')
      x[2] += power(3, x[3]);
    else if (s[u] == 'b')
      x[1] += x[2];
    else
      x[0] += x[1];
    for (long long i = (long long)0; i < 4; i++) x[i] %= MOD;
    return dp[u] = x;
  } else {
    ans[0] = 3 * x[0] + x[1];
    ans[1] = 3 * x[1] + x[2];
    ans[2] = 3 * x[2] + power(3, x[3]);
    ans[3] = x[3] + 1;
    for (long long i = (long long)0; i < 4; i++) ans[i] %= MOD;
    return dp[u] = ans;
  }
}
long long solve() {
  long long n;
  string s;
  cin >> n >> s;
  vector<array<long long, 4>> dp(n);
  long long ans = find(n - 1, dp, s)[0];
  return ans;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << solve() << '\n';
}
