#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
template <typename T1, typename T2>
inline bool chkmin(T1& x, const T2& y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chkmax(T1& x, const T2& y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
using namespace std;
const long long maxn = 2e5 + 20;
ostream& operator<<(ostream& out, vector<long long>& v) {
  for (auto& x : v) out << x << ' ';
  return out;
}
ostream& operator<<(ostream& out, pair<long long, long long>& v) {
  out << v.first << ", " << v.second;
  return out;
}
istream& operator>>(istream& in, pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
const long long inf = (long long)2e9;
const long double pi = asin(1) * 2;
const long double eps = 1e-8;
const long long mod = (long long)1e9 + 7;
const long long ns = 97;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
long long dp[3], f[maxn];
long long mult(long long a, long long b) { return a * b % mod; }
long long add(long long a, long long b) {
  long long c = a + b;
  if (c >= mod) c -= mod;
  if (c < 0) c += mod;
  return c;
}
long long powmod(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2) return mult(a, powmod(a, n - 1));
  long long b = powmod(a, n / 2);
  return mult(b, b);
}
long long inv(long long a) { return powmod(a, mod - 2); }
long long kek(long long t) { return add(powmod(3, t), -powmod(2, t)); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = 1, t = 0;
  for (long long i = (long long)s.size() - 1; i >= 0; --i) {
    if (s[i] == 'c') {
      dp[2] = add(dp[2], powmod(3, t));
    } else if (s[i] == 'b') {
      dp[1] = add(dp[1], dp[2]);
    } else if (s[i] == 'a') {
      dp[0] = add(dp[0], dp[1]);
    } else {
      dp[0] = add(add(dp[0], dp[0]), add(dp[0], dp[1]));
      dp[1] = add(add(dp[1], dp[1]), add(dp[1], dp[2]));
      dp[2] = add(add(dp[2], dp[2]), add(dp[2], powmod(3, t)));
      ++t;
    }
    for (auto& x : dp)
      ;
    ;
  }
  cout << dp[0] << '\n';
}
