#include <bits/stdc++.h>
long long md = 1000000007;
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, cnt = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long> > dp(3, vector<long long>(n + 1, 0));
  for (long long i = 0; i < n; i++) {
    if (s[i] == '?') {
      long long z = power(3ll, cnt, md);
      dp[0][i + 1] = (3ll * dp[0][i] + z) % md;
      dp[1][i + 1] = (dp[0][i] + 3ll * dp[1][i]) % md;
      dp[2][i + 1] = (dp[1][i] + 3ll * dp[2][i]) % md;
      cnt++;
    } else if (s[i] == 'a') {
      long long z = power(3ll, cnt, md);
      dp[0][i + 1] = (dp[0][i] + z) % md;
      dp[1][i + 1] = dp[1][i];
      dp[2][i + 1] = dp[2][i];
    } else if (s[i] == 'b') {
      dp[0][i + 1] = dp[0][i];
      dp[1][i + 1] = (dp[0][i] + dp[1][i]) % md;
      dp[2][i + 1] = dp[2][i];
    } else {
      dp[0][i + 1] = dp[0][i];
      dp[1][i + 1] = dp[1][i];
      dp[2][i + 1] = (dp[1][i] + dp[2][i]) % md;
    }
  }
  cout << dp[2][n] << endl;
  return 0;
}
