Once upon a time, there was a famous actress. As you may expect, she most enjoyed performing in Ancient Comedies. Everyone loved her, but she was not interested in the crowds. Her biggest hobby was collecting beads of all kinds. Many bead makers worked for her, producing new necklaces and bracelets every day. One day, she called her main Inspector of Bead Makers (IBM) and told him she wanted a very long and special necklace.
The necklace should be made of glass beads of different sizes, each connected together, but with no thread passing through the beads—so that any bead can be disconnected at any moment. The actress chose the sequence of beads she wanted, and the IBM promised to make the necklace. But then came a problem: the joint between two neighboring beads is not very reliable, so the necklace might tear under its own weight. The situation gets even worse if the necklace becomes separated. The points where the beads are joined are very important. If small beads are at the beginning, the chance of tearing is higher than if there were large beads. The bead maker wants to check the reliability of the necklace and requires a program to determine the worst possible point of separation.
The necklace is described by a string A = a_1 a_2 \ldots a_m specifying the sizes of the particular beads; the necklace is circular, so the bead a_m is followed by a_1.
A joint at position is said to be worse than a joint at position if and only if the string A[i] = a_i a_{i+1} \ldots a_m a_1 \ldots a_{i-1} is lexicographically smaller than the string A[j] = a_j a_{j+1} \ldots a_m a_1 \ldots a_{j-1}. The string a_1 a_2 \ldots a_n is lexicographically smaller than the string b_1 b_2 \ldots b_n if there exists an integer (i \leq n) such that a_j = b_j for each (1 \leq j < i), and a_i < b_i.
The first line contains the number of test cases . Each test case is given on a single line describing the structure of the necklace. The maximum necklace length is characters. Each bead is represented by a lowercase letter of the English alphabet (-), where a < b < \ldots < z.
For each test case, output a single integer on its own line—the number of the bead that comes first at the worst possible joint, that is, such that the string is lexicographically smallest among all possible separations of the necklace. If there are multiple solutions, print the one with the smallest .
Example 1