#include <stdio.h>
#include <string.h>
long long count_swaps(char *s, int n) {
int freq[26] = {0}; // frequency array for lowercase letters
long long swaps = 0;
for (int i = 0; i < n; i++) {
freq[s[i] - 'a']++; // increment frequency of each character
}
for (int i = 0; i < 26; i++) {
swaps += (freq[i] * (freq[i] - 1)) / 2; // calculate swaps for each character
}
return swaps;
}
int main() {
int T;
scanf("%d", &T);
for (int i = 0; i < T; i++) {
int N;
scanf("%d", &N);
char S[N + 1]; // +1 for null terminator
scanf("%s", S);
printf("%lld\n", count_swaps(S, N));
}
return 0;
}