Under construction

Still being built. Things may change

Golden Khon Kaen

Interview

Time limit10sMemory limit64 MB

Summary
Count how many times the word GOLDEN can be formed from each given string of capital letters.
Level

Easy1 of 10

Topics
Hash map
Solved
No attempts yet

Problem

Khon Kaen is a province in northeastern Thailand. Its slogan is

พระธาตุขามแก่น เสียงแคนดอกคูน ศูนย์รวมผ้าไหม ร่วมใจผูกเสี่ยว
เที่ยวขอนแก่นนครใหญ่ ไดโนเสาร์สิรินธรเน่ สุดเท่เหรียญทองมวยโอลิมปิก

The slogan names two golden things. The first is the golden shower, ดอกคูน, the official flower of the province. The second is the gold medal, Thailand's first Olympic gold, won by Somruk Khamsing, whose hometown is Khon Kaen.

To celebrate the golden province, count how many copies of the word GOLDEN a given series of letters can form. All letters are capitals from A to Z. One GOLDEN needs exactly one G, one O, one L, one D, one E and one N.

For example, from the series GOOOOOOOOLDENN you can build one GOLDEN, and some O and N are left over.

Given several series of letters, report for each one the largest number of GOLDEN words it can form. Letters may be left over, and letters that are not needed at all, such as B, may appear.

Input

The first line contains the number of test cases NN (1≤N≤1001 \le N \le 100). Each of the next NN lines contains one test case: a series of capital letters from A to Z, in any order and with repetitions allowed. A line is at most 400 characters long.

Output

For each test case, print on its own line the largest number of GOLDEN words that the available letters can form. Leftover letters are allowed.

Examples5

  1. Example 1

    Input
    5
    GOLDEN
    GOGOGOLDENENEDLOG
    GOALD
    BOLOGNESACAPRICHOSADOMATERA
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
    Expected output
    1
    2
    0
    1
    1
    
  2. Example 2

    Input
    1
    GOLDEN
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    A
    
    Expected output
    0
    
  4. Example 4

    Input
    6
    OLDEN
    GLDEN
    GODEN
    GOLEN
    GOLDN
    GOLDE
    
    Expected output
    0
    0
    0
    0
    0
    0
    
  5. Example 5

    Input
    1
    GOOOOOOOOLDENN
    
    Expected output
    1