#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void run() {
  string s;
  int i, j, n;
  long long a = 0, ab = 0, abc = 0, q = 1;
  cin >> n >> s;
  for (i = 0; i < n; i++) {
    if (s[i] == 'a')
      a = (a + q) % MOD;
    else if (s[i] == 'b')
      ab = (ab + a) % MOD;
    else if (s[i] == 'c')
      abc = (abc + ab) % MOD;
    else {
      abc = (3 * abc + ab) % MOD;
      ab = (3 * ab + a) % MOD;
      a = (3 * a + q) % MOD;
      (q *= 3) %= MOD;
    }
  }
  cout << abc << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  run();
}
