#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7, n, p, cnt0 = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0, ans0 = 0,
          ans1 = 0, ans2 = 0, ans3 = 0, c0[200005], c1[200005], c2[200005],
          c3[200005], x[200005];
long long pow3(long long hina) {
  if (hina < 0) {
    return 0;
  } else if (hina == 0) {
    return 1;
  } else {
    return (3 * pow3(hina - 1)) % MOD;
  }
}
int main() {
  string s;
  cin >> n >> s;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') {
      c0[cnt0] = i;
      cnt0++;
    } else if (s[i] == 'b') {
      c1[cnt1] = i;
      cnt1++;
    } else if (s[i] == 'c') {
      c2[cnt2] = i;
      cnt2++;
    } else {
      c3[cnt3] = i;
      cnt3++;
    }
  }
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt1; i++) {
    while (c1[i] >= c2[p] && p < cnt2) {
      p++;
    }
    x[i] = cnt2 - p;
  }
  for (long long i = cnt1 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt0; i++) {
    while (c0[i] >= c1[p] && p < cnt1) {
      p++;
    }
    ans0 += x[p];
    ans0 %= MOD;
  }
  ans0 *= pow3(cnt3);
  ans0 %= MOD;
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt1; i++) {
    while (c1[i] >= c3[p] && p < cnt3) {
      p++;
    }
    x[i] = cnt3 - p;
  }
  for (long long i = cnt1 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt0; i++) {
    while (c0[i] >= c1[p] && p < cnt1) {
      p++;
    }
    ans1 += x[p];
    ans1 %= MOD;
  }
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c2[p] && p < cnt2) {
      p++;
    }
    x[i] = cnt2 - p;
  }
  for (long long i = cnt3 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt0; i++) {
    while (c0[i] >= c3[p] && p < cnt3) {
      p++;
    }
    ans1 += x[p];
    ans1 %= MOD;
  }
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt1; i++) {
    while (c1[i] >= c2[p] && p < cnt2) {
      p++;
    }
    x[i] = cnt2 - p;
  }
  for (long long i = cnt1 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c1[p] && p < cnt1) {
      p++;
    }
    ans1 += x[p];
    ans1 %= MOD;
  }
  ans1 *= pow3(cnt3 - 1);
  ans1 %= MOD;
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c3[p] && p < cnt3) {
      p++;
    }
    x[i] = cnt3 - p;
  }
  for (long long i = cnt3 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt0; i++) {
    while (c0[i] >= c3[p] && p < cnt3) {
      p++;
    }
    ans2 += x[p];
    ans2 %= MOD;
  }
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt1; i++) {
    while (c1[i] >= c3[p] && p < cnt3) {
      p++;
    }
    x[i] = cnt3 - p;
  }
  for (long long i = cnt1 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c1[p] && p < cnt1) {
      p++;
    }
    ans2 += x[p];
    ans2 %= MOD;
  }
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c2[p] && p < cnt2) {
      p++;
    }
    x[i] = cnt2 - p;
  }
  for (long long i = cnt3 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c3[p] && p < cnt3) {
      p++;
    }
    ans2 += x[p];
    ans2 %= MOD;
  }
  ans2 *= pow3(cnt3 - 2);
  ans2 %= MOD;
  p = 0;
  for (long long i = 0; i < 200005; i++) {
    x[i] = 0;
  }
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c3[p] && p < cnt3) {
      p++;
    }
    x[i] = cnt3 - p;
  }
  for (long long i = cnt3 - 2; i >= 0; i--) {
    x[i] += x[i + 1];
  }
  p = 0;
  for (long long i = 0; i < cnt3; i++) {
    while (c3[i] >= c3[p] && p < cnt3) {
      p++;
    }
    ans3 += x[p];
    ans3 %= MOD;
  }
  ans3 *= pow3(cnt3 - 3);
  ans3 %= MOD;
  cout << (ans0 + ans1 + ans2 + ans3) % MOD << '\n';
}
