#K33397. Find the Core Substring

    ID: 25078 Type: Default 1000ms 256MiB

Find the Core Substring

Find the Core Substring

Given a string s, the core of the string is defined as the longest contiguous substring that contains either only letters or only digits. In case there are multiple such substrings of the same maximum length, the leftmost substring should be chosen.

Your task is to process multiple input strings and, for each string, output its core.

Note: A substring is a contiguous block of characters within the string. Letters are defined as A-Z and a-z, and digits are 0-9.

The solution should follow the \( \text{O}(n) \) approach for each string, where \( n \) is the length of the string.

inputFormat

The first line of input contains an integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a non-empty string \( s \) consisting of letters and digits.

Example:

4
AB12C34DE
1234AB56
ABCDE123
1000A5B67

outputFormat

For each test case, output the core substring on a new line.

Example:

AB
1234
ABCDE
1000
## sample
4
AB12C34DE
1234AB56
ABCDE123
1000A5B67
AB

1234 ABCDE 1000

</p>