import java.io.*;
class Main{
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 100010;
static int[][] dp = new int[N][4];
public static void main(String[] args) throws Exception{
char[] cs = read.readLine().toCharArray();
int mod = (int) 1e9 + 7;
for(int i = 1; i <= cs.length; i++){
dp[i][0] = dp[i - 1][0] + (cs[i - 1] == 'P' ? 1: 0);
dp[i][1] = dp[i - 1][1] + (cs[i - 1] == 'A' ? dp[i - 1][0]: 0);
dp[i][2] = dp[i - 1][2] + (cs[i - 1] == 'T' ? dp[i - 1][1]: 0);
for(int j = 0; j < 3; j++)
dp[i][j] %= mod;
}
System.out.println(dp[cs.length][2]);
}
}