Regular Expression

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Grammy has recently been interested in regular expressions while focusing on cases where the alphabet consists of characters from 'a' to 'z'. Today she asks NIO some questions. Each question gives string AA, asking the minimum length of an expression matching string AA according to the matching rules, and also the number of such 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' and special characters '.', '?', '*', '+', '|', '(', ')'. It is assumed that the asterisk, the question mark and the plus sign have the highest priority, then follows concatenation and then alternation. Parentheses can be used to change the priority. For example, "a(b|c)" can match "ab" and "ac". Parentheses may be omitted when they don't change the priority. For example, "(ab)c" can be written as "abc", and "a|(b(c*))" can be written as "a|bc*".

Here are some examples of matching:

  • (or): "gray|grey" can match "gray" or "grey".
  • (question mark): "colou?r" matches both "color" and "colour".
  • (asterisk): "ab*c" matches "ac", "abc", "abbc", "abbbc", and so on.
  • (plus sign): "ab+c" matches "abc", "abbc", "abbbc", and so on, but not "ac".
  • (wildcard): "a.b" matches any string that contains an "a", then any single character, and then "b"; and "a.*b" matches any string that contains an "a", and then the character "b" at some later point. More precisely, "ab" can be matched by "a.*b" but not by "a.b".
  • (concatenation): Consider expression R=R = "(ab|c)" matching {"ab", "c"}, and expression S=S = "(d|ef)" matching {"d", "ef"}. Then, (RS)=(RS) = "((ab|c)(d|ef))" matches {"abd", "abef", "cd", "cef"}.

입력

The input contains only a single case.

The first line contains a single integer QQ (1Q100,0001\leq Q\leq 100\\,000) denoting the number of questions. The ii-th line of the following QQ lines contains one string AA consisting of lowercase English letters (1A200,0001\leq |A|\leq 200\\,000) denoting the string AA of the ii-th question. It is guaranteed that A1,000,000\sum |A|\leq 1\\,000\\,000.

출력

For each question, output a single line containing two integers: the minimum length of a matching expression and the number of matching expressions of such length. Note that the answers may be extremely large, so please print them modulo 998,244,353998\\,244\\,353.