Problem p00225 - Generation 1

Orig Description

Kobuta Nuki Kitsuneko
B-boy, a relative of Mrs. A, came to her house. He loves singing and is only 3 years old. He enthusiastically sings a song called "Kobuta Nuki Kitsuneko" (written and composed by Naotoshi Yamamoto) that he learned in kindergarten. In this song, four words, "kobuta," "nuki," "kitsune", and "neko," are played in order, and the last sound and the first sound are the same. B-boy asked A if she could make a similar word chain using words he said.
To help A, let's create a program that determines whether it is possible to make a word chain using all the given words in order and whether the first letter of the first word and the last letter of the last word are the same.
Create a program that takes n words as input and determines whether a word chain can be created from the combination of those words. If it is possible, output OK, and if it is impossible, output NG.
Input
Multiple datasets are given as input. The end of the input is indicated by a single zero line.
Each dataset is given in the following format.
n
word1
word2
:
wordn
The number of words n (2 ≤ n ≤ 10000) is given on the first line. The following n lines contain n words wordi (a string consisting of up to 32 lowercase English letters).
There are no more than 50 datasets.
Output
For each input dataset, output the determination result on one line.
Sample Input
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
Output for the Sample Input
NG
OK

Extracted Specification

An integer n (2 ≤ n ≤ 10000).
A list of n strings, each string consisting of up to 32 lowercase English letters.
The input ends with a single zero line.
There are no more than 50 datasets.

### Example Input:

```
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
```

### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, List[str]]]):
    '''
    inputs: a list of tuples, where each tuple contains:
        - an integer
        - a list of strings
    '''
```

Test Case Generator

Certainly! Below is a test case generator for the described problem "Kobuta Nuki Kitsuneko":

```python
import random
import string

def generate_word(length):
    return ''.join(random.choices(string.ascii_lowercase, k=length))

def generate_test_case():
    n = random.randint(2, 10000)
    words = [generate_word(random.randint(1, 32)) for _ in range(n)]
    
    return n, words

def tcgen():
    datasets = []
    for _ in range(random.randint(1, 50)):  # Generating between 1 and 50 datasets
        n, words = generate_test_case()
        datasets.append((n, words))
    
    return datasets

def format_test_case(test_case):
    formatted = []
    for n, words in test_case:
        formatted.append(f"{n}")
        formatted.extend(words)
    formatted.append("0")
    return "\n".join(formatted)

# Example usage
test_case = tcgen()
formatted_test_case = format_test_case(test_case)
print(formatted_test_case)
```

This generator creates a random number of datasets (between 1 and 50). Each dataset contains a random number of words (between 2 and 10000), and each word is a string of random lowercase letters with a length between 1 and 32.

The `format_test_case` function formats the generated test cases into the required input format for the problem.

You can run the `tcgen` function to generate the test cases, and use the `format_test_case` function to print them in the desired format. Here is an example of how it would look:

```plaintext
5
apple
yellow
georgia
king
email
7
apple
yellow
georgia
king
email
wink
lucky
0
```

You can run the code to generate different test cases and use them to test your solution.

Extract Arguments

def extract_arguments(fh):
    inputs = []
    while True:
        n = int(fh.readline().strip())
        if n == 0:
            break
        words = [fh.readline().strip() for _ in range(n)]
        inputs.append((n, words))
    return inputs

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         inputs = extract_arguments(fh)
#         f(inputs)