#include<bits/stdc++.h>
#define fi first
#define se second
#define MAXN 1e18
#define debug
using namespace std;

long long n,m,k,a,b,c,t,d;
long long X,Y;
vector<string>vs;
string s1,qs,s2,s,alph="abcdefgihjklmnopqrstubwxyz",cp;
char ch;


int main(){
    #ifdef debug_
    freopen("rectangle.in", "r", stdin);
    freopen("rectangle.out", "w", stdout);
    #endif // debug
    cin>>t;
    while(t--){
        cin>>n;
        vector<int>v;
        cin>>s;
        for (int i=0; i<n; i++){
            if (s[i]=='*'){
                v.push_back(i);
            }
        }
        a=v.size()/2;
        b=v.size();
        c=0;
        for (int i=0; i<b; i++){
            if(i!=a){
                c+=abs(v[a]-v[i])-abs(a-i);
            }
        }
        cout<<c<<endl;
    }
}
