SP26773 ICCSECRET - Secret Key

Description

You are working in security cell of your Institute Computer Center(ICC) and want to generate a secret key following a pattern. The pattern consists of the characters 'A' and 'B' where A means increasing and 'B' means decreasing. Generate the secret key which is the minimum number encoded following that pattern. Digits 1-9 in the key and digits can not repeat.

Input Format

Input starts with an integer T denoting the number of test cases. T lines follows containing pattern string(length

Output Format

For every test case, output the minimum number denoting that pattern.