#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		//for getting input from input.txt
		freopen("input.txt", "r", stdin);
		//for writing output to output.txt
		freopen("output.txt", "w", stdout);
	#endif */
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		string s;
		cin >> s;
		long long costf[n + 1];
		costf[0] = 0;
		long long costb[n + 1];
		costb[n] = 0;
		int star = 0;
		for (int i = 1; i <= n; i++) {
			costf[i] = costf[i - 1];
			if (s[i - 1] == '*')
				star++;
			else
				costf[i] += star;
		}
		star = 0;
		for (int i = n - 1; i >= 0; i--) {
			costb[i] = costb[i + 1];
			if (s[i] == '*')
				star++;
			else
				costb[i] += star;
		}
		int count = 0;
		long long ans = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '*')
				count++;
			if (count >= (star + 1) / 2) {
				ans = costf[i + 1] + costb[i + 1];
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}