#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector <int> vi;
typedef vector <vi> vii;
typedef pair<int,int> pii;
typedef int ft;
#define get getchar_unlocked
#define put putchar_unlocked
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define ln length()
#define rep(i,n) for(int i=0;i<n;i++)
#define ref(i,a,n) for(int i=a;i<=n;i++)
#define reb(i,n,a) for(int i=n;i>=a;i--)
#define all(a) a.begin(),a.end()
#define gi(n) scanf("%d",&n)
#define gii(n) scanf("%lld",&n)
#define gc(c) scanf(" %c",&c)
#define pi(n) printf("%d",n)
#define pii(n) printf("%lld",n)
#define pc(c) printf("%c",c)
#define ps printf(" ")
#define pn printf("\n")
void gl(char *str) { char c; int i=0; if((c=get())!='\n') str[i++]=c; while((c=get())!='\n') str[i++]=c;str[i]='\0'; }
void pl(char *str) { rep(i,strlen(str)) put(str[i]); }
void gfi(ft &x) {
register ft c = get(); x = 0; ft sn=1;
for(;(c<48 || c>57);c = get()) if(c=='-') sn=-1;
for(;c>47 && c<58;c = get()) {x = (x<<1) + (x<<3) + c - 48;}
x*=sn;
}
struct node {
int data;
struct node *next[26];
}*head;
typedef struct node node;
node *create() {
node *temp;
temp = (node*) malloc (sizeof(node));
rep(i,26) temp->next[i]=NULL;
return temp;
}
char str[100000],temp[100000];
int n,m,cnt=0,ans=0;
void Trie(node *ptr,int i) {
if(i<n) {
if(ptr->next[str[i]-'A']==NULL) {
cnt++;
ptr->next[str[i]-'A']=create();
Trie(ptr->next[str[i]-'A'],i+1);
} else {
Trie(ptr->next[str[i]-'A'],i+1);
}
}
}
void deallocate(node *ptr) {
if(ptr!=NULL) {
rep(i,26) {
if(ptr->next[i]!=NULL) deallocate(ptr->next[i]);
}
free(ptr);
}
}
int main() {
int t;
gfi(t); //get fast input
while(t--) {
scanf("%s",temp);
m=strlen(temp);
deallocate(head); // deallocating all memory
head=create();
ans=0;
rep(i,m) {
int k=0;
ref(j,i,m-1) {
str[k++]=temp[j];
}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