Regular Expression
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Grammy has recently been interested in regular expression while focusing on cases where the alphabet consists of characters from a to z. Today she asks NIO some questions. Each question gives string A, asking the minimum length of expressions matching string A according to the matching rules and the number of all shortest expressions.

To learn detailed rules about how regular expressions match strings,
you can refer to https://en.wikipedia.org/wiki/Regular_expression.

Here we only consider characters from 'a' to 'z', '.', '?', '*', '+', '|', '(', ')'. It is assumed that the asterisk, the question mark and the plus sign have the highest priority, then concatenation and then alternation. Parentheses can be used to change the priority. For example, can match “ab” and “ac”. If there is no ambiguity then parentheses may be omitted. For example, can be written as , and can be written as

Here are some examples of matching:


  • (or): can match “gray” or “grey”.

  • (question mark): matches both “color” and “colour”.

  • (asterisk): matches “ac”, “abc”, “abbc”, “abbbc”, and so on.

  • (plus sign): matches “abc”, “abbc”, “abbbc”, and so on, but not “ac”.

  • (wildcard): matches any string that contains an “a”, and then any character and then “b”; and matches any string that contains an “a”, and then the character “b” at some later point. More precisely, “ab” can be matched by but not .

  • (concatenation): Let expression matches and expression matches . Then, matches
If you are not sure about whether a regular expression is valid, then you can use https://regex101.com/ to check its validity. Note that the character set we use is slightly different from the website. 

输入描述:

The input contains only a single case.

The first line contains a single integer Q (), denoting the number of questions. The i-th line of the following Q lines contain one string A consisting of lowercase letters (), denoting the string A of the i-th question. It is guaranteed that .

输出描述:

For each question, output a single line containing 2 integers - the minimum length and the number to the question. Note that the answer may be extremely large, so please print it modulo  instead.
示例1

输入

复制
2
a
ab

输出

复制
1 2
2 6