#include <bits/stdc++.h>
using namespace std;
int in(char &c) { return scanf("%c", &c); }
int in(char s[]) { return scanf("%s", s); }
int in(int &x) { return scanf("%d", &x); }
int in(long long &x) { return scanf("%lld", &x); }
int in(double &x) { return scanf("%lf", &x); }
int in(pair<int, int> &p) { return scanf("%d%d", &p.first, &p.second); }
int in(pair<long long, long long> &p) {
  return scanf("%lld%lld", &p.first, &p.second);
}
int in(pair<double, double> &p) { return scanf("%lf%lf", &p.first, &p.second); }
int in(long double &a) { return scanf("%Lf", &a); }
int in(int &x, long long &y) { return scanf("%d%lld", &x, &y); }
int in(long long &x, int &y) { return scanf("%lld%d", &x, &y); }
int in(int &x, int &y) { return scanf("%d%d", &x, &y); }
int in(long long &x, long long &y) { return scanf("%lld%lld", &x, &y); }
int in(char s[], int &n) { return scanf("%s%d", s, &n); }
int in(int &n, char s[]) { return scanf("%d%s", &n, s); }
int in(char a[], char b[]) { return scanf("%s%s", a, b); }
int in(double &x, double &y) { return scanf("%lf%lf", &x, &y); }
int in(int &n, char s[], char t[]) { return scanf("%d%s%s", &n, s, t); }
int in(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int in(long long &x, long long &y, long long &z) {
  return scanf("%lld%lld%lld", &x, &y, &z);
}
int in(double &x, double &y, double &z) {
  return scanf("%lf%lf%lf", &x, &y, &z);
}
int in(int &x, int &y, int &z, int &k) {
  return scanf("%d%d%d%d", &x, &y, &z, &k);
}
int in(long long &x, long long &y, long long &z, long long &k) {
  return scanf("%lld%lld%lld%lld", &x, &y, &z, &k);
}
int in(double &x, double &y, double &z, double &k) {
  return scanf("%lf%lf%lf%lf", &x, &y, &z, &k);
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
const int N = 3e5 + 10, M = 1e3 + 10, mod = 1e9 + 7;
const double eps = 1e-6, Pi = acos(-1.0);
char s[N];
long long dp[N][3];
int main() {
  int n;
  in(n, s + 1);
  long long ans = 0, cnt = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) dp[i][j] = dp[i - 1][j];
    if (s[i] == 'a') {
      dp[i][0] += cnt;
    } else if (s[i] == 'b') {
      dp[i][1] += dp[i - 1][0];
    } else if (s[i] == 'c') {
      dp[i][2] += dp[i - 1][1];
    } else {
      for (int j = 0; j < 3; j++) dp[i][j] = dp[i - 1][j] * 3;
      dp[i][2] += dp[i - 1][1];
      dp[i][1] += dp[i - 1][0];
      dp[i][0] += cnt;
      cnt *= 3;
    }
    for (int j = 0; j < 3; j++) {
      dp[i][j] %= mod;
    }
    cnt %= mod;
  }
  printf("%lld\n", dp[n][2]);
  return 0;
}
