import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
int t
= Integer.
parseInt(bf.
readLine()); while(t-->0){
int n = s.length();
suffixsarray x = new suffixsarray(s);
int res = n - x.index(0);
for(int i=1; i<n; i++)
res += (n-x.index(i)) - x.lcp(i);
}
}
}
class suffixsarray {
private Suffix[] suffixes;
public suffixsarray
(String text
) { int N = text.length();
this.suffixes = new Suffix[N];
for (int i = 0; i < N; i++)
suffixes[i] = new Suffix(text, i);
}
private static class Suffix implements Comparable<Suffix> {
private final int index;
private Suffix
(String text,
int index
) { this.text = text;
this.index = index;
}
private int length() {
return text.length() - index;
}
private char charAt(int i) {
return text.charAt(index + i);
}
public int compareTo(Suffix that) {
if (this == that)
return 0; // optimization
int N
= Math.
min(this.
length(), that.
length()); for (int i = 0; i < N; i++) {
if (this.charAt(i) < that.charAt(i))
return -1;
if (this.charAt(i) > that.charAt(i))
return +1;
}
return this.length() - that.length();
}
return text.substring(index);
}
}
// length of string
public int length() {
return suffixes.length;
}
// index of ith sorted suffix
public int index(int i) {
return suffixes[i].index;
}
// longest common prefix of suffixes(i) and suffixes(i-1)
public int lcp(int i) {
return lcp(suffixes[i], suffixes[i - 1]);
}
// longest common prefix of s and t
private static int lcp(Suffix s, Suffix t) {
int N
= Math.
min(s.
length(), t.
length()); for (int i = 0; i < N; i++) {
if (s.charAt(i) != t.charAt(i))
return i;
}
return N;
}
return suffixes[i].toString();
}
// number of suffixes strictly less than query
public int rank
(String query
) { int lo = 0, hi = suffixes.length - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
int cmp = compare(query, suffixes[mid]);
if (cmp < 0)
hi = mid - 1;
else if (cmp > 0)
lo = mid + 1;
else
return mid;
}
return lo;
}
// compare query string to suffix
private static int compare
(String query, Suffix suffix
) { int N
= Math.
min(query.
length(), suffix.
length()); for (int i = 0; i < N; i++) {
if (query.charAt(i) < suffix.charAt(i))
return -1;
if (query.charAt(i) > suffix.charAt(i))
return +1;
}
return query.length() - suffix.length();
}
}