#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MAXN = 1e6 + 100;
char str[MAXN];
int T, n;
ll pre[MAXN], suf[MAXN], pre_cnt[MAXN], suf_cnt[MAXN];

void init() {
    pre[0] = 0;
    suf[n + 1] = 0;
    pre_cnt[0] = 0;
    suf_cnt[n + 1] = 0;
}

int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        scanf("%s", str + 1);
        init();
        for (int i = 1; i <= n; i++) {
            if (str[i] == '*') {
                pre_cnt[i] = pre_cnt[i - 1] + 1;
            }
            else pre_cnt[i] = pre_cnt[i - 1];
            pre[i] = pre[i - 1] + pre_cnt[i - 1];
        }
        for (int i = n; i >= 1; i--) {
            if (str[i] == '*') {
                suf_cnt[i] = suf_cnt[i + 1] + 1;
            }
            else suf_cnt[i] = suf_cnt[i + 1];
            suf[i] = suf[i + 1] + suf_cnt[i + 1];
        }
        ll ans = -1;
        bool ext = 0;
        for (int i = 1; i <= n; i++) {
 //           printf("%d %d %d %d\n", pre[i], pre_cnt[i], suf[i], suf_cnt[i]);
            if (str[i] == '*') {
                ext = 1;
                ll cur = pre[i] - pre_cnt[i - 1] * (pre_cnt[i - 1] + 1) / 2;
                cur += suf[i] - suf_cnt[i + 1] * (suf_cnt[i + 1] + 1) / 2;
            /*    if (n == 1000000 && cur < 0) {
                    printf("%d\n%d\n%d\n%d\n", pre[i], pre_cnt[i - 1], suf[i], suf_cnt[i + 1]);
                }*/
                if (ans == -1) ans = cur;
                else ans = min(ans, cur);
            }
        }
        if (ext) printf("%lld\n", ans);
        else puts("0");
    }
    return 0;
}
