#include <bits/stdc++.h>
using namespace std;
long long li[200010], ri[200010], la[200010], rc[200010], pot[200010];
long long pot3(long long p) {
  if (p < 0) return 0;
  if (p == 0) return 1;
  return pot[p];
}
int32_t main() {
  long long n;
  string str;
  cin >> n >> str;
  for (long long i = 0; str[i]; i++) {
    if (i) {
      la[i] = la[i - 1];
      li[i] = li[i - 1];
    }
    if (str[i] == 'a') la[i]++;
    if (str[i] == '?') li[i]++;
  }
  for (long long i = str.size() - 1; i >= 0; i--) {
    rc[i] = rc[i + 1];
    ri[i] = ri[i + 1];
    if (str[i] == 'c') rc[i]++;
    if (str[i] == '?') ri[i]++;
  }
  pot[0] = 1;
  for (long long i = 1; i <= ri[0]; i++) {
    pot[i] = (pot[i - 1] * 3) % 1000000007;
  }
  long long tot = ri[0];
  long long res = 0;
  for (long long i = 0; str[i]; i++) {
    long long l = i - 1;
    long long r = i + 1;
    if (l < 0) l = str.size();
    long long cur = res;
    if (str[i] == 'b') {
      res += (la[l] * rc[r] % 1000000007 * pot3(tot) % 1000000007 +
              la[l] * ri[r] % 1000000007 * pot3(tot - 1) % 1000000007 +
              li[l] * rc[r] % 1000000007 * pot3(tot - 1) % 1000000007 +
              li[l] * ri[r] % 1000000007 * pot3(tot - 2) % 1000000007);
      res %= 1000000007;
    }
    if (str[i] == '?') {
      res += (la[l] * rc[r] % 1000000007 * pot3(tot - 1) % 1000000007 +
              la[l] * ri[r] % 1000000007 * pot3(tot - 2) % 1000000007 +
              li[l] * rc[r] % 1000000007 * pot3(tot - 2) % 1000000007 +
              li[l] * ri[r] % 1000000007 * pot3(tot - 3) % 1000000007);
      res %= 1000000007;
    }
    cur = (res - cur);
  }
  cout << res << endl;
  return 0;
}
