The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:

* 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)
* T_i = `A` (T_i is the i-th character of T from the beginning.)
* T_j = `B`
* T_k = `C`



For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.

You are given a string S. Each character of S is `A`, `B`, `C` or `?`.

Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.

This sum can be extremely large, so print the sum modulo 10^9 + 7.

Constraints

* 3 ≤ |S| ≤ 10^5
* Each character of S is `A`, `B`, `C` or `?`.

Input

Input is given from Standard Input in the following format:


S


Output

Print the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.

Examples

Input

A??C


Output

8


Input

ABCBC


Output

3


Input

????C?????B??????A???????


Output

979596887
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static String S;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        S = sc.next();

        System.out.println(solve());
    }

    static int MOD = 1_000_000_007;

    static int solve() {
        int [] A = new int[S.length()];
        int [] B = new int[S.length()];
        int [] C = new int[S.length()];
        int [] Q = new int[S.length()];
        for (int i = 0; i < S.length(); i++) {
            if( i != 0 ) {
                A[i] = A[i-1];
                B[i] = B[i-1];
                C[i] = C[i-1];
                Q[i] = Q[i-1];
            }

            char c = S.charAt(i);
            if( c == 'A' ) {
                A[i]++;
            } else if( c == 'B' ) {
                B[i]++;
            } else if( c == 'C' ) {
                C[i]++;
            } else {
                Q[i]++;
            }
        }

        int maxq = Q[Q.length-1];
        FQ = new int[maxq + 1];
        Arrays.fill(FQ, -1);
        POW3 = new int[maxq + 1];
        POW3[0] = 1;

        for (int i = 1; i <= maxq; i++) {
            fq(i);
            POW3[i] = mul(POW3[i-1], 3);
        }

        int ans = 0;

        // 一般式を出さないで漸化式のメモ化で実装した版
        for (int j = 1; j < S.length()-1; j++) {
            if( S.charAt(j) == 'B' || S.charAt(j) == '?' ) {
                int a = A[j-1];
                int q1 = Q[j-1];
                int prev = f(a, q1);

                int c = C[S.length()-1] - C[j];
                int q2 = Q[S.length()-1] - Q[j];
                int post = f(c, q2);

                ans = add(mul(prev, post), ans);
            }
        }

        return ans;
    }

    static int[] FQ;
    static int[] POW3;

    static int fq(int q) {
        if( FQ[q] != -1 ) return FQ[q];

        int ret;
        if( q == 0 ) {
            ret = 0;
        } else if( q == 1 ) {
            ret = 1;
        } else {
            ret = add(f(1, q-1), mul(2, f(0, q-1)));
        }
        FQ[q] = ret;
        return ret;
    }

    static int f(int a, int q) {
        // (a * 3 ^ q) + fq(q)
        return add(mul(a, pow3(q)), fq(q));
    }

    static int pow3(int n) {
        return POW3[n];
    }

    static int mul(int a, int b) {
        return (int)((long)a * b % MOD);
    }

    static int add(int a, int b) {
        return (int)(((long)a + b) % MOD);
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}
