#include<bits/stdc++.h>
using namespace std;

typedef long double ld;
#define int long long
#define largest 9223372036854775807
#define mod 1000000007
#define endl "\n"
//priority_queue <int, vector<int>, greater<int>> minheap

void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) 
{
    cerr << '{';
    __print(x.first); 
    cerr << ','; 
    __print(x.second); 
    cerr << '}';
}

template<typename T>
void __print(const T &x) 
{
    int f = 0; 
    cerr << '{'; 
    for (auto &i: x) 
        cerr << (f++ ? "," : ""), __print(i); 
    cerr << "}";
}
void _print() 
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v) 
{
    __print(t); 
    if (sizeof...(v)) 
        cerr << ", "; 
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//----------------------------------------------------------------------------------------------



void precomputation()
{
    //no precomputation
}

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;

    if(n==1)
    {
        cout<<0<<endl;
        return;
    }
    vector<int> left(n,0), right(n,0);
    debug(left,right);
    int count = 0;
    if(s[0] == '.')
    {
        count=0;
    }
    else count=1;
    for( int i = 1 ; i < n ; i++ )
    {
        if(s[i] == '.')
        {
            left[i] = left[i-1] + count;
        }
        else
        {
            left[i] = left[i-1];
            count++;
        }
    }
    if(s[n-1] == '.')
    {
        count=0;
    }
    else count=1;
    for( int i = n-2 ; i >= 0 ; i-- )
    {
        if(s[i] == '.')
        {
            right[i] = right[i+1] + count;
        }
        else
        {
            right[i] = right[i+1];
            count++;
        }
    }
    int ans = largest;
    for( int i = 0,j = 1 ; i < n-1 && j<n ; i++,j++ )
    {
        if(left[i] + right[j] < ans) ans= left[i] + right[j];
    }
    debug(left,right);
    cout<<ans<<endl;

}

//------------------------------------------------------------------------------------------------

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    precomputation();

    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}