#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>

using namespace std;

#define len(a)            (ll) a.size()
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)
#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)

#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cincont(vec)      for (auto& it: vec) cin1(it);
#define cots(a)           cout << a << " "
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define line              cout << "\n"
#define printc(c)         for(auto it: c) {cout << it << " ";} line;
#define cotcase(cs)       cout << "Case " << cs << ": "
#define yes               cout << "Yes\n"
#define no                cout << "No\n"

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)

typedef long long int ll;

int main() {
  ll t;
  cin1(t);

  while (t--) {
    ll n;
    cin1(n);

    string str;
    cin >> str;

    ll cntOv = 0;
    ll curResult = 0;

    vector<ll> prefix;
    for (ll i = 0; i < str.size(); i++) {
      if (str[i] != '.') {
        cntOv += ll(1);
      }
      else {
        curResult += cntOv;
      }
      prefix.push_back(curResult);
    }


    cntOv = 0;
    curResult = 0;

    vector<ll> suffix(n);
    for (ll i = str.size() - 1; i >= 0; i--) {
      if (str[i] != '.') {
        cntOv++;
      }
      else {
        curResult += cntOv;
      }
      suffix[i] = curResult;
    }

    ll minVal = prefix[0] + suffix[0];
    for (ll i = 0; i < n; i++) {
      minVal = min(minVal, prefix[i] + suffix[i]);
    }
    cot1(minVal);
  }

  return 0;
}
