#include <bits/stdc++.h>
using namespace std;
int main() {
    long long t;
    cin >> t;
    while(t--){
        long long n;
        cin >> n;
        string str;
        cin >> str;
        long long count = 0, ans = 0;
        for(long long i = 0; i < n; i++){
            if(str[i] == '*')
                count++;
        }
        if(count == 0){
            cout << 0 << endl;
            continue;
        }
        long long index = -1;
        long long temp = 0;
        for(long long i = 0; i < n; i++){
            if(str[i] == '*'){
                temp++;
            }
            if(temp == count / 2 + 1){
                index = i;
                break;
            }
        }
        long long counter = 0;
        for(long long i = index - 1; i >= 0; i--){
            if(str[i] == '*'){
                counter++;
                ans += ((index - counter) - i);
            }
        }
        counter = 0;
        for(long long i = index + 1; i < n; i++){
            if(str[i] == '*'){
                counter++;
                ans += abs((index + counter) - i);
            }
        }
        cout << ans << endl;
    }
}
