/* String */# include <stdio. h> # include <string. h> # include <stdlib. h> # include <algorithm> # include <iostream> # include <queue> # include <map> # include <stack> # include <set> # include <math. h> using namespace std; typedef long int64; // typedef _ int64 int64; typedef pair <int64, int64> PII; # define MP (a, B) make_pair (a), (B) const int maxn = 10090; const int mod = 10007; const int inf = 0x7fffffff; const double pi = acos (-1.0 ); const double eps = 1e-8; int Fib [maxn]; void init () {Fib [0] = 1; Fib [1] = 1; for (int I = 2; I <maxn; I ++) {Fib [I] = Fib [I-1] + Fib [I-2]; Fib [I] % = mod ;}} int main () {init (); int Case = 1; int T; scanf ("% d", & T); while (T --) {char s [maxn]; printf ("Case % d:", Case ++); int ans = 1; scanf ("% s", s); int len = strlen (s ); for (int I = 0; I <len; I ++) {int cnt = 0; if (I + 1 <len & s [I] = 'H' & s [I + 1] = 'E') {// cnt = 1; int Index = I; bool f = false; while (Index + 1 <len) {if (s [Index] = 'H' & s [Index + 1] = 'E') {cnt ++; Index + = 2; I = Index;} else {if (cnt) I --; if (cnt) ans = ans * Fib [cnt] % mod; f = true; break ;}} if (f = false & cnt) ans = ans * Fib [cnt] % mod;} printf ("% d \ n", max (ans % mod, 1);} return 0 ;}