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

const int N = 1e6 + 10;
typedef long long ll;
typedef pair<int, int> PII;

int t, n;
string s;
int a[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> t;
	while (t -- )
	{
		cin >> n;
		cin >> s;
		int cnt = 0;
		for (int i = 0; i < n; i ++ )
			if (s[i] == '*') a[cnt ++] = i;
		int mid = cnt / 2;
		ll sum = 0;
		for (int i = 0; i < cnt; i ++ )
		{
			sum += abs(a[i] - a[mid]) - abs(i - mid);
		}
		cout << sum << endl;
		for (int i = 0; i < cnt; i ++) a[i] = 0;
	}
	return 0;
}