#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"a=[1]+[0]*4\n"
"m=10**9+7\n"
"for s in input():\n"
" i=ord(s)-64\n"
" if i>0:a[i]+=a[i-1]\n"
" else:a=[a[i]*3%m+a[i-1]for i in range(4)]+[0]\n"
"print(a[3]%m)\n"
"\"";
  system(s);
  return 0;
}            