Architect Omar is responsible for furnishing the new apartments after completion of its construction. Omar has a set of living room furniture, a set of kitchen furniture, and a set of bedroom furniture, from different manufacturers.
In order to furnish an apartment, Omar needs a living room furniture, a kitchen furniture, and two bedroom furniture, regardless the manufacturer company.
You are given a list of furniture Omar owns, your task is to find the maximum number of apartments that can be furnished by Omar.
Input
The first line contains an integer T (1 ≤ T ≤ 100), where T is the number of test cases.
The first line of each test case contains an integer n (1 ≤ n ≤ 1000), where n is the number of available furniture from all types. Then n lines follow, each line contains a string s representing the name of a furniture.
Each string s begins with the furniture's type, then followed by the manufacturer's name. The furniture's type can be:
- bed, which means that the furniture's type is bedroom.
- kitchen, which means that the furniture's type is kitchen.
- living, which means that the furniture's type is living room.
All strings are non-empty consisting of lowercase and uppercase English letters, and digits. The length of each of these strings does not exceed 50 characters.
Output
For each test case, print a single integer that represents the maximum number of apartments that can be furnished by Omar
Example
Input
1 6 bedXs kitchenSS1 kitchen2 bedXs living12 livingh
Output
1
#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
int main()
{
int a,b,i,g,h,j;
int n[4];
char s[60];
cin >> a;
while(a--)
{
g=0;
h=0;
j=0;
cin >> b;
for(i=1; i<=b; i++)
{
cin >> s;
if(s[0]=='b')
{
g++;
}
else if(s[0]=='k')
{
h++;
}
else if(s[0]=='l')
{
j++;
}
}
g=g/2;
n[1]=g;
n[2]=h;
n[3]=j;
int mi=1010;
for(i=1; i<=3; i++)
{
if(mi>n[i])
{
mi=n[i];
}
}
cout << mi << endl;
}
return 0;
}