You had a sequence of consecutive nonnegative integers. You appended all integers at the end of each other to form a string ‘S’ without any separators. While appending each integer in a string, you forgot to append exactly one integer from the sequence. Now all the integers from a string and you don’t know which integer you have missed.
For example sequence 11, 12, 13 may form a string (without any separators) “1113” if you miss 12.
Your task is to find the missing number in the string such that it is possible to obtain a sequence of consecutive non-negative integers from the given string. If more than one missing integer is present or all the integers are already present or if the string is not valid then the answer will be -1 for all such cases.
Note:
1. The string consists of only digits 0 to 9.
2. The numbers will have no more than six digits.
Input Format:-
The first line of input contains an integer ‘T’ denoting the number of test cases.
The only line of each test case contains a string of numbers 'S'.
Output Format:-
For each test case, print a single line containing a single integer denoting the missing number.
The output of each test case will be printed in a separate line.
Note:
You don’t have to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
1 <= |S| <= 10 ^ 4
0 <= S[i] <= 9
Where |S| denotes the length of the given string 'S' and S[i] is the digit at index i.
Time Limit: 1 sec.