//find 来查找、计数string
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 ;
const int mod = 1e9 + 7 ;
int main (){
int T, caset= 0 ;
cin>> T;
while ( T--){
string s;
cin>> s;
int flag= 1 ;
for ( int i= 0 ; i< s. length(); i++){
if ( s[ i]== 32 || ( s[ i]!= 'c' && s[ i]!= 'f' ))
{
flag= 0 ;
break ;
}
}
if ( s. find( "cc" )!= string:: npos) flag= 0 ;
if ( s. find( "cfc" )!= string:: npos) flag= 0 ;
if ( s[ 0 ]== 'c' && s[ s. length()- 1 ]== 'c' ) flag= 0 ;
if ( s. length()>= 2 && s[ 0 ]== 'f' && s[ 1 ]== 'c' && s[ s. length()- 1 ]== 'c' ) flag= 0 ;
if ( s. length()>= 2 && s[ 0 ]== 'c' && s[ s. length()- 2 ]== 'c' && s[ s. length()- 1 ]== 'f' ) flag= 0 ;
string p( "c" );
int ans= 0 ;
string:: size_type pos= 0 ;
while (( pos = s. find( p, pos)) != string:: npos) ans++, pos++;
if ( ans== 0 )
ans=( s. length()+ 1 )/ 2 ;
cout<< "Case #" <<++ caset<< ": " ;
if ( flag) cout<< ans<< endl;
else cout<<- 1 << endl;
}
}