#include <bits/stdc++.h>
using namespace std;
const long long mx=2*1e5+5;
const long long mod=1e9+7;
typedef long long ll;
#define f first
#define s second
bool uper(char x){
return(x>='A'&&x<='Z');
}
bool lower(char x){
if(x=='.'||x=='?'||x=='!'){return 1;}
return(x>='a'&&x<='z');
}
bool endd(char x){
return (x=='.'||x=='?'||x=='!');
}
int main() {
int n;cin>>n;
int counter=0;
string s;
ll temp=0;
while(counter<n){
cin>>s;
int ss=s.size();
int b=0;
if(uper(s[0])){
for(int j=1;j<ss;j++){
if(!lower(s[j])){b=1;break;}
}if(b==0){temp++;}
}
if(endd(s[ss-1])){
cout<<temp<<endl;
temp=0;
counter++;
}
}
}