import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Scanner;
import java.util.Set;
public class BalancedStrings {
static int returnbalance(String input){
HashMap<Character, Integer> characters=new LinkedHashMap<>();
int count=0;
Character c=null;
for(int i=0;i<input.length();i++){
c=input.charAt(i);
if(characters.containsKey(c)==true){
count=characters.get(c);
characters.put(c, count+1);
}
else
characters.put(c,1);
}
int countunique=0;
Set<Character> s=characters.keySet();
for(Character cc:s){
count=characters.get(cc);
if(count%2==0)
countunique++;
}
if(countunique!=s.size())
return 0;
Object[] sar= s.toArray();
int len=0;
for(int i=sar.length-1;i>=0;i--){
len=len+i;
}
return len+countunique;
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int numberOfInputs=in.nextInt();
in.nextLine();
for(int i=0;i<numberOfInputs;i++){
System.out.println(BalancedStrings.returnbalance(in.nextLine()));
}
}
}
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int main()
{
int t,n;
long long ans;
string s;
map <int,long long> m;
cin >> t;
while ( t-- )
{
cin >> s;
n = (int)s.size();//calculates length of string
assert(n<=100000);//checks if n<=100000
m.clear();
dp[0] = 0;
ans = 0;
for ( int i = 1; i <= n; i++ )
dp[i] = dp[i-1]^(1<<(s[i-1]-97));
m[dp[0]]++;
for ( int i = 1; i <= n; i++ )
{
ans += m[dp[i]];
m[dp[i]]++;
}
cout << ans << endl;
}
return 0;
}