Bob is a construction worker who does mathematics for increasing his efficiency. He is working on a site and has buckets of cement lined up with different characters marked upon them. He has a strict command from the senior that he cannot change the order of the buckets.
Before starting his work, he has been given a string of length in which the character at position () gives us the mark on the bucket. He can only carry one bucket at a time and bring it back to the base site. In each round, he has a criterion on which bucket to pick up. He will take the bucket with the smallest character marked upon it () and if there are multiple buckets with the smallest character, then he will take the one closest to the base.
The cost of picking up a bucket is the number of buckets he passes through while walking from the site to get (the bucket which he picks is also included). In each round, the cost accumulates. Find the final cost incurred by Bob while completing his job.
Input format
Output format
Print the accumulation cost for each test case separated by a new line.
Constraints
The sum of over all test cases does not exceed 106.
The total cost becomes 7 units.