#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int, vector<int>, greater<int> > minheap;
typedef priority_queue<int> maxheap;
#define f(i,n) for(int i=0;i<n;++i)
#define sfor(i,s,t) for(int i=s;i<=t;++i)
#define dfor(i,s,t) for(int i=t;i>=s;--i)
#define mp make_pair
#define pb push_back
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int sheeps=0;
		f(i,n){
			if(s[i]=='*')
				sheeps++;
		}
		int median=(sheeps+1)/2;
		sheeps=0;
		int medinx=-1;
		f(i,n){
			if(s[i]=='*'){
				sheeps++;}
			//cout<<sheeps<<" "<<median<<endl;
			if(sheeps==median){
				medinx=i;
				break;
			}
		}
		//cout<<medinx<<endl;
		int cnt=0;
		ll ans=0;
		for(int j=medinx-1;j>=0;j--){
			if(s[j]=='.'){
				cnt++;
			}
			else{
				ans+=cnt;
			}
		}
		cnt=0;
		
		for(int j=medinx+1;j<n;j++){
			if(s[j]=='.'){
				cnt++;
			}
			else{
				ans+=cnt;
			}
		}
		cout<<ans<<endl;
	}
}


