using namespace std;
#include<bits/stdc++.h>
#define int long long
signed main() {
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int pre[n], suff[n];
        int count=0;
        if(s[0]=='*') count++;
        pre[0]=0;
        suff[n-1]=0;
        for(int i=1;i<n;i++){
            if(s[i]=='*') {
                pre[i]=pre[i-1];
                count++;
            }
            else pre[i]=pre[i-1]+count;
        }
        count=0;
        if(s[n-1]=='*') count++;
        for(int i=n-2;i>=0;i--){
            if(s[i]=='*') {
                suff[i]=suff[i+1];
                count++;
            }
            else suff[i]=suff[i+1]+count;
        }
        if(n==1) cout<<0<<endl;
        else{
            int ans=pre[0]+suff[1];
            for(int i=1;i<n-1;i++){
                ans=min(ans,pre[i]+suff[i+1]);
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}