#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long mod = 1e9 + 7;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long>> dp(n + 1, vector<long long>(3));
  s = "#" + s;
  long long esc = 0;
  for (long long i = 1; i <= n; i++) {
    if (s[i] == 'a') {
      dp[i][0] = dp[i - 1][0] + binpow(3, esc);
      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][2] = dp[i - 1][2];
      dp[i][1] = (dp[i - 1][1] + dp[i - 1][0]) % mod;
    } else if (s[i] == 'c') {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = (dp[i - 1][2] + dp[i - 1][1]) % mod;
    } else {
      dp[i][0] = (dp[i - 1][0] * 3 % mod + binpow(3, esc)) % mod;
      dp[i][1] = (dp[i - 1][1] * 3 % mod + dp[i - 1][0]) % mod;
      dp[i][2] = (dp[i - 1][2] * 3 % mod + dp[i - 1][1]) % mod;
      esc++;
    }
  }
  cout << dp[n][2] << '\n';
}
