#include<bits/stdc++.h>usingnamespace std;#define int long long
string str;signedmain(){int t;
cin>>t;while(t--){int n;
cin>>n;
cin>>str;int len = str.length();int k =1;while(k<len&&str[k]==str[k-1]) k++;int nx =0,ny =0;if(k==len){
cout<<n<<endl;continue;}for(int i = k;i<len;i++){if(str[i]=='R') nx++;else ny++;}int res =0;
res+=k*(n-1);
res+=nx*ny;
cout<<n*n-res<<endl;}}