#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5;
const long long Mod = 1e9 + 7;
const long long INF = 1e9 + 1;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<long long> p(n);
  p[0] = 1;
  for (int i = 1; i < n; i++) p[i] = p[i - 1] * 3 % Mod;
  string s;
  cin >> s;
  vector<long long> L(4), R(4);
  for (char& i : s) {
    if (isalpha(i))
      i -= 'a';
    else
      i = 3;
    L[i]++;
  }
  long long ans = 0;
  R = vector<long long>(4);
  for (int i = n - 1; i > 0; i--) {
    int c = s[i];
    L[c]--;
    if (i + 1 < n && (c == 1 || c == 3)) {
      long long l =
          L[0] * p[L[3]] % Mod + (L[3] ? L[3] * p[L[3] - 1] % Mod : 0);
      long long r =
          R[2] * p[R[3]] % Mod + (R[3] ? R[3] * p[R[3] - 1] % Mod : 0);
      ans = (ans + l * r % Mod) % Mod;
    }
    R[s[i]]++;
  }
  cout << ans << endl;
  return 0;
}
