#include <bits/stdc++.h>

using namespace std;
long long dp[2000005]{};
long long dp2[2000005]{};

int main()
{
    long long n, t;
    cin >> t;
    while (t--)
    {
        string ss;
        cin >> n;
        cin >> ss;

        memset(dp, 0, n * 8 + 40);
        memset(dp2, 0, n * 8 + 40);

        long long prev = 0;
        for (int i = 1; i <= n; i++)
        {
            if (ss[i - 1] == '.')
            {
                dp[i] = dp[i - 1] + prev;
            }
            else
            {
                prev++;
                dp[i] = dp[i - 1];
            }
        }
        prev = 0;

        for (int i = n; i > 0; i--)
        {
            if (ss[i - 1] == '.')
            {
                dp2[i] = dp2[i + 1] + prev;
            }
            else
            {
                prev++;
                dp2[i] = dp2[i + 1];
            }
        }

        long long ans = dp[n];
        for (int i = 1; i <= n - 1; i++)
        {
            ans = min(ans, dp[i] + dp2[i + 1]);
        }

        printf("%lld \n", ans);
    }
    return 0;
}