#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6+5;

int t,n;
ll pref[maxn],suff[maxn];

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        string s;
        cin>>s;
        s="0"+s;
        int cnt1=0,cnt2=0;
        for(int i=1; i<=n; ++i)
        {
            if(s[i]=='*')
            {
                cnt1++;
            }
            else
            {
                cnt2++;
                pref[cnt2]=cnt1;
            }
        }
        int num=cnt2;
        cnt1=0,cnt2++;
        for(int i=n; i>=1; --i)
        {
            if(s[i]=='*')
            {
                cnt1++;
            }
            else
            {
                cnt2--;
                suff[cnt2]=cnt1;
            }
        }
        for(int i=1; i<=num; ++i) pref[i]+=pref[i-1];
        suff[num+1]=0;
        for(int i=num; i>=1; --i) suff[i]+=suff[i+1];
        ll ans=1e18;
        for(int i=0; i<=num; ++i)
            ans=min(ans,pref[i]+suff[i+1]);
        printf("%lld\n",ans);
    }
    return 0;
}
