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

#define pb push_back
#define ll long long
#define ull unsigned long long
#define forn(i,n) for(int i=0;i<n;++i)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
 
int main() {
	FAST_IO;
 
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		ll ans=0;

		int count=0;
		for(int i=0;s[i];++i)
			if(s[i]=='*')
				count+=1;
		if(count==0 or count==1 or count==s.size()){
			cout<<0<<"\n";
			continue;
		}

		int median=(count+1)/2;
		//cout<<"Median: "<<median<<"\n";
		int pos=0,c=0;
		while(c<median){
			if(s[pos]=='*')
				c+=1;
			pos+=1;
		}
		pos-=1;//point to median
		//cout<<"medianPOS: "<<pos<<"\n";
		int ptr=pos-1;
		for(int i=pos-1;i>=0;--i){
			if(s[i]=='*'){
				ans+=ptr-i;
				ptr-=1;
			}
		}
		//cout<<"LeftANS: "<<ans<<"\n";
		ptr=pos+1;
		for(int i=ptr;i<n;++i){
			if(s[i]=='*'){
				ans+=i-ptr;
				ptr+=1;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}