#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int M=1e9+7;
long long mod(long long x){
    return ((x%M + M)%M);
}
long long add(long long a, long long b){
    return mod(mod(a)+mod(b));
}
long long mul(long long a, long long b){
    return mod(mod(a)*mod(b));
}

#define FOR(i,a,n) for(ll i=a; i<n; i++)


// **************************************** //


int main(){
  int t;cin>>t;
  while(t--){
    ll n;cin>>n;
    char a[n];
    FOR(i,0,n)cin>>a[i];
  	
  	vector<ll>v;
  	FOR(i,0,n)
  	{
  		if(a[i]=='*')
  		v.push_back(i);
	}
	
	ll x=v.size();
	
	if(x==0)
	{cout<<"0"<<endl;
	continue;}
	
	ll sum=0;
	
	if(x%2==0)
	{
		ll mid=(x/2)-1;
		ll midx=v[mid];
		
// 		cout<<"midx "<<midx<<endl;
		
		ll sum1=0;
		for(ll i=mid-1;i>=0;i--)
		{
			sum1 += abs(v[i]-midx)-1;
			midx--;	
		}
		midx=v[mid];
		for(ll i=mid+1;i<x;i++)
		{
			sum1+= abs(v[i]-midx)-1;
			midx++;
		}
		
		mid++;
		midx=v[mid];
		
// 		cout<<"midx "<<midx<<endl;
		
		ll sum2=0;
		for(ll i=mid-1;i>=0;i--)
		{
			sum2 += abs(v[i]-midx)-1;
			midx--;	
		}
		midx=v[mid];
		for(ll i=mid+1;i<x;i++)
		{
			sum2+= abs(v[i]-midx)-1;
			midx++;
		}
		
		sum=min(sum1,sum2);
	}
	else{
		
		ll mid=(x/2);
		ll midx=v[mid];
		
// 		cout<<"midx "<<midx<<endl;
		
		for(ll i=mid-1;i>=0;i--)
		{
			sum+= abs(v[i]-midx)-1;
// 			cout<<"sum "<<sum<<" ";
			midx--;	
		}
		
		midx=v[mid];
		
		for(ll i=mid+1;i<x;i++)
		{
			sum+= abs(v[i]-midx)-1;
// 			cout<<"sum "<<sum<<" ";
			midx++;
		}	
// 		cout<<endl;
	}
	
	cout<<sum<<endl;
}
  	
  return 0;
}