#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define ll long long
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define sdf(n) scanf("%lf",&n)
#define pdf(n) printf("%lf",n)
#define pE printf("\n")
#define ull unsigned long long
#define pb push_back
#define debug(a) cout<<a<<"??"
#define me(a)  memset(a,0,sizeof(a))
#define pre(i,beg,en) for(ll i=beg;i<=en;i++)
#define rep(i,beg,en) for(ll i=beg;i>=en;i--)
#define ph push
#define pi pair<ll,ll>
#define fi first
#define se second
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
const ll mod = 1e9 + 7;
char  s[1000010];
int main(){

      ll t;
      
      sl(t);
      
      while(t--){
      
        ll n;
      
        sl(n);
      
        cin>>(s+1);
        
        std::vector<ll> v;

        for(ll i=1;i<=n;i++){
        if(s[i]=='*'){
            v.pb(i);
        }
        }

        ll tag = (ll) v.size()/2;

        ll num=0,num1=0,ans=0;

        for(ll i=tag-1;i>=0;i--){
          num++;
          ans=ans+v[tag]-v[i]-num;
        }
      
        ll len= v.size();
       
        for(ll i=tag+1;i<len;i++){
          num1++;
          ans=ans+v[i]-v[tag]-num1;
        }
       
          pl(ans);
          pE;

      }
      
        return 0;

}
