#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define vch vector<char>
#define vstr vector<string>
#define vcust vector<custom>
#define u_set unordered_set
#define sint set<int>
#define sch set<char>
#define u_map unordered_map
#define pii pair<int, int>
#define vpii vector<pii>
#define mii map<int, int>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x)
#define trail_zero(x) __builtin_ctz(x)
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define nl cout << '\n';
using namespace std;
int cerrr = 1;
#define err cerr << "Thats GFG! " << cerrr++ << '\n'
const ll Inf = 0x3fffffffffffffff;
const int mod = 0x3b9aca07;
void debug_mode()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
struct custom
{
int a;
char b;
string c;
};
int factorial(int n) {
int prod = 1ll;
for(int i = 1; i <= n; i++) prod *= i;
return prod;
}
int comb(int n, int r) {
return (factorial(n) / (factorial(n - r) * factorial(r)));
}
void solve();
int32_t main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
//debug_mode();
// fileIO();
int TestCase = 1;
cin >> TestCase;
int case_no = 1;
while (TestCase--)
{
// cout << "Case " << case_no++ << ": ";
solve();
// cout << '\n';
}
return 0;
}
void solve()
{
int n; cin >> n;
string txt; cin >> txt;
u_map<char, int> freq;
int count = 0ll;
for(auto &&i : txt) freq[i]++;
for(auto &&i : freq){
if(i.se > 1){
count += i.se * (i.se - 1) / 2;
}
}
cout << count * 2<< '\n';
}