#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define rep(i,a,b) for(int i=a;i<b;i++);
void solve(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	vector<ll>v;
	for(int i=0;i<n;i++){
		if (s[i]=='*'){
			v.push_back(i);
		}
	}
	if (v.size()<=1 or v.size()==n){
		cout<<0<<endl;
	}
	else{
	ll mid=v.size()/2;
	ll ans=0;
	for(int i=0;i<v.size();i++){
		ans+=abs(v[i]-v[mid]);
	}
	

	if (v.size()%2==0){
		ll t1=v.size()/2;
		ll t2=v.size()/2-1;

		ll d1=t1*(t1+1)/2;
		ll d2=t2*(t2+1)/2;
		ans-=(d1+d2);
	}

	else{
		ll t1=v.size()/2;
		ll d1=t1*(t1+1)/2;
		ans-=(2*d1);
	}

	cout<<ans<<endl;
}
}
int main(){
	int t=1;
	cin>>t;
	while(t--)
	solve();
}
