#Lutece2740. Debutante Waltz
Debutante Waltz
Migrated from Lutece 2740 Debutante Waltz
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
纯音乐,请您欣赏。
——《Debutante Waltz》
对于一个 串 (即只包含 和 的字符串),我们总可以把它写成 的形式。其中 表示顺序连接 个字符串 。 是 的一个前缀(可以为空串)。 表示把字符串 直接连接在 的后面。
我们称字符串 的循环节 为当忽略 时,使得 最大且非空的 ,而这个字符串的值 就是 。例如 ,因为 可以写成 。,因为 可以写成 , 为一空串。
现在给定 ,请计算所有长度恰好为 的 字符串的值的和。由于答案很大,请输出它对 取模后的值。
Input
第一行包含一个整数 ,表示数据组数。
接下来 行,每行包含一个整数 。
保证对于每组数据,都有 。
Output
对于每组数据,输出一行一个整数,表示答案对 取模后的值。
Samples
5
1
2
3
114
514
2
6
12
954037435
530871613
Note
对于 ,
$$\begin{aligned} &v(000)+v(001)+v(010)+v(011)+v(100)+v(101)+v(110)+v(111)\\ &=3+1+1+1+1+1+1+3\\ &=12\\ \end{aligned} $$Resources
2022 UESTC ICPC Training for Math and Geometry