#include<iostream>
#include<cmath>
using namespace std;

int main(){
  long long int t; cin>>t;
  for(long int x=0;x<t;x++){
    long long int n; cin>>n;
    long long int sheep=0;
    char arr[n];
    for(long long int i=0;i<n;i++){
      cin>>arr[i];
      if(arr[i]=='*')sheep++;
    }
    long long int middle=(sheep-1)/2;
    long long int pos_sheep[sheep];
    long long int y=0;
    for(long long int i=0;i<n;i++){
      if(arr[i]=='*'){
        pos_sheep[y]=i;
        y++;
      }
    }
    long long int moves=0;
    for(long long int i=0;i<sheep;i++){
      moves+=abs(pos_sheep[i]-pos_sheep[middle]+(middle-i));
    }
    cout<<moves<<endl;
  }
}
