#include<bits/stdc++.h>

#define st first
#define nd second

#define ll long long
#define ld long double
#define y1 yy
#define data Data

using namespace std ;

typedef pair< int , int > ii ;
typedef pair< ll , ll > lii ;
typedef pair< int , ii > iii ;

const int maxn = 1e6 + 3 ;
const int maxm = 1e6 + 3 ;
const int mod = 1e9 + 7 ;
const int oo = 1061109567 ;
const ll loo = 4557430888798830399 ;
const ld pi = 3.141592653589793238462643383279502884 ;

void input() {
    #define name "abc"
	if (fopen(name".inp" , "r") ){
        freopen(name".inp" , "r" , stdin) ;
        freopen(name".out" , "w" , stdout) ;
	}
	ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
}

int t , n ;
ll pref[maxm] , a[maxn] ;
string s ;

int main() {
	input();
	cin >> t ;
    while (t -- ) {
        cin >> n >> s ;
        s = " " + s ;
        int m = 0 ;
        for (int i = 1 ; i <= n ; ++ i) {
            if (s[i] == '*'){
                m ++ ;
                a[m] = i ;
                pref[m] = pref[m - 1] + i ;
            }
        }
        if (!m) {
            cout << "0\n" ;
            continue ;
        }
        ll suff = 0 , ans = loo ;
        for (int i = m ; i > 0 ; -- i) {
            ans = min(ans , a[i] * (i - 1) - pref[i - 1] - 1ll * i * (i - 1) / 2 + suff - a[i] * (m - i) - 1ll * (m - i) * (m - i + 1) / 2) ;
            suff += a[i] ;
        }
        for (int i = 1 ; i <= n ; ++ i) {
            pref[i] = pref[i - 1] ;
            a[i] = a[i - 1] ;
            if (s[i] == '*') {
                pref[i] += i ;
                a[i] ++ ;
            }
        }
        suff = 0 ;
        ll b = 0 ;
        for (int i = n ; i > 0 ; -- i) {
            if (s[i] == '.' && (i == n || s[i + 1] == '.')) {
                ans = min(ans , a[i] * i - pref[i] - a[i] * (a[i] - 1) / 2 + suff - b * (i + 1) - 1ll * b * (b - 1) / 2) ;
            }
            if (s[i] == '*') {
                suff += i ;
                b ++ ;
            }
        }
        cout << ans << "\n" ;
    }

	return 0;
}