#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        string str;
        cin >> str;
        str = " " + str;
        vector<int> vec;
        int l = 0;
        int i;
        for(i=1;i<=n;i++)
        {
            if(str[i] == '*')
                vec.push_back(abs(i - l)), l++;
        }
        sort(vec.begin(), vec.end());
        if(vec.size() == 0)
        {
            cout << 0 << '\n';
            continue;
        }
        int pos = vec[vec.size()/2];
        int ans = 0;
        for(auto j : vec)
            ans = ans + abs(pos - j);
        cout << ans << '\n';
    }
}