#include <bits/stdc++.h>
const int64_t mod = 1e9 + 7;
const long long INF = 1e15;
const double PI = acos(-1);
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int64_t i = 0; i < v.size(); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "{";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << "}\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  os << "{";
  for (auto it : v) {
    os << "(" << it.first << " : " << it.second << ")";
    if (it != *v.rbegin()) os << ", ";
  }
  os << "}\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  return os;
}
template <typename T>
inline istream& operator>>(istream& in, vector<T>& a) {
  for (auto& x : a) in >> x;
  return in;
}
template <int64_t D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int64_t n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int64_t n = 0, const T& val = T()) : vector<T>(n, val) {}
};
int64_t fpow(int64_t x, int64_t y, int64_t p);
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t T = 1;
  for (int64_t tc = 1; tc <= T; ++tc) {
    int64_t n;
    cin >> n;
    string s;
    cin >> s;
    vector<int64_t> lefta(n + 1, 0);
    vector<int64_t> ls(n + 1, 0);
    vector<int64_t> rightc(n + 1, 0);
    vector<int64_t> rs(n + 1, 0);
    if (s[0] == 'a' || s[0] == '?') lefta[0] = 1;
    ls[0] = 1;
    if (s[0] == '?') ls[0] = 3;
    for (int64_t i = 1; i < n; ++i) {
      if (s[i] == 'b' || s[i] == 'c')
        lefta[i] = lefta[i - 1];
      else if (s[i] == 'a') {
        lefta[i] = (lefta[i - 1] + ls[i - 1]) % mod;
      } else {
        lefta[i] = (lefta[i - 1] + ls[i - 1]) % mod;
        lefta[i] += 2 * lefta[i - 1];
        lefta[i] %= mod;
      }
      ls[i] = ls[i - 1];
      if (s[i] == '?') ls[i] = ls[i - 1] * 3;
      ls[i] %= mod;
    }
    rightc[n - 1] = 0;
    if (s[n - 1] == 'c' || s[n - 1] == '?') rightc[n - 1] = 1;
    rs[n - 1] = 1;
    if (s[n - 1] == '?') rs[n - 1] = 3;
    for (int64_t i = n - 2; i >= 0; --i) {
      if (s[i] == 'a' || s[i] == 'b') {
        rightc[i] = rightc[i + 1];
      } else if (s[i] == 'c') {
        rightc[i] = rightc[i + 1] + rs[i + 1];
      } else {
        rightc[i] = (3 * rightc[i + 1] + rs[i + 1]) % mod;
      }
      rs[i] = rs[i + 1];
      if (s[i] == '?') rs[i] = rs[i + 1] * 3;
      rightc[i] %= mod;
      rs[i] %= mod;
    }
    int64_t ans = 0;
    for (int64_t i = 1; i < n - 1; ++i) {
      if (s[i] == 'b' || s[i] == '?')
        ans += (lefta[i - 1] * rightc[i + 1]) % mod;
      ans %= mod;
    }
    cout << ans % mod << endl;
  }
  return 0;
}
int64_t fpow(int64_t x, int64_t y, int64_t p) {
  int64_t res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
