#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string second;
  cin >> second;
  long long a = 0, b = 0, c = 0, t = 1;
  for (long long i = 0; i < n; i++) {
    if (second[i] == '?') {
      c = (3 * c + b);
      b = (3 * b + a);
      a = (3 * a + t);
      t *= 3;
    } else if (second[i] == 'a') {
      a += t;
    } else if (second[i] == 'b') {
      b += a;
    } else {
      c += b;
    }
    a %= 1000000007;
    b %= 1000000007;
    c %= 1000000007;
    t %= 1000000007;
  }
  cout << c << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
