/* 
        ~~~~~~ @spectre900 ~~~~~~~
*/
 
#include<bits/stdc++.h>
 
#define mod 1000000007
 
#define endl "\n"
#define space " "
#define li long int
#define llli __int128
#define ld long double
#define lli long long int
#define uli unsigned long int
#define cd complex<long double>
#define pi acos((long double)(-1))
#define ulli unsigned long long int

#define ms multiset
#define uset unordered_set
#define umap unordered_map
#define priq priority_queue
#define ums unordered_multiset

#define SEED srand(18112001)
#define modinv(x) power((x),mod-2)
#define all(x) (x).begin(),(x).end()
#define getBlock(x) (((int)(sqrt(x)/100)+1)*100)
#define range(i,beg,end) for(int i=beg;i<end;i++)
#define rrange(i,end,beg) for(int i=end;i>=beg;i--)
#define itover(x) for(auto it=(x).begin();it!=(x).end();it++)
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
 
using namespace std;
 
void solve();
 
lli power(lli n,lli k){
    if(k==0)return 1;
    if(k%2)return (n*power(n,k-1))%mod;
    return power((n*n)%mod,k/2);
}
 
lli gcd(lli a,lli b){
    return b?gcd(b,a%b):a;
}
 
lli lcm(lli a,lli b){
    return (((a*b)%mod)*modinv(gcd(a,b)))%mod;
}
 
int main(){
    SEED;
    FASTIO;
    solve();
    return 0;
}
 
#define N 100000

void solve(){
    lli t;
    cin>>t;
    while(t--){
        lli n;
        cin>>n;
        string str;
        cin>>str;
        lli ans=0;
        vector<int>nums;
        for(int i=0;i<str.size();i++){
            if(str[i]=='*'){
                nums.push_back(i);
            }
        }
        if(nums.size()){
            lli ind = nums.size()/2;
            lli med = nums[ind];
            lli tempMed = med+1;
            for(int i=ind+1;i<nums.size();i++){
                ans += nums[i] - tempMed;
                tempMed++;
            }
            tempMed = med-1;
            for(int i=ind-1;i>=0;i--){
                ans += tempMed - nums[i];
                tempMed--;
            }
        }
        cout<<ans<<endl;
    }
}