G - I ❤ Pizza |
Everybody loves pizza: Margarita, Four cheese, Salami, Caprichosa, Neapolitan, Hawaiian... The famous pizza Margarita is named after the Italian Queen Margarita of Savoy. It is said that the chef Raffaele Esposito gave her to choose from a variety of pizzas he had prepared specially for the Queen. Margarita chose this pizza in honor of the colors of the Italian flag: red tomato, white cheese, and green basil.
However, some people argue that, in fact, Queen Margarita did not like onion, and as all the other pizzas had onion, she had no choice but that pizza.
For example, if we have the ingredients:
AAAAAAMMRRTITIGGRRRRRRRR
Then we can make 2 pizzas MARGARITA, and still spare some R.
Given a set of ingredients, you have to say how many pizzas MARGARITA can be made. Note that there may be leftover ingredients, and also there may be unnecessary ingredients, such as B.
The first line contains a natural number, N, which indicates the number of test cases.
Each test case is given in one line. This line contains a series of capital letters from A to Z, which can be messy and may be repeated. At most one line can have 600 characters.
For each test case, you must indicate how many pizzas MARGARITA can be made with the letters available, taking into account that there may be spare letters.
5
MARGARITAAAAAAAMMRRTITIGGRRRRRRRR
AMARGITA
BOLOGNESACAPRICHOSATOMATERA
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
0
1
0