#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<map>
#include<cstdio>
#include<stack>
#include<set>
using namespace std;
#define endl  '\n'
#define IOS ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long, long>pll;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define re(i,a,b) for(int i = a;i <= b;i++)
#define rre(i,a) for(int i = 0;i < a;i++)
#define prre(i,a) for(int i = a;i >= 0;i--)
#define pre(i,a) for(int i = a;i > 0;i--)
#define bug system("pause")
const double eps = 1e-6;
const int N = 2e5 + 10;
const int M = 2e6 + 10;
const int mod = 1e9 + 7;

int t, n;
string s;
int main()
{
	IOS;
	cin >> t;
	while (t--)
	{
		cin >> n >> s;
		ll a = 0, cnt = 0;
		for (int i = 0; i < n; i++)
			if (s[i] == '*')cnt++;
		if (cnt == 0)
		{
			cout << 0 << endl;
			continue;
		}
		int mid = (cnt + 1) / 2;
		int tmp = 0;
		for (int i = 0; i < n; i++)
			if (s[i] == '*')
			{
				tmp++;
				if (tmp == mid)
				{
					tmp = i;
					break;
				}
			}
		ll ans = 0;
		cnt = 0;
		for (int i = 0; i < n; i++)
			if (s[i] == '*')
				ans += abs(tmp - mid + (++cnt) - i);
		cout << ans << endl;
	}
	return 0;
}