Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 難易度: [表示] ハック可能 ✓
統計

Little Cyan Fish likes string theory very much. Today, Little Cyan Fish invites you to study human nicknames with him.

In Little Cyan Fish's universe, human nicknames can all be represented as a string containing only lowercase Latin letters (a to z). For example, "qingyu" and "xiuga" are human nicknames, but "Abacde" is not a human nickname.

Little Cyan Fish considers a name $s$ to be Lyndon if and only if for each proper suffix* $t$ of $s$, the lexicographical order of $s$ is strictly smaller than $t$. For example, "abacde" is a Lyndon string, but "qingyu" is not a Lyndon string (because the original string is not lexicographically smaller than the proper suffix "ingyu").

Now, Little Cyan Fish gives you a human nickname $s$, and you need to calculate how many different pairs of $(l, r)$ with $1 \le l \le r \le |s|$ exist such that $s[l \dots r]$ is Lyndon.

* A proper suffix is a non-empty suffix that is not equal to the original string. For example, "qqoj" has $3$ proper suffixes, which are "j", "oj", and "qoj".

Input

There are multiple test cases. The first line of the input contains a single integer $T$ ($1 \le T$), indicating the number of test cases.

For each test case, the input contains a single line with a string $s$ ($1 \le |s| \le 2 \times 10^5$), indicating the human nickname.

It is guaranteed that the sum of $|s|$ over all test cases does not exceed $2 \times 10^5$.

Output

For each test case, output a single line containing one integer, indicating the answer.

Example

Input 1

6
aaa
qingyu
littlecyanfish
abacde
abcdefghbidajkad
abcdeabdfag

Output 1

3
9
27
16
58
32

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.