/* SHUBHAM KESHARWANI */
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main()
{fast;
test
{
ll n,i,sum=0,c=0;
cin>>n;
string s;
cin>>s;
ll dp[n];
if(s[n-1]=='*')
dp[n-1]=1;
else
dp[n-1]=0;
for(i=n-2;i>=0;i--)
{
   	if(s[i]=='*')
   	dp[i]=dp[i+1]+1;
   	else
   	dp[i]=dp[i+1];
}
sum=0;
for(i=0;i<n;i++)
{
if(s[i]=='*')
sum++;
else
{
	c+=min(sum,dp[i]);
}
}
cout<<c;
cout<<'\n';
}
    return 0;
}