We call a string as a 0689-string if this string only consists of digits 0, 6, 8 and 9. Given a 0689-string s of length n, one must do the following operation exactly once: select a non-empty substring of s and rotate it 180 degrees.
More formally, let si be the i-th character in string s. After rotating the substring starting from sl and ending at sr 180 degrees (1≤l≤r≤n), string s will become string t of length n extracted from the following equation, where ti indicates the i-th character in string t:
ti=⎩⎨⎧si‘0’‘6’‘8’‘9’if 1≤i<l or r<i≤nif l≤i≤r and sl+r−i=‘0’if l≤i≤r and sl+r−i=‘9’if l≤i≤r and sl+r−i=‘8’if l≤i≤r and sl+r−i=‘6’
What's the number of different strings one can get after the operation?
输入格式
There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case:
The first and only line contains a 0689-string s (1≤∣s∣≤106).
It's guaranteed that the sum of ∣s∣ of all test cases will not exceed 107.
输出格式
For each test case output one line containing one integer, indicating the number of different strings one can get after applying the operation exactly once.
题目大意
【题目描述】
我们称一个字符串为 0689-字符串,如果这个字符串只包含数字 0、6、8 和 9。给定一个长度为 n 的 0689-字符串 s,必须执行以下操作一次:选择 s 的一个非空子串并将其旋转 180 度。
更正式地说,设 si 为字符串 s 的第 i 个字符。在将从 sl 开始到 sr 结束的子串旋转180度后 (1≤l≤r≤n),字符串 s 将变成长度为 n 的字符串 t,其通过以下公式得到,其中 ti 表示字符串 t 中的第 i 个字符:
ti=⎩⎨⎧si‘0’‘6’‘8’‘9’if 1≤i<l or r<i≤nif l≤i≤r and sl+r−i=‘0’if l≤i≤r and sl+r−i=‘9’if l≤i≤r and sl+r−i=‘8’if l≤i≤r and sl+r−i=‘6’
经过这个操作后,可以得到多少个不同的字符串?
【输入格式】
有多个测试用例。输入的第一行包含一个整数 T,表示测试用例的数量。对于每个测试用例:
第一行且唯一一行包含一个 0689-字符串 s (1≤∣s∣≤106)。
保证所有测试用例的 ∣s∣ 之和不超过 107。