#C1374. Highest Value Numeric Substring

    ID: 43311 Type: Default 1000ms 256MiB

Highest Value Numeric Substring

Highest Value Numeric Substring

You are given a string that can contain any characters. Your task is to find the highest numerical value represented by a contiguous substring of digits within the given string. If the string does not contain any digits, output 0.

For example, given the input string abc123xyz, the highest numeric substring is 123; for abc100xyz200, it is 200.

The numeric substrings are interpreted using the standard base-10 numeral system. More formally, if a substring \(S\) is composed only of digits, its value is \(\mathrm{val}(S)=\sum_{i=0}^{n-1} (S[i]-'0')\times10^{n-1-i}\). Your solution should correctly and efficiently process multiple test cases.

inputFormat

The first line contains an integer \(T\) that denotes the number of test cases.

Each of the following \(T\) lines contains a single string \(S\) which may include alphabetic characters, digits, and other symbols.

outputFormat

For each test case, output the highest numerical value of any contiguous substring found in the input string. If no digits are present, output 0.

Each result should be printed on its own line.

## sample
3
abc123xyz
abc100xyz200
abc987def765gh123
123

200 987

</p>