#C46. Capitalize Each Word

    ID: 48155 Type: Default 1000ms 256MiB

Capitalize Each Word

Capitalize Each Word

Given a string, your task is to capitalize the first letter of each word while converting the remaining letters of the word to lowercase. A word is defined as a contiguous sequence of non-space characters, and the spaces in the string should be preserved exactly as they appear.

For example, given the input "hello world", the output should be "Hello World".

This problem tests your ability to process strings and handle edge cases such as multiple spaces, leading or trailing spaces, and words in all uppercase or mixed case.

Mathematically, if S is an input string consisting of characters, we are to transform S into S' such that

$$ S' = \text{join}([\text{capitalize}(w) \;|\; w \text{ is a word in } S]) $$

inputFormat

The input starts with an integer \(T\) on a single line indicating the number of test cases. This is followed by \(T\) lines, each line containing a string that may include spaces.

outputFormat

For each test case, output the transformed string on a separate line, where each word is capitalized as described.

## sample
3
hello world
java coding
python programming
Hello World

Java Coding Python Programming

</p>