Sure! Let's write a test case generator for the given problem statement. The generator will produce valid test cases based on the constraints provided.

Here is the Python test case generator:

```python
import random

def tcgen():
    # Generate a random number of datasets
    num_datasets = random.randint(1, 200)
    
    datasets = []
    
    for _ in range(num_datasets):
        # Generate a random length for the sequence, n
        n = random.randint(1, 12)
        
        # Generate the sequence S of length n with elements between 1 and 100
        S = [random.randint(1, 100) for _ in range(n)]
        
        # Append the dataset to the list
        datasets.append((n, S))
    
    # Add the end marker
    datasets.append((0,))
    
    return datasets

# Example usage
if __name__ == "__main__":
    test_cases = tcgen()
    for case in test_cases:
        if case[0] == 0:
            print(0)
        else:
            n, S = case
            print(n)
            print(" ".join(map(str, S)))
```

This script generates random test cases according to the constraints provided in the problem statement. Each dataset consists of a sequence length \(n\) and a sequence \(S\). The test cases end with a line containing a single 0 to signify the end of input.

### Explanation:
1. **Number of Datasets**: The generator creates a random number of datasets (between 1 and 200).
2. **Sequence Length \(n\)**: For each dataset, a random sequence length \(n\) is generated (between 1 and 12).
3. **Sequence \(S\)**: For each sequence, \(n\) integers are generated, each between 1 and 100.
4. **Output Format**: The datasets are printed in the required format, with each dataset's length \(n\) and sequence \(S\) printed on separate lines, followed by a final line containing a single 0.

You can run this script to generate random test cases for the problem. The output will be a series of datasets formatted correctly, ready to be used for testing the solution to the problem.