#include<bits/stdc++.h>
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
using namespace std;
int main()
{
string s;
int t , cnt=0 , M=0,A=0,G=0,R=0,T=0,I=0;
cin>>t;
while(t--){
cnt=0 , M=0,A=0,G=0,R=0,T=0,I=0;
cin>>s;
ff(i,0,s.size()){
if(s[i]=='M')
M++;
else if(s[i]=='A')
A++;
else if(s[i]=='G')
G++;
else if(s[i]=='R')
R++;
else if(s[i]=='T')
T++;
else if(s[i]=='I')
I++;
}
// cout<<cnt<<endl;
while(1){
if(M>=1&&A>=3&&R>=2&&G>=1&&I>=1&& T>=1 )
cnt++;
else
break;
M-=1 , A-=3 , R-=2, G-=1, I-=1, T-=1;
}
cout<<cnt<<endl;
}
return 0;
}
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
using namespace std;
int main()
{
string s;
int t , cnt=0 , M=0,A=0,G=0,R=0,T=0,I=0;
cin>>t;
while(t--){
cnt=0 , M=0,A=0,G=0,R=0,T=0,I=0;
cin>>s;
ff(i,0,s.size()){
if(s[i]=='M')
M++;
else if(s[i]=='A')
A++;
else if(s[i]=='G')
G++;
else if(s[i]=='R')
R++;
else if(s[i]=='T')
T++;
else if(s[i]=='I')
I++;
}
// cout<<cnt<<endl;
while(1){
if(M>=1&&A>=3&&R>=2&&G>=1&&I>=1&& T>=1 )
cnt++;
else
break;
M-=1 , A-=3 , R-=2, G-=1, I-=1, T-=1;
}
cout<<cnt<<endl;
}
return 0;
}
No comments:
Post a Comment