The disjoint point i is said to be worse than the disjoint point j if and only if the string aiai+1 . . . ana1 . . . ai-1 is lexicografically smaller than the string ajaj+1 . . . ana1 . . . aj-1. String a1a2 . . . an is lexicografically smaller than the string b1b2 . . . bn if and only if there exists an integer i, i ≤ n, so that aj = bj, for each j, 1 ≤ j < i and ai < bi.
The input consists of N cases. The first line of the input contains only positive integer N . Then follow the cases. Each case consists of exactly one line containing necklace description. Maximal length of each description is 10000 characters. Each bead is represented by a lower-case character of the english alphabet (a–z), where a < b < ... < z.
For each case, print exactly one line containing only one integer — number of the bead which is the first at the worst possible disjoining, i.e. such i, that the string A[i] is lexicographically smallest among all the n possible disjoinings of a necklace. If there are more than one solution, print the one with the lowest i.