#include <bits/stdc++.h>

using namespace std;

void solve () {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int64_t> pref(n, 0), suf(n, 0);

	for (int i = 0, sheep = 0, j = n - 1, sheepj = 0; i < n; ++i, --j) {
		if (s[i] == '*') {
			pref[i] = i > 0 ? pref[i - 1] : 0;
			sheep++;
		} 
		else pref[i] = i > 0 ? sheep + pref[i - 1]: 0;

		if (s[j] == '*') {
			suf[j] = j == n - 1 ? 0 : suf[j + 1];
			sheepj++;
		}
		else suf[j] = j == n - 1 ? 0 : sheepj + suf[j + 1];
	}
	int64_t ans = 1e18;

	for (int i = 0; i < n; ++i) 
		ans = min (ans, pref[i] + suf[i]);
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int tc = 1;
	cin >> tc;

	for (int i = 1; i <= tc; ++i) 
		solve ();
}

/*
	aj - j = ai - i;
	aj - j++;

*/