// Problem: E. Arranging The Sheep
// Contest: Codeforces - Codeforces Round #719 (Div. 3)
// URL: https://codeforces.com/contest/1520/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>

const int p = 1e9 + 7;
const int lim = 1e6 + 5;

// //Number theory
// int facto[lim];
// void prefacto(){
	// facto[0]=0;
	// for(int i=1; i<=lim; i++)
		// facto[i] = (facto[i-1]*i)%p;
// }

// //Graph theory
// vi status(lim, 0);
// vi adj[lim];
// void edgeInput(int m){
	// for(int i=1; i<=m; i++){
		// int a, b;
		// cin>>a>>b;
		// adj[a].push_back(b);
		// adj[b].push_back(a);
	// }
// }

//Binary search
bool check(int elem){
	return true;
}
void bsearch(){
	int lo=0, hi=1e9, res=-1, mid;
	while(lo<=hi){
		mid = lo + (hi-lo)/2;
		if(check(mid)){
			res = mid;
			hi = mid-1;
		}else{
			lo = mid+1;
		}
	}
}

//Custom comparator
struct Node{};
struct Compare{
	bool operator() (const Node &a, const Node &b){
		return true;
	}
};
bool compare(const Node &a, const Node &b){
	return true;
}

void pre_io(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}

const int l=0, r=1;
ll dp[lim][2];
int freq[lim][2];
int n;
string s;

ll fun(int idx, int dir){
	if(idx==n) return 0;
	if(idx==0) return dp[idx][dir] = 0;
	
	if(dp[idx][dir]!=-1) return dp[idx][dir];
	
	if(dir==l)
		return dp[idx][l] = (s[idx]=='*'?0:freq[idx-1][l]) + fun(idx-1, l);
	
	
	return dp[idx][r] = (s[idx]=='*'?0:freq[idx+1][r]) + fun(idx+1, r);
}

int32_t main()
{
	pre_io();
	int test;
	cin>>test;
	while(test--){
		cin>>n;
		cin>>s;
		for(int i=0; i<=n; i++){
			dp[i][l] = dp[i][r] = -1;
			freq[i][l] = freq[i][r] = 0;
		}
		
		freq[0][l] = (s[0]=='*');
		for(int i=1; i<n; i++) freq[i][l] = freq[i-1][l] + (s[i]=='*');
		
		freq[n-1][r] = (s[n-1]=='*');
		for(int i=n-2; i>=0; i--) freq[i][r] = freq[i+1][r] + (s[i]=='*');
		
		ll res = LONG_LONG_MAX;
		for(int i=0; i<n; i++){
			res = min(res, fun(i, l) + fun(i+1, r));
		}
				
		cout<<res<<"\n";
	}
}