#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e6+9;
const int MAX=1e2+9;
const int MAX1=5e6+9;
const int INF=0x3f3f3f3f;
const double ep=1e-8;
const double ep1=1e-12;
const int mod=998244353;
const double inf=1e20;
const long double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PDI pair<double,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIIII pair<PII,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define PLIII pair<PLI,PII >
#define PLL pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
#define PR(x) printf("Case %d: ",(x))
#define INF 0x3f3f3f3f
typedef long double ld;
typedef unsigned long long ull;
/*
*/
int n;
ll l[maxn],r[maxn];
char s[maxn];
void solve()
{
	sd(n);
	sc(s+1);	
	rep(i,1,n+1)l[i]=r[i]=0;
	int cnt=0;
	rep(i,1,n)
	{
		l[i]=l[i-1];
		if(s[i]=='*')
		{
			cnt++;
			continue;
		}
		l[i]+=cnt;
	}
	cnt=0;
	ll ans=1e18;
	dep(i,n,1)
	{
		r[i]=r[i+1];
		if(s[i]=='*')cnt++;
		else r[i]+=cnt;
		ans=min(ans,r[i]+l[i-1]);
	}
	plld(ans);
}
int main()
{
	int T=1;
	sd(T);
	while(T--)solve();
}