#include<bits/stdc++.h>
typedef long long ll;
#define All(x) (x).begin(),(x).end()
int fuck[1000010];
int main()
{
	int T,n;
	scanf("%d",&T);
	while(T-->0)
	{
		scanf("%d",&n);
		int tot=0;
		for(int i=1;i<=n;++i)
		{
			char now=getchar();
			while((now^	'.') && (now^'*'))	now=getchar();
			if(now=='*')	fuck[++tot]=i;
		}
		int mpos=int(std::ceil(tot/2.0));
		ll ans=0;
		for(int i=1;i<=tot;++i)	ans+=std::abs(fuck[i]-fuck[mpos]+mpos-i);
		printf("%lld\n",ans);
	}
	return 0;
}
	  				 					   	  	 		 			