#include<iostream>
#include<bits/stdc++.h>
#define ll long long int
int INF = 1e9+5;
const int mod=1e9+7;
const int N=1e5+1;
int wi[101],p[101];
int dp[3001][3001];
using namespace std;
 
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        string s;
        cin>>s;
        vector<ll> v;
        for(ll i=0;i<n;i++){
            if(s[i]=='*')
            v.push_back(i);
        }
        if(v.size()==0){
            cout<<"0\n";
            continue;
        }
        ll m=v[v.size()/2];
        ll c=0,res=0;
        for(ll i=m;i<n;i++){
            if(s[i]=='*'){
                res+=i-m-c;
                c++;
            }
        }
        c=0;
        for(int i=m;i>=0;i--){
            if(s[i]=='*'){
                res+=m-i-c;
                c++;
            }
        }
        cout<<res<<endl;
    }
    return 0;     
}