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

void solve(int tc) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> pos;
	for (int i = 0  ; i < n ; i++) {
		char ch = s[i];
		if (ch == '*') pos.push_back(i);
	}

	int sz = (int)pos.size();
	if (sz == 0) {
		cout << 0 << endl;
		return;
	}

	int median = sz / 2;
	ll ans = 0;
	for (int i = median - 1 , j = pos[median] - 1 ; i >= 0 ; i-- , j--) {
		ans += abs(pos[i] - j);
	}

	for (int i = median + 1 , j = pos[median] + 1 ; i < sz ; i++ , j++) {
		ans += abs(pos[i] - j);
	}

	cout << ans << endl;
}

int main()
{
	int t;
	cin >> t;

	while (t--)
		solve(0);
}