#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e6 + 10, M = 1010, inf = 0x3f3f3f3f, mod = 1e9 + 7;
typedef long long ll;

char s[N];
ll b[N];

int main(){
    int t; cin >> t;
    while (t--){
        int n; cin >> n;
        cin >> s + 1;
        int k = 0;
        for (int i = 1; i <= n;i++) if (s[i] == '*') b[++k] = i; // 找到所有星星的位置

        for (int i = 1; i <= k;i++) b[i] -= i;   // 减去偏移量  也就是说走到前一个1的右边  又是一个计数问题

        ll res = 0;
        for (int i = 1; i <= k; i++)
            res += abs(b[i] - b[k / 2 + 1]);
        cout << res << "\n";
    }
    return 0;
}
