#include<iostream>
#include<string.h>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip> 
#include <cmath>
#include <cstdlib>
#include<map>
#include <ctime>
using namespace std;	
int main(){	
	long long int t;
	cin>>t;
	for(long long int mat=0;mat<t;mat=mat+1){
		long long int total;
		cin>>total;
		long long int median;
		vector<long long int> array;
		for(long long int i=0;i<total;i=i+1){
			char a;
			cin>>a;
			if(a=='*'){
				array.push_back(i);
			}
		}
		long long int n=array.size();
		if(n%2==0){
			median=n/2-1;
		}
		else{
			median=n/2;
		}
		long long int ans=0;
		for(long long int i=0;i<array.size();i=i+1){
			ans+=abs(array[i]-array[median])-abs(i-median);
		}	
		cout<<ans<<endl;
		


	}			
return 0;
}
