Problem Statement:
The game of digits is a very popular game, which you used to play with your friends. In this game you are given a very long string of digits (all letters are digits from '0' to '9'). Your task is to count the number of substrings which satisfy the following condition: All digits from '0' to N (inclusive) appears exactly once in that substring, and no other digits appear in that substring, for any given N. The digits can appear in any order.

For example if the given string is "03210", the following substrings satisfy the above condition: "0", "0321", "3210", "210", "10", "0". Note that the substring "0" was counted twice because it appeared twice in the original string.

Your task is to write a program to solve this game.


Input Format:
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 <= T <= 100). Followed by the test cases, each test case is described in one line which contains a non-empty string which consists of up to 100,000 letters, each letter is a digit from '0' to '9'. This string is the given string for the game.


Output Format:
For each test case, print a single line which contains a single integer representing the number of substrings which satisfy the above condition.


Sample Input:
3 03210 123 0101010


Sample Output:
6 0 10





Added by: ahmed_aly
Added at: 2014-08-23 14:00:03 UTC
Time Limit: 3 seconds
Partial score: No
Source:A2OJ FCI-CU Tournament 2014 - Final Round