You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.

For example, if $n=6$ and the level is described by the string "**.*..", then the following game scenario is possible:

the sheep at the $4$ position moves to the right, the state of the level: "**..*.";

the sheep at the $2$ position moves to the right, the state of the level: "*.*.*.";

the sheep at the $1$ position moves to the right, the state of the level: ".**.*.";

the sheep at the $3$ position moves to the right, the state of the level: ".*.**.";

the sheep at the $2$ position moves to the right, the state of the level: "..***.";

the sheep are lined up and the game ends.

For a given level, determine the minimum number of moves you need to make to complete the level.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 10^6$).

The second line of each test case contains a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep) — the description of the level.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.


-----Output-----

For each test case output the minimum number of moves you need to make to complete the level.


-----Examples-----

Input
5
6
**.*..
5
*****
3
.*.
3
...
10
*.*...*.**
Output
1
0
0
0
9


-----Note-----

None

Source: codeforces | Difficulty: MEDIUM
Tags: Mathematics

Greedy algorithms


Solutions:
for _ in range(int(input())):
	n = int(input())
	s = input()
	cast = s.count('*')
	c = 0
	b = 0
	for i in s:
		if i == '*':
			b += 1
		else:
			c += min(b, cast - b)
	print(c)


import math

def cal(s):
	lenS = len(s)
	sheeps = []
	ans = 0
	for i in range(lenS):
		if s[i] == '*':
			sheeps.append(i)
	if not sheeps:
		return ans
	mid = math.ceil(len(sheeps) / 2)
	midInd = sheeps[mid - 1]
	cur = 1
	for i in range(lenS):
		if s[i] == '*':
			ans += abs(midInd - i - (mid - cur))
			cur += 1
	return ans
for i in range(int(input())):
	n = int(input())
	s = input()
	print(cal(s))


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = input().rstrip()
	ch = []
	for i in range(len(arr)):
		if arr[i] == '*':
			ch.append(i)
	if ch:
		mid = ch[len(ch) // 2]
		res = 0
		check = 0
		for i in range(mid + 1, n):
			if arr[i] == '*':
				check += 1
				res += i - mid - check
		check = 0
		for i in range(mid - 1, -1, -1):
			if arr[i] == '*':
				check += 1
				res += mid - i - check
		print(res)
	else:
		print(0)


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
	n = int(input())
	ar = input()
	cs = [0] * n
	cs[0] = 1 if ar[0] == '*' else 0
	for i in range(1, n):
		cs[i] = cs[i - 1] + (1 if ar[i] == '*' else 0)
	ans = 0
	for i in range(n):
		if ar[i] == '.':
			ans += min(cs[i], cs[-1] - cs[i])
	print(ans)


t = int(input())
for i in range(t):
	N = input()
	M = input()
	T = 0
	J = 0
	ANS = 0
	for i in M:
		if i == '*':
			T += 1
	for i in M:
		if i == '*':
			J += 1
		else:
			ANS += min(J, T - J)
	print(ANS)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	for i in s:
		if i == '*':
			c += 1
	c = (c + 1) // 2
	for i in range(n):
		if s[i] == '*':
			c -= 1
		if c == 0:
			break
	cc = 0
	ans = 0
	for j in range(i - 1, -1, -1):
		if s[j] == '.':
			cc += 1
		else:
			ans += cc
	cc = 0
	for j in range(i + 1, n):
		if s[j] == '.':
			cc += 1
		else:
			ans += cc
	print(ans)


import sys
pl = 1
sys.setrecursionlimit(10 ** 5)
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

def li():
	return [int(xxx) for xxx in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = fi()
raneg = range
while t > 0:
	t -= 1
	n = fi()
	s = si()
	pre = [0] * n
	suf = [0] * (n + 1)
	if s.count('*') == 0:
		print(0)
		continue
	c = 0
	prev = -1
	for i in range(n):
		pre[i] = pre[i - 1]
		pre[i] += c * (i - prev - int(s[i] == '*'))
		prev = i
		if s[i] == '*':
			c += 1
	c = 0
	prev = n
	for i in range(n - 1, -1, -1):
		suf[i] = suf[i + 1]
		suf[i] += c * (prev - i - int(s[i] == '*'))
		prev = i
		if s[i] == '*':
			c += 1
	ans = 10 ** 18
	for i in range(n - 1):
		ans = min(ans, pre[i] + suf[i + 1])
	if ans == 10 ** 18:
		ans = 0
	print(ans)


for u in range(int(input())):
	n = int(input())
	arr = input()
	ans = []
	ans2 = []
	for i in range(n):
		if arr[i] == '*':
			ans.append(i)
	if len(ans) == 1 or len(ans) == 0:
		print(0)
	else:
		for i in range(len(ans)):
			nn = len(ans) // 2
			ans2.append(abs(ans[nn] - ans[i]) - abs(nn - i))
		print(sum(ans2))


for i in range(int(input())):
	n = int(input())
	s = input()
	j = 0
	ans = 0
	sheep = 0
	c = s.count('*')
	while sheep < c / 2:
		if s[j] == '*':
			sheep += 1
		else:
			ans += sheep
		j += 1
	while j < n:
		if s[j] == '*':
			sheep += 1
		else:
			ans += c - sheep
		j += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	sheeps = list(input().strip('.'))
	n = len(sheeps)
	total_sheeps = sheeps.count('*')
	ans = 0
	left_count = 0
	for i in range(n):
		if sheeps[i] == '.':
			ans += min(left_count, total_sheeps - left_count)
		else:
			left_count += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	sheep = []
	gap = []
	pos = -1
	pos2 = -1
	for i in range(n):
		if s[i] == '*':
			pos = i
			break
	for i in reversed(range(n)):
		if s[i] == '*':
			pos2 = i
			break
	if pos == -1:
		print(0)
		continue
	cnt = 1
	for i in range(pos + 1, pos2 + 1):
		if s[i] != s[i - 1]:
			if s[i - 1] == '*':
				sheep.append(cnt)
			else:
				gap.append(cnt)
			cnt = 1
		else:
			cnt += 1
	sheep.append(cnt)
	ans = 10000000000
	some = 0
	pref = 0
	pref_sheep = 0
	suff_sheep = sheep[0]
	for i in range(1, len(sheep)):
		suff_sheep += sheep[i]
		pref += gap[i - 1]
		some += sheep[i] * pref
	pref_sheep = 0
	ans = some
	for i in range(0, len(gap)):
		pref_sheep += sheep[i]
		suff_sheep -= sheep[i]
		cur = some
		cur += pref_sheep * gap[i]
		cur -= suff_sheep * gap[i]
		ans = min(ans, cur)
		some = cur
	print(ans)


from math import floor
import sys
from statistics import median

def triangular(n):
	return n * (n + 1) / 2
test_cases = int(sys.stdin.readline())
for _ in range(0, test_cases):
	length = int(sys.stdin.readline())
	field = sys.stdin.readline().strip()
	sheep = 0
	sheep_location = []
	for i in range(0, length):
		if field[i] == '*':
			sheep_location.append(i)
	if len(sheep_location) == 0:
		print('0')
	else:
		if len(sheep_location) % 2 == 1:
			middle = int((len(sheep_location) - 1) / 2)
			median_sheep = sheep_location[middle]
			bad = 2 * triangular(middle)
		else:
			middle = int(len(sheep_location) / 2)
			median_sheep = sheep_location[middle]
			bad = triangular(middle) + triangular(middle - 1)
		distance = 0
		for i in sheep_location:
			distance += abs(i - median_sheep)
		print(int(distance - bad))


def answer():
	last = [0] * (n + 1)
	(c1, c2, d) = (0, 0, 0)
	for i in range(n - 1, -1, -1):
		if s[i] == '*':
			c1 += 1
		else:
			d += c1
		last[i] = d
	ans = 1000000000000000.0
	(c1, c2, d) = (0, 0, 0)
	for i in range(n):
		if s[i] == '*':
			c1 += 1
		else:
			d += c1
		ans = min(ans, d + last[i + 1])
	return ans
for T in range(int(input())):
	n = int(input())
	s = input()
	print(answer())


def test():
	N = int(input())
	s = input()
	total_sheep = 0
	for c in s:
		if c == '*':
			total_sheep += 1
	sheep = 0
	moves = 0
	for c in s:
		if c == '*':
			sheep += 1
		elif sheep <= total_sheep / 2:
			moves += sheep
		else:
			moves += total_sheep - sheep
	print(moves)
T = int(input())
for i in range(T):
	test()


def solve():
	N = int(input())
	S = input()
	sheep = []
	for (i, c) in enumerate(S):
		if c == '*':
			sheep.append(i)
	center = len(sheep) // 2
	ans = sum([abs(sheep[i] - (sheep[center] - center + i)) for i in range(len(sheep))])
	print(ans)
T = int(input())
for _ in range(T):
	solve()


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print(0)
		continue
	suf = [0] * n
	pre = [0] * n
	c = 0
	if s[0] == '*':
		c = 1
	pre[0] = 0
	for i in range(1, n):
		if s[i] == '.':
			pre[i] = pre[i - 1] + c
		else:
			c += 1
			pre[i] = pre[i - 1]
	c = 0
	if s[-1] == '*':
		c = 1
	suf[-1] = 0
	for i in range(n - 2, -1, -1):
		if s[i] == '.':
			suf[i] = suf[i + 1] + c
		else:
			c += 1
			suf[i] = suf[i + 1]
	ans = pre[0] + suf[1]
	for i in range(n - 1):
		ans = min(pre[i] + suf[i + 1], ans)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input().strip())
	numSheep = 0
	for c in s:
		if c == '*':
			numSheep += 1
	count = 0
	curSheep = 0
	for c in s:
		if c == '*':
			curSheep += 1
		else:
			count += min(curSheep, numSheep - curSheep)
	print(count)


def solve(n, s):
	A = []
	for i in range(n):
		if s[i] == '*':
			A.append(i)
	if not A:
		return 0
	ans = 0
	m = len(A) // 2
	l = m - 1
	left_pos = A[m] - 1
	r = m + 1
	right_pos = A[m] + 1
	while l >= 0:
		ans += left_pos - A[l]
		left_pos -= 1
		l -= 1
	while r < len(A):
		ans += A[r] - right_pos
		right_pos += 1
		r += 1
	return ans
for nt in range(int(input())):
	n = int(input())
	s = input()
	print(solve(n, s))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('*') < 2:
		print(0)
	else:
		order_num = ceil(s.count('*') / 2)
		ind = -1
		stars = 0
		while stars != order_num:
			ind += 1
			if s[ind] == '*':
				stars += 1
		steps = 0
		pos = ind - 1
		empty_space = 0
		while pos != -1:
			if s[pos] == '*':
				steps += empty_space
			else:
				empty_space += 1
			pos -= 1
		pos = ind + 1
		empty_space = 0
		while pos != n:
			if s[pos] == '*':
				steps += empty_space
			else:
				empty_space += 1
			pos += 1
		print(steps)


import statistics
t = int(input())
for z in range(t):
	n = int(input())
	s = input()
	k = s.count('*') // 2
	l = list()
	ac = 0
	for i in range(0, n):
		if s[i] == '*':
			ac += 1
			if ac == k + 1:
				break
	c = 0
	dc = 0
	for j in reversed(range(i + 1)):
		if s[j] == '.':
			dc += 1
		else:
			c += dc
	dc1 = 0
	for j in range(i + 1, n):
		if s[j] == '.':
			dc1 += 1
		else:
			c += dc1
	print(c)


I = input
for _ in range(int(I())):
	(n, s) = (int(I()), I())
	(q, w, e, t, y) = (0, [0] * n, 0, 0, 0)
	for i in range(n):
		if s[n - 1 - i] == '*':
			q += 1
		else:
			e += q
		if s[i] == '*':
			t += 1
		else:
			y += t
		w[n - 1 - i] += e
		w[i] += y
	print(min(w))


answers = []

def solve(n, s):
	store = []
	for (i, ele) in enumerate(s):
		if ele == '*':
			store.append(i)
	length = len(store)
	if length == 0:
		answers.append(0)
		return
	median = None
	if length % 2 == 0:
		median = (store[length // 2] + store[length // 2 - 1]) // 2
	else:
		median = store[length // 2]
	hashStore = {}
	for ele in store:
		hashStore[ele] = 1
	leftLimit = median
	rightLimit = median + 1
	while leftLimit in hashStore:
		leftLimit -= 1
	while rightLimit in hashStore:
		rightLimit += 1
	newStore = {}
	count = 0
	for i in range(leftLimit, -1, -1):
		if i in hashStore:
			count += leftLimit - i
			leftLimit -= 1
	length = n
	for i in range(rightLimit + 1, length):
		if i in hashStore:
			count += i - rightLimit
			rightLimit += 1
	answers.append(count)
T = int(input())
while T:
	n = int(input())
	s = input()
	solve(n, s)
	T -= 1
for ans in answers:
	print(ans)


def check(sum_arr, a, b, d):
	count = 0
	for i in range(a, b - d, -d):
		if st[i] == '*':
			count += 1
		else:
			sum_arr[i] += count
		sum_arr[i] += sum_arr[i + d]
	return sum_arr
for _ in range(int(input())):
	n = int(input())
	st = 'o' + input() + '0'
	sum_f = [0] * (n + 2)
	sum_b = [0] * (n + 2)
	ans1 = check(sum_f, 1, n, -1)
	ans2 = check(sum_b, n, 1, 1)
	mini = 999999999999
	for i in range(1, n + 1):
		mini = min(mini, ans1[i] + ans2[i])
	print(mini)


import sys
import math
MOD = 1000000007
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = r = 0
	c = s.count('*')
	for i in s:
		if '*' < i:
			ans += min(r, c - r)
		else:
			r += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	a = []
	for c in input():
		if c == '*':
			s += 1
		else:
			a.append(s)
	res = 0
	for k in a:
		res += min(k, s - k)
	print(res)


def process(A):
	answer = 0
	n = len(A)
	A = [A[i] - i for i in range(n)]
	if n % 2 == 1:
		answer = sum(A[n // 2 + 1:]) - sum(A[:n // 2])
	else:
		answer = sum(A[n // 2:]) - sum(A[:n // 2])
	return answer
T = int(input())
for I in range(T):
	N = int(input())
	S = input()
	A = []
	for i in range(N):
		if S[i] == '*':
			A.append(i)
	print(process(A))


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
tc = 1
tc = int(input())

def minMoves(nums):
	k = nums.count(1)
	a = [i for (i, val) in enumerate(nums) if val == 1]
	a = [val - i for (i, val) in enumerate(a)]
	ans = float('inf')
	Mid = k // 2
	ans = 0
	for i in range(k):
		ans += abs(a[i] - a[Mid])
	res = ans
	left = Mid
	right = k - Mid - 1
	for i in range(Mid + 1, len(a) - right):
		res = res + (left - right) * (a[i] - a[i - 1]) - (a[i - 1] - a[i - 1 - Mid]) + (a[i + right] - a[i])
		ans = min(ans, res)
	return ans
for test in range(1, tc + 1):
	n = int(input())
	a = str(input())
	a = [1 if i == '*' else 0 for i in a]
	print(minMoves(a))


from itertools import groupby
for _ in range(int(input())):
	ans = 0
	lw = input()
	arr = input().strip('.')
	l = 0
	r = len(arr) - 1
	left = 0
	right = 0
	if len(arr) != 0:
		if arr[r] == '*':
			right += 1
		if arr[0] == '*':
			left += 1
		while l < r:
			if left <= right:
				l += 1
				if arr[l] == '*':
					left += 1
				else:
					ans += left
			else:
				r -= 1
				if arr[r] == '*':
					right += 1
				else:
					ans += right
		print(ans)
	else:
		print(0)


def sheep(n, s):
	c = s.count('*')
	ans = 0
	star = 0
	for i in range(n):
		if s[i] == '*':
			star += 1
		else:
			ans += min(star, c - star)
	return ans
for i in range(int(input())):
	n = int(input())
	s = input()
	print(sheep(n, s))


from math import comb

def a_ser(n):
	return comb(n + 1, 2)
for _ in range(int(input())):
	n = int(input())
	positions = [i for (i, c) in enumerate(input()) if c == '*']
	sheeps = len(positions)
	if sheeps == 0:
		print(0)
	else:
		m = positions[sheeps // 2]
		answer = sum([abs(m - positions[i]) for i in range(sheeps)])
		if sheeps % 2 == 0:
			answer -= a_ser(sheeps // 2 - 1) + a_ser(sheeps // 2)
		else:
			answer -= 2 * a_ser((sheeps - 1) // 2)
		print(answer)


import math

def get_min_steps(s, n):
	sheep = 0
	for x in s:
		if x == '*':
			sheep += 1
	if sheep == 0:
		return 0
	median_sheeps = math.ceil(sheep / 2)
	count = 0
	for i in range(len(s)):
		if s[i] == '*':
			count += 1
			if count == median_sheeps:
				index_mid = i
				break
	count = 0
	steps_move_left = 0
	for i in range(index_mid, -1, -1):
		if s[i] == '.':
			count += 1
		else:
			steps_move_left += count
	count = 0
	steps_move_right = 0
	for i in range(index_mid, len(s), 1):
		if s[i] == '.':
			count += 1
		else:
			steps_move_right += count
	return steps_move_left + steps_move_right
t = int(input())
while t:
	n = int(input())
	s = input()
	print(get_min_steps(s, n))
	t -= 1


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	n = int(stdin.readline())
	a = list(stdin.readline()[:-1])
	m1 = None
	m2 = None
	alls = 0
	for i in range(n):
		if a[i] == '*':
			alls += 1
	if alls <= 1:
		ANS.append('0')
		continue
	cnt = 0
	for i in range(n):
		if a[i] == '*':
			cnt += 1
		if cnt == (alls + 1) // 2:
			m1 = i
			break
	st = m1 - (alls + 1) // 2 + 1
	ans = 0
	for i in range(n):
		if a[i] == '*':
			ans += abs(i - st)
			st += 1
	ANS.append(str(ans))
print('\n'.join(ANS))


import sys
from sys import stdout
import bisect as bi
import math
from collections import defaultdict as dd
from types import GeneratorType
from collections import deque
from heapq import heapify, heappush, heappop
from itertools import permutations
import random
input = sys.stdin.readline
mo = 10 ** 9 + 7
MOD = 998244353

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def inin():
	return int(input())

def solve(a, n):
	if n % 2 != 0:
		return float(a[int(n / 2)])
	return float((a[int((n - 1) / 2)] + a[int(n / 2)]) / 2.0)

def calc(a, l, n):
	ans = 0
	for i in range(n):
		ans += abs(a[i] - l[i])
	return ans

def forma(start, n):
	return [i for i in range(start, start + n)]
for _ in range(inin()):
	n = inin()
	s = sin()
	l = []
	for i in range(n):
		if s[i] == '*':
			l += [i]
	k = len(l)
	if k == 0 or k == n:
		print(0)
	else:
		med = solve(l, k)
		if isinstance(med, float):
			med = int(med)
			if k % 2:
				a = forma(med - k // 2, k)
				ans = calc(a, l, k)
				print(ans)
			else:
				a1 = forma(med - k // 2, k)
				a2 = forma(med - k // 2 + 1, k)
				ans = min(calc(a1, l, k), calc(a2, l, k))
				print(ans)
		else:
			ans = 10 ** 9
			med = int(med)
			if k % 2:
				a = forma(med - k // 2, k)
				ans = min(calc(a, l, k), ans)
			else:
				a1 = forma(med - k // 2, k)
				a2 = forma(med - k // 2 + 1, k)
				ans = min(calc(a1, l, k), calc(a2, l, k), ans)
			med += 1
			if k % 2:
				a = forma(med - k // 2, k)
				ans = min(calc(a, l, k), ans)
			else:
				a1 = forma(med - k // 2, k)
				a2 = forma(med - k // 2 + 1, k)
				ans = min(calc(a1, l, k), calc(a2, l, k), ans)
			print(ans)

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def kadane(A):
	maxSoFar = maxEndingHere = start = end = beg = 0
	for i in range(len(A)):
		maxEndingHere = maxEndingHere + A[i]
		if maxEndingHere < 0:
			maxEndingHere = 0
			beg = i + 1
		if maxSoFar < maxEndingHere:
			maxSoFar = maxEndingHere
			start = beg
			end = i
	return (maxSoFar, start, end)

def modFact(n, p):
	if n < 0:
		return 0
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result

def ncr(n, r, p):
	if n < r or n < 0:
		return 0
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)

def hnbhai():
	n = sb()
	a = sa()
	prefix = [0 for i in range(n + 1)]
	sufix = [0 for i in range(n)]
	ans = 1 if a[0] == '*' else 0
	for i in range(1, n):
		if a[i] != '*':
			prefix[i] = prefix[i - 1] + ans
		else:
			prefix[i] = prefix[i - 1]
			ans += 1
	ans = 1 if a[-1] == '*' else 0
	for i in range(1, n):
		if a[-1 - i] != '*':
			sufix[-1 - i] = sufix[-i] + ans
		else:
			ans += 1
			sufix[-1 - i] = sufix[-i]
	min_ = float('inf')
	for i in range(n):
		min_ = min(min_, sufix[i] + prefix[i])
	print(min_)
for _ in range(sb()):
	hnbhai()


for s in [*open(0)][2::2]:
	a = 0
	c = s.count('*')
	r = 0
	for j in s:
		if j > '*':
			a += min(r, c - r)
		else:
			r += 1
	print(a)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(l, r) = (0, n - 1)
	(moveLeft, moveRight) = (0, 0)
	ans = 0
	while l <= r:
		if moveLeft <= moveRight:
			if s[l] == '*':
				moveLeft += 1
			else:
				ans += moveLeft
			l += 1
		else:
			if s[r] == '*':
				moveRight += 1
			else:
				ans += moveRight
			r -= 1
	print(ans)


def fun(st, n):
	suffix = [0 for i in range(n)]
	prefix = [0 for i in range(n)]
	count = 0
	for (i, val) in enumerate(st):
		if val == '*':
			if i == 0:
				prefix[i] = 0
				count += 1
			else:
				prefix[i] = prefix[i - 1]
				count += 1
		elif i == 0:
			prefix[i] = 0
			count += 0
		else:
			prefix[i] = prefix[i - 1] + count
			count += 0
	count = 0
	for i in range(n - 1, -1, -1):
		val = st[i]
		if val == '*':
			if i == n - 1:
				suffix[i] = 0
				count += 1
			else:
				suffix[i] = suffix[i + 1]
				count += 1
		elif i == n - 1:
			suffix[i] = 0
			count += 0
		else:
			suffix[i] = suffix[i + 1] + count
			count += 0
	ans = 10 ** 12
	for i in range(n):
		if i != n - 1:
			ans = min(ans, prefix[i] + suffix[i + 1])
		else:
			ans = min(ans, prefix[i])
	print(ans)
T = int(input())
for _ in range(T):
	n = int(input())
	st = input()
	fun(st, n)


from collections import defaultdict
from string import ascii_uppercase, ascii_lowercase

def is_square(x):
	return x ** 0.5 % 1 == 0

def arr_to_str(arr):
	return ' '.join((str(n) for n in arr))

def nested_arr_to_str(arr):
	return '\n'.join((' '.join((str(n) for n in r)) for r in arr))

def solve(s):
	sheeps = [i for i in range(len(s)) if s[i] == '*']
	n = len(sheeps)
	if n in [0, 1, len(s)]:
		return 0
	sheeps = sorted((sheeps[i] - i for i in range(n)))
	median = sheeps[n // 2]
	return sum((abs(i - median) for i in sheeps))
for _ in range(int(input())):
	input()
	s = input()
	print(solve(s))


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, stdin.readline().split())
L = lambda : list(map(int, stdin.readline().split()))
mod = 1000000009
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = I()
	s = inp()
	(c, d, e) = (0, 0, 0)
	for i in range(n):
		if s[i] == '*':
			c = c + 1
	for i in range(n):
		if s[i] == '*':
			d = d + 1
		elif d > 0 and c - d > 0:
			e = e + min(d, c - d)
	print(e)
tt = 1
tt = I()
for _ in range(tt):
	solve()


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	suf = {}
	c = 0
	prev = 0
	cur = 0
	for j in range(n - 1, -1, -1):
		if s[j] == '*':
			cur += c * (prev - j - 1)
			c += 1
			prev = j
			suf[j] = cur
	if c == 0:
		print(0)
		continue
	c = 0
	prev = 0
	cur = 0
	ans = 10 ** 18
	for j in range(n):
		if s[j] == '*':
			cur += c * (j - prev - 1)
			c += 1
			prev = j
			ans = min(ans, cur + suf[j])
	print(ans)


for t in range(int(input())):
	n = int(input())
	st = input()
	first = [[None for i in range(2)] for j in range(n)]
	second = [[None for i in range(2)] for j in range(n)]
	for i in range(n):
		if i == 0:
			if st[i] == '*':
				first[i][0] = 0
				first[i][1] = 1
			else:
				first[i][0] = 0
				first[i][1] = 0
		elif st[i] == '*':
			first[i][0] = first[i - 1][0]
			first[i][1] = first[i - 1][1] + 1
		else:
			first[i][0] = first[i - 1][0] + first[i - 1][1]
			first[i][1] = first[i - 1][1]
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			if st[i] == '*':
				second[i][0] = 0
				second[i][1] = 1
			else:
				second[i][0] = 0
				second[i][1] = 0
		elif st[i] == '*':
			second[i][0] = second[i + 1][0]
			second[i][1] = second[i + 1][1] + 1
		else:
			second[i][0] = second[i + 1][0] + second[i + 1][1]
			second[i][1] = second[i + 1][1]
	mn = float('inf')
	for i in range(n - 1):
		mn = min(mn, first[i][0] + second[i + 1][0])
	print(min(mn, first[n - 1][0]))


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	l = []
	for i in range(n):
		if s[i] == '*':
			l.append(i)
	x = len(l)
	if x == 0:
		print(0)
		continue
	med = l[x // 2]
	temp = 0
	left = med - x // 2
	for i in l:
		temp += abs(left - i)
		left += 1
	print(temp)


for _ in range(int(input())):
	n = int(input())
	s = input()
	index = []
	for i in range(n):
		if s[i] == '*':
			index.append(i)
	cnt = s.count('*')
	if cnt > 1:
		middle = cnt // 2
		start = index[middle]
		k = 0
		ans = 0
		for i in range(start - middle, start - middle + cnt):
			ans += abs(i - index[k])
			k += 1
		print(ans)
	else:
		print(0)


from copy import deepcopy
import math
from collections import defaultdict as D
from itertools import permutations
from collections import deque
import random
import copy

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def frequency(l):
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	return d

def getSum(n):
	sum = 0
	for digit in str(n):
		sum += int(digit)
	return sum

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def listToString(s):
	str1 = ' '
	return str1.join(s)

def main():
	for yu in range(int(input())):
		n = int(input())
		a = list(input())
		l = [0]
		count = 0
		for i in range(n):
			if a[i] == '*':
				l.append(l[-1])
				count += 1
			else:
				l.append(count + l[-1])
		b = a[::-1]
		r = [0]
		count = 0
		for i in range(n):
			if b[i] == '*':
				r.append(r[-1])
				count += 1
			else:
				r.append(count + r[-1])
		l = l[1:]
		r = r[1:]
		r = r[::-1]
		ans = 0
		ans = min(r[0], l[-1])
		for i in range(n - 1):
			ans = min(ans, l[i] + r[i + 1])
		print(ans)
	return
main()


from sys import stdin, stdout
t = int(stdin.readline())
for q in range(t):
	n = int(stdin.readline())
	a = list(stdin.readline())
	a.pop()
	left = [0] * n
	cnt = int(a[0] == '*')
	for i in range(1, n):
		left[i] = left[i - 1]
		if a[i] == '*':
			cnt += 1
		else:
			left[i] += cnt
	right = [0] * n
	cnt = int(a[-1] == '*')
	for i in range(n - 2, -1, -1):
		right[i] = right[i + 1]
		if a[i] == '*':
			cnt += 1
		else:
			right[i] += cnt
	mn = n ** 3
	for i in range(n - 1):
		mn = min(mn, left[i] + right[i + 1])
	mn = min(mn, left[n - 1])
	stdout.write(str(mn) + '\n')


import sys
import collections
import math
inf = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	n = int(input())
	s = input()
	u = [[0] * 2 for i in range(n)]
	v = [[0] * 2 for i in range(n)]
	for i in range(n):
		if i == 0:
			if s[i] == '*':
				u[i][0] = 0
				u[i][1] = 1
			else:
				u[i][0] = 0
				u[i][1] = 0
		elif s[i] == '*':
			u[i][0] = u[i - 1][0]
			u[i][1] = u[i - 1][1] + 1
		else:
			u[i][0] = u[i - 1][0] + u[i - 1][1]
			u[i][1] = u[i - 1][1]
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			if s[i] == '*':
				v[i][0] = 0
				v[i][1] = 1
			else:
				v[i][0] = 0
				v[i][1] = 0
		elif s[i] == '*':
			v[i][0] = v[i + 1][0]
			v[i][1] = v[i + 1][1] + 1
		else:
			v[i][0] = v[i + 1][0] + v[i + 1][1]
			v[i][1] = v[i + 1][1]
	minVal = u[-1][0]
	for i in range(n - 1):
		minVal = min(minVal, u[i][0] + v[i + 1][0])
	print(minVal)


import sys
CONST = 100030001

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
t = int(input())
while t:
	n = int(input())
	s = str(input())
	shp_idx = []
	for (idx, ch) in enumerate(s):
		if ch == '*':
			shp_idx.append(idx)
	if not shp_idx:
		print(0)
		t -= 1
		continue
	mod_idx = shp_idx[len(shp_idx) // 2]
	ans = 0
	for idx in shp_idx:
		ans += abs(mod_idx - idx)
	half = len(shp_idx) // 2
	if len(shp_idx) % 2 != 0:
		ans -= half * (half + 1)
	else:
		ans -= half * (half + 1) // 2
		ans -= half * (half - 1) // 2
	print(ans)
	t -= 1


from math import ceil

def func():
	total = sum((1 for x in range(n) if st[x] == '*'))
	if total == 0 or total == n:
		print(0)
		return
	else:
		med = ceil(total / 2)
		ind = 0
		curr = 0
		for i in range(n):
			if st[i] == '*':
				curr += 1
			if curr == med:
				ind = i
				break
		cnt = 0
		rz = 0
		for j in range(ind, -1, -1):
			if st[j] == '.':
				cnt += 1
			else:
				rz += cnt
		cnt = 0
		for j in range(ind, n):
			if st[j] == '.':
				cnt += 1
			else:
				rz += cnt
	print(rz)
for _ in range(int(input())):
	n = int(input())
	st = list(input())
	func()


from collections import defaultdict
from math import gcd

def read(test):
	n = int(input())
	s = input()
	solve(n, s)

def solve(n, s):
	a = []
	for i in range(len(s)):
		if s[i] == '*':
			a.append(i)
	if len(a) < 2:
		print(0)
		return
	mi = len(a) // 2
	m = a[mi]
	ans = 0
	i = 0
	for j in range(mi - 1, -1, -1):
		i += 1
		tmp = m - a[j] - i
		assert tmp >= 0
		ans += tmp
	i = 0
	for j in range(mi + 1, len(a)):
		i += 1
		tmp = a[j] - m - i
		assert tmp >= 0
		ans += tmp
	print(ans)
for tc in range(int(input())):
	read(tc + 1)


import math
import collections
import itertools
import bisect
for tt in range(1, int(input()) + 1):
	n = int(input())
	s = input()
	if s.count('*') == 0:
		print('0')
		continue
	one_indexes = [i for (i, x) in enumerate(s) if x == '*']
	median_count = len(one_indexes) // 2
	median_index = one_indexes[median_count]
	min_swaps = 0
	for (count, index) in enumerate(one_indexes):
		min_swaps += abs(median_index - index) - abs(median_count - count)
	print(str(min_swaps))


def solve():
	length = int(input())
	str = input()
	Csum = 0
	zero = 0
	element = []
	cumalative = []
	for x in str:
		if x == '.':
			zero = zero + 1
		elif x == '*':
			element.append(zero)
			Csum = Csum + zero
			cumalative.append(Csum)
	elen = int(len(element))
	median = int((elen - 1) / 2)
	if elen == 0:
		ans = 0
		return ans
	elif elen % 2 == 0:
		ans = cumalative[elen - 1] - 2 * cumalative[median]
		return ans
	else:
		ans = cumalative[elen - 1] - 2 * cumalative[median] + element[median]
		return ans
test = int(input())
for x in range(test):
	print(solve())


def linput():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	x = input()
	l = []
	for i in range(n):
		if x[i] == '*':
			l.append(i)
	if len(l) == 0:
		print(0)
	else:
		mid = len(l) // 2
		c = 0
		for i in range(len(l)):
			c += abs(l[mid] - l[i]) - abs(mid - i)
		print(c)


test = int(input())
for t in range(test):
	n = int(input())
	a = input()
	n = len(a)
	yn = a.count('*') - 1
	if yn <= 0:
		print(0)
		continue
	l = 0
	u = n
	while a[l] == '.':
		l += 1
	while a[u - 1] == '.':
		u -= 1
	a = a[l:u]
	l = 0
	ll = []
	c = 0
	yn = a.count('*') - 1
	if yn <= 0:
		print(0)
		continue
	for e in a:
		if e == '*':
			ll.append(l)
			c += 1
			l = 0
		else:
			l += 1
	rr = ll[1:] + [0]
	ll.reverse()
	rs = [0]
	rr.reverse()
	for e in rr[1:]:
		rs.append(rs[-1] + e)
	rs.reverse()
	rr.reverse()
	ls = [0]
	ll.reverse()
	for e in ll[1:]:
		ls.append(ls[-1] + e)
	ls.reverse()
	ll.reverse()
	rss = [rs[0]]
	for e in rs[1:]:
		rss.append(rss[-1] + e)
	lss = [ls[0]]
	for e in ls[1:]:
		lss.append(lss[-1] + e)
	for i in range(0, len(rss) - 1):
		rss[i] = rss[i] - rs[i + 1] * (i + 1)
	for i in range(0, len(lss) - 1):
		lss[i] = lss[i] - ls[i + 1] * (i + 1)
	lss.reverse()
	lul = []
	for i in range(0, len(rss)):
		if i == 0:
			lul.append(lss[i + 1])
		if i == len(rss) - 1:
			lul.append(rss[i - 1])
		else:
			lul.append(lss[i + 1] + rss[i - 1])
	print(min(lul))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ctr = 0
	main = []
	for i in range(n):
		if s[i] == '*':
			main.append(i - ctr)
			ctr += 1
	if ctr > 0:
		opt = main[ctr // 2]
	ans = 0
	for i in main:
		ans += abs(opt - i)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	r = s.count('*')
	if r == 0:
		print(0)
		continue
	c = 0
	if r % 2 == 0:
		k = r // 2
	else:
		k = r // 2 + 1
	ans = 0
	ans1 = 0
	center = None
	for j in range(n):
		if s[j] == '*':
			c = c + 1
			if c < k:
				ans = ans + j + c
			if c == k:
				center = j
				ans = ans + j
			if c > k:
				ans1 = ans1 + j - (c - k)
	print(center * k - ans + (ans1 - center * (r - k)))


t = int(input())

def getGapLength(arr, i):
	k = i
	count = 0
	while arr[k] == '.':
		count += 1
		k += 1
	return count
ns = []
levels = []
for _ in range(t):
	ns.append(int(input()))
	levels.append(list(input()))
for i in range(t):
	n = ns[i]
	level = levels[i]
	sheep = level.count('*')
	count = 0
	j = -1
	moves = 0
	while count != sheep:
		j += 1
		if level[j] == '*':
			count += 1
		elif count != 0:
			gapSize = getGapLength(level, j)
			moves += min(count * gapSize, (sheep - count) * gapSize)
			j += gapSize - 1
	print(moves)


for k in [*open(0)][2::2]:
	c = k.count('*')
	a = r = 0
	for x in k:
		if '*' < x:
			a += min(r, c - r)
		else:
			r += 1
	print(a)


def solve(s):
	ones = []
	(jumps, median, ind) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '1':
			ones.append(i)
	if len(ones) == 0:
		return jumps
	median = ones[len(ones) // 2]
	ind = median
	for i in range(ind, -1, -1):
		if s[i] == '1':
			jumps += ind - i
			ind -= 1
	ind = median
	for i in range(ind, len(s)):
		if s[i] == '1':
			jumps += i - ind
			ind += 1
	return jumps
for _ in range(int(input())):
	n = int(input())
	s = input()
	arr = []
	for i in s:
		if i == '*':
			arr.append('1')
		else:
			arr.append('0')
	print(solve(arr))


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	li = []
	for i in range(n):
		if s[i] == '*':
			li.append(i + 1)
	p = len(li)
	ans = 0
	if p == n or p == 0:
		print(ans)
	else:
		z = p // 2
		mid = li[z]
		sub = 0
		for i in range(z, p):
			ans += abs(mid - li[i])
			ans += sub
			sub -= 1
		sub = -1
		for i in range(z - 1, -1, -1):
			ans += abs(mid - li[i])
			ans += sub
			sub -= 1
		print(ans)


import sys
from collections import deque
from queue import PriorityQueue
from math import gcd
from math import log
from math import ceil
from math import pi
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
for _ in range(ii()):
	n = ii()
	s = ip()
	pre = [0 for i in range(n)]
	suf = [0 for i in range(n)]
	t = 0
	if s[0] == '*':
		t += 1
	for i in range(1, n):
		if s[i] != '*':
			pre[i] = pre[i - 1] + t
		else:
			pre[i] = pre[i - 1]
			t += 1
	t = 0
	if s[-1] == '*':
		t += 1
	for i in range(1, n):
		if s[-1 - i] != '*':
			suf[-1 - i] = suf[-i] + t
		else:
			suf[-1 - i] = suf[-i]
			t += 1
	mn = float('inf')
	for i in range(n):
		mn = min(mn, pre[i] + suf[i])
	print(mn)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = input()
	(l, r) = (0, n - 1)
	left = 0
	right = 0
	ans = 0
	while l <= r:
		steps = 0
		while l <= r and a[l] != '*':
			l += 1
			steps += 1
		ans += steps * left
		left += 1
		l += 1
		steps = 0
		while r >= l and a[r] != '*':
			r -= 1
			steps += 1
		ans += steps * right
		right += 1
		r -= 1
	print(ans)


t = int(input())
for task in range(t):
	n = int(input())
	a = input()
	sheeps = a.count('*')
	res = 0
	sheepsDone = 0
	for cell in a:
		if cell == '.':
			res += min(sheepsDone, sheeps - sheepsDone)
		else:
			sheepsDone += 1
	print(res)


for _ in ' ' * int(input()):
	n = int(input())
	s = input()
	c = [s.find('*')]
	while c[-1] != -1:
		c.append(s.find('*', c[-1] + 1))
	del c[-1]
	if len(c) < 2:
		print(0)
	else:
		a = c[len(c) // 2]
		v = sum([abs(abs(i - len(c) // 2) - abs(c[i] - a)) for i in range(len(c)) if i != len(c) // 2])
		print(v)


for _ in range(int(input())):
	n = int(input())
	string = input()
	dots = string.count('*')
	b = 0
	ans = 0
	for i in string:
		if i == '*':
			b += 1
		else:
			ans += min(b, dots - b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	string = input()
	sheepIndices = []
	for char in range(n):
		if string[char] == '*':
			sheepIndices.append(char)
	middle = len(sheepIndices) // 2
	total = 0
	for index in range(middle - 1, -1, -1):
		total += sheepIndices[index + 1] - sheepIndices[index] - 1
		sheepIndices[index] += sheepIndices[index + 1] - sheepIndices[index] - 1
	for index in range(middle + 1, len(sheepIndices)):
		total += sheepIndices[index] - sheepIndices[index - 1] - 1
		sheepIndices[index] -= sheepIndices[index] - sheepIndices[index - 1] - 1
	print(total)


def calc():
	n = int(input())
	ss = input()
	total = ss.count('*')
	c = 0
	ans = 0
	for i in range(n):
		if ss[i] == '*':
			c += 1
		else:
			ans += min([c, total - c])
	print(ans)
t = int(input())
for _i in range(t):
	calc()


from collections import defaultdict

def check(mid):
	c = 0
	cv = a[mid] - 1
	for i in range(mid - 1, -1, -1):
		c += abs(a[i] - cv)
		cv -= 1
	cv = a[mid] + 1
	for i in range(mid + 1, len(a)):
		c += abs(a[i] - cv)
		cv += 1
	return c
for i in range(int(input())):
	n = int(input())
	d = defaultdict(lambda : 0)
	s = input()
	a = []
	for j in range(n):
		if s[j] == '*':
			a.append(j)
	l = len(a)
	if l < 2:
		print(0)
	else:
		mid = l // 2
		print(check(mid))


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = []
	for i in range(n):
		if s[i] == '*':
			z.append(i)
	ans = 0
	n1 = len(z)
	x1 = z[n1 // 2] if n1 >= 1 else 0
	x2 = x1
	for i in range(n1 // 2):
		ans += x1 - z[i] - 1
		x1 -= 1
	for i in range(n1 // 2 + 1, n1):
		ans += z[i] - x2 - 1
		x2 += 1
	print(ans)


from sys import stdin
input = stdin.readline

def f(s):
	mid = len(s) // 2
	ind = []
	for i in range(0, len(s)):
		if s[i] == '*':
			ind.append(i)
	ans = 0
	try:
		mid = len(ind) // 2
		l = ind[:mid][::-1]
		lc = ind[mid]
		rc = ind[mid]
		r = ind[mid + 1:]
		for i in range(len(l)):
			ans += lc - l[i] - 1
			l[i] = lc - 1
			lc = l[i]
		for i in range(len(r)):
			ans += r[i] - rc - 1
			rc += 1
			r[i] = rc
		return ans
	except:
		return 0
for i in range(int(input())):
	a = input()
	lst = list(input().strip())
	print(f(lst))


for _ in range(int(input())):
	n = int(input())
	ans = 0
	s = list(input())
	c = s.count('*')
	i = 0
	for x in s:
		if x > '*':
			ans += min(i, c - i)
		else:
			i += 1
	print(ans)


def solve():
	n = int(input())
	s = input()
	l = 0
	r = n - 1
	while l < n and s[l] == '.':
		l += 1
	while r >= 0 and s[r] == '.':
		r -= 1
	if l >= r:
		print(0)
		return
	sr = s.count('*')
	sl = 0
	ans = 0
	for k in s:
		if k == '*':
			sl += 1
			sr -= 1
		else:
			ans += min(sl, sr)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())

def get_answer(n, s):
	total = 0
	place = []
	cur = 0
	for v in s:
		if v == '*':
			total += 1
			place.append(cur)
		cur += 1
	if total == 0:
		return 0
	i = place[total // 2]
	totalv = 0
	for j in range(total):
		totalv += abs(j + i - total // 2 - place[j])
	return totalv
for _ in range(t):
	n = int(input())
	s = input()
	print(get_answer(n, s))


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())

def sout(v):
	print(v, end=' ')

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def vow():
	return ['a', 'e', 'i', 'o', 'u']

def let():
	return [chr(i) for i in range(97, 123)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def linear_sieve(n):
	primes = []
	least_prime_divs = [0] * (n + 1)
	for i in range(2, n + 1):
		if not least_prime_divs[i]:
			least_prime_divs[i] = i
			primes.append(i)
		for p in primes:
			if i * p > n or p > least_prime_divs[i]:
				break
			least_prime_divs[i * p] = p
	return (primes, least_prime_divs)

def helper(l, r, p, b):
	if p == -1:
		return 9999999999
	ans = 0
	for i in range(p - 1, -1, -1):
		if b[i] == '*':
			ans += p - i - (r[i] - r[p])
	for i in range(p + 1, len(b)):
		if b[i] == '*':
			ans += i - p + (l[p] - l[i])
	return ans
t = ii()
while t:
	t -= 1
	n = ii()
	b = si()
	ans = 0
	left = [0 for _ in range(n + 1)]
	for i in range(1, n + 1):
		if b[i - 1] == '*':
			left[i] = left[i - 1] + 1
		else:
			left[i] = left[i - 1]
	for i in range(n):
		if b[i] == '.':
			ans += min(left[i], left[n] - left[i])
	print(ans)


import statistics
for _ in range(int(input())):
	n = int(input())
	s = input()
	p = []
	for i in range(len(s)):
		if s[i] == '*':
			p.append(i)
	if len(p) == 0:
		print(0)
	else:
		med = int(statistics.median(p))
		n = len(p)
		if n % 2 == 0:
			f = list(range(med - n // 2 + 1, med + n // 2 + 1))
		else:
			f = list(range(med - n // 2, med + n // 2 + 1))
		m = 0
		for i in range(len(p)):
			m += abs(f[i] - p[i])
		print(m)


for _ in range(int(input())):
	n = int(input())
	a = input()
	cnt = 0
	for i in a:
		if i == '*':
			cnt += 1
	pos = -1
	cur = -1
	for i in range(n):
		if a[i] == '*':
			cur += 1
			if cur == cnt // 2:
				pos = i
	ans = 0
	cur = pos - cnt // 2
	for i in range(n):
		if a[i] == '*':
			ans += abs(cur - i)
			cur += 1
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def solve():
	n = II()
	s = S()
	ans = 0
	total_num = s.count('*')
	cnt = 0
	for i in range(n):
		if s[i] == '*':
			cnt += 1
		else:
			left = cnt + 0
			right = total_num - cnt
			ans += min(left, right)
	return ans

def main():
	t = II()
	for _ in range(t):
		res = solve()
		print(res)
	return 0
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	y = 0
	b = []
	for i in range(n):
		if s[i] == '*':
			y += 1
			b.append(i)
	x = y // 2
	if len(b) == n or len(b) == 0 or len(b) == 1:
		print(0)
	else:
		moves = 0
		for i in range(len(b)):
			moves += abs(abs(b[x] - b[i] - 1) - abs(x - i - 1))
		print(moves)


from collections import defaultdict

def readInt():
	return int(input())

def readInts():
	return [int(x) for x in input().split()]

def readString():
	return input().rstrip()

def readCase():
	n = readInt()
	board = readString()
	return (n, board)

def solve(n, board):
	moves = 0
	num_sheep = board.count('*')
	target_sheep = (num_sheep + 1) // 2
	seen_sheep = 0
	target_pos = -1
	while seen_sheep < target_sheep:
		target_pos += 1
		if board[target_pos] == '*':
			seen_sheep += 1
	to_find = num_sheep - target_sheep
	found = 0
	sheep_end = 0
	while found < to_find:
		for (pos, char) in enumerate(board[target_pos + 1:]):
			if char == '*':
				moves += pos - sheep_end
				sheep_end += 1
				found += 1
	found = 0
	to_find = target_sheep - 1
	sheep_end = 0
	while found < to_find:
		for (pos, char) in enumerate(reversed(board[:target_pos])):
			if char == '*':
				moves += pos - sheep_end
				sheep_end += 1
				found += 1
	return moves
cases = readInt()
for case in range(cases):
	print(solve(*readCase()))


t = int(input())
while t != 0:
	n = int(input())
	s = input()
	list1 = []
	for i in range(n):
		if s[i] == '*':
			list1.append(i)
	med = -1
	if len(list1) == 0:
		print(0)
	elif len(list1) == 1:
		print(0)
	else:
		if len(list1) % 2 == 0:
			m = len(list1) // 2
			med = (list1[m] + list1[m - 1]) // 2
		else:
			med = len(list1) // 2
			med = list1[med]
		pos = med - 1
		ans = 0
		f = 0
		if s[med] != '*':
			pos += 1
			f = 1
		for i in range(med - 1, -1, -1):
			if s[i] == '*':
				ans += pos - i
				pos -= 1
				f = 2
		pos = med + 1
		if f == 1:
			pos -= 1
		for i in range(med + 1, n):
			if s[i] == '*':
				ans += i - pos
				pos += 1
		print(ans)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	cnt = 0
	re = 0
	for j in s:
		if j == '*':
			cnt += 1
	curr = 0
	ret = 0
	for j in s:
		if j == '*':
			curr += 1
		if j == '.':
			ret += min(curr, cnt - curr)
	print(ret)


def question5():
	N = int(input())
	string = input()
	count_upto = string.count('*')
	left = 0
	right = count_upto
	ans = 0
	for i in range(N):
		if string[i] == '*':
			left += 1
			right -= 1
		else:
			ans += min(left, right)
	return ans
remained_test_cases = int(input())
while remained_test_cases > 0:
	print(question5())
	remained_test_cases -= 1


import heapq
import sys
from collections import *
from heapq import *
import math
import bisect
from itertools import *
for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 0
	for i in range(n):
		if s[i] == '*':
			cnt += 1
	tot = (cnt + 1) // 2
	cnt = 0
	pos = -1
	for i in range(n):
		if s[i] == '*':
			cnt += 1
		if cnt == tot:
			pos = i
			break
	find = False
	div = 0
	left = 0
	right = 0
	for i in s:
		if i == '*':
			div += 1
		if div == tot:
			find = True
			continue
		if not find and i == '*':
			left += 1
		elif i == '*':
			right += 1
	summ = 0
	for i in range(n):
		if s[i] == '*' and i < pos:
			temp = pos - left
			summ += abs(temp - i)
			left -= 1
		elif s[i] == '*' and i > pos:
			temp = pos + 1
			summ += abs(temp - i)
			right -= 1
			pos += 1
	print(summ)


import sys, os, io
import math, bisect, operator, itertools
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
for _ in range(test):
	(n,) = Neo()
	s = input()
	A = [i for i in range(len(s)) if s[i] == '*']
	m = len(A) // 2
	ans = 0
	for i in range(len(A)):
		ans += abs(A[m] - A[i]) - abs(m - i)
	print(max(0, ans))


def solve(n, s):
	ans = []
	for i in range(n):
		if s[i] == '*':
			ans.append(i)
	if len(ans) < 2:
		print('0')
		return
	mid = ans[len(ans) // 2]
	c = 0
	tmp = 0
	for i in range(len(ans) // 2 - 1, -1, -1):
		c += mid - tmp - ans[i] - 1
		tmp += 1
	tmp = 0
	for i in range(len(ans) // 2 + 1, len(ans)):
		c += ans[i] - (mid + tmp) - 1
		tmp += 1
	print(c)
for _ in range(int(input())):
	n = int(input())
	s = str(input())
	solve(n, s)


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	temp = []
	ans = 0
	res = 0
	for i in range(n):
		if s[i] == '*':
			temp.append(i)
			ans += 1
	ans = ans // 2
	if ans != 0:
		x = temp[ans] + 1
		for i in range(ans + 1, len(temp)):
			res += abs(temp[i] - x)
			x += 1
		x = temp[ans] - 1
		for i in range(ans):
			res += x - temp[i]
			x -= 1
	print(res)


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	l = []
	for i in range(n):
		if s[i] == '*':
			l.append(i)
	x = len(l)
	if x == 0:
		print(0)
		continue
	med = l[x // 2]
	if x % 2:
		temp = 0
		left = med - x // 2
		right = med + x // 2
		for i in l:
			temp += abs(left - i)
			left += 1
		ans = temp
	else:
		temp1 = 0
		temp2 = 0
		left = med - x // 2 - 1
		for i in l:
			temp1 += abs(left - i)
			left += 1
		left = med - x // 2
		for i in l:
			temp2 += abs(left - i)
			left += 1
		ans = min(temp1, temp2)
		temp1 = 0
		temp2 = 0
		med = l[x // 2 - 1]
		left = med - x // 2 - 1
		for i in l:
			temp1 += abs(left - i)
			left += 1
		left = med - x // 2
		for i in l:
			temp2 += abs(left - i)
			left += 1
		ans = min(ans, temp1, temp2)
	print(ans)


import sys, os, io
from sys import stdin, stdout
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import bisect
import math
input = stdin.readline
alphabets = 'abcdefghijklmnopqrstuvwxyz'

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mi():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)

def dfs(node, vis, adj, lis):
	lis.append(node)
	vis[node] = 1
	for i in adj[node]:
		if vis[i] == 0:
			dfs(i, vis, adj, lis)

def dfsOfGraph(n, adj):
	lis = []
	vis = [0] * (n + 1)
	for i in range(1, n + 1):
		if vis[i] == 0:
			dfs(i, vis, adj, lis)
	return lis

def bfsOfGraph(n, adj):
	vis = [0] * (n + 1)
	lis = []
	for i in range(1, n + 1):
		if vis[i] == 0:
			queue = [i]
			vis[i] = 1
			while len(queue) > 0:
				node = queue.pop(0)
				lis.append(node)
				for j in adj[node]:
					if vis[j] == 0:
						queue.append(j)
						vis[j] = 1
	return lis
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = ii()
	s = input()[:-1]
	l = []
	for i in range(n):
		if s[i] == '*':
			l.append(i)
	md = len(l) // 2
	ans = 0
	for i in range(len(l)):
		st = l[i]
		dt = l[md] - (md - i)
		ans += abs(dt - st)
	print(ans)
t = ii()
for _ in range(t):
	solve()


def solve(n: int, s: str) -> int:
	left = 0
	right = 0
	for x in s:
		if x == '*':
			right += 1
	ans = 0
	for x in s:
		if x == '*':
			left += 1
			right -= 1
		else:
			ans += min(left, right)
	return ans
test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	s = input()
	print(solve(n, s))


for q in range(int(input())):
	n = int(input())
	s = input()
	S = s.count('*')
	k = 0
	ans = 0
	for i in range(n):
		if s[i] == '.':
			ans += min(k, S - k)
		else:
			k += 1
	print(ans)


import sys
import bisect
from collections import deque

def solve():
	N = int(input())
	S = input().strip()
	p = []
	left = 0
	right = 0
	for i in range(N):
		if S[i] == '*':
			left = i
			break
	for i in range(N - 1, -1, -1):
		if S[i] == '*':
			right = i
			break
	for i in range(left, right):
		if S[i] == '.':
			p.append(i)
	ans = 0
	left_index = 0
	right_index = len(p) - 1
	while left_index <= right_index:
		if p[left_index] - left <= right - p[right_index]:
			ans += p[left_index] - left
			left += 1
			left_index += 1
		else:
			ans += right - p[right_index]
			right -= 1
			right_index -= 1
	print(ans)
	return
T = int(input())
for i in range(T):
	solve()


import collections
import itertools
import sys

def read_ints():
	return map(int, sys.stdin.readline().split())

def read_string():
	return sys.stdin.readline()[:-1]

def f(p_seq, start_p):
	result = 0
	for (p, p_need) in enumerate(p_seq, start_p):
		result += abs(p_need - p)
	return result

def main():
	(t_n,) = read_ints()
	for i_t in range(t_n):
		(n,) = read_ints()
		s = read_string()
		p_seq = [p for (p, ch) in enumerate(s) if ch == '*']
		min_start = 0
		max_start = len(s) - len(p_seq)
		while min_start != max_start:
			mid_start = (min_start + max_start) // 2
			assert mid_start < max_start
			if f(p_seq, mid_start) <= f(p_seq, mid_start + 1):
				max_start = mid_start
			else:
				min_start = mid_start + 1
		start = min_start
		result = f(p_seq, start)
		print(result)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	lst = []
	for (i, c) in enumerate(s):
		if c == '*':
			lst.append(i)
	mid = len(lst) // 2
	total = 0
	for item in lst:
		total += abs(lst[mid] - item)
	left = mid
	right = len(lst) - 1 - mid
	total = total - (left * (left + 1) // 2 + right * (right + 1) // 2)
	print(total)


def solve(n, sheeps):
	result = count = index = 0
	for i in sheeps:
		if i == '*':
			count += 1
	count = (count + 1) // 2
	for i in range(n):
		if sheeps[i] == '*':
			count -= 1
		if count == 0:
			index = i
			break
	step = temp = 0
	j = i - 1
	while j >= 0:
		if sheeps[j] == '.':
			temp += 1
		else:
			step += temp
		j -= 1
	result += step
	step = temp = 0
	j = i + 1
	while j < n:
		if sheeps[j] == '.':
			temp += 1
		else:
			step += temp
		j += 1
	result += step
	return result
t = int(input())
for i in range(t):
	n = int(input())
	sheeps = input()
	print(solve(n, sheeps))


for t in range(int(input())):
	n = int(input())
	s = input()
	sheeps = s.count('*')
	if sheeps == 0 or sheeps == 1 or sheeps == n:
		print(0)
		continue
	moves = scnt = 0
	i = 0
	while i < n:
		if s[i] == '*':
			scnt += 1
		elif scnt < (sheeps + 1) // 2:
			moves += scnt
		else:
			moves += sheeps - scnt
		i += 1
	i = n - 1
	scnt = 0
	print(moves)


rn = lambda : int(input())
rl = lambda : [x for x in input().split()]
rln = lambda : [int(x) for x in input().split()]
rlfn = lambda : [float(x) for x in input().split()]

def solve():
	k = rn()
	l = input()
	vacas = 0
	vacas_tot = sum([1 if c == '*' else 0 for c in l])
	tot = 0
	for c in l:
		if c == '*':
			vacas += 1
		else:
			tot += min(vacas, vacas_tot - vacas)
	return [tot]
tests = rn()
for tc in range(1, tests + 1):
	rta = solve()
	print(' '.join(map(str, rta)))


import sys

def f(s, n):
	if n == 1:
		print(0)
	else:
		nos = 0
		l = []
		for i in range(n):
			if s[i] == '*':
				nos = nos + 1
				l.append(i)
		if nos == 0 or nos == 1:
			print(0)
		else:
			mid = nos // 2
			alpha = l[mid] - mid
			ans = 0
			for j in range(nos):
				ans = ans + abs(alpha + j - l[j])
			print(ans)
t = int(input())
i = 0
while i != t:
	i = i + 1
	n = int(input())
	s = input()
	f(s, n)


def solve_the_problem():
	n = int(input())
	s = input().strip()
	cnt = s.count('*')
	pos = -1
	cur = -1
	for i in range(n):
		if s[i] == '*':
			cur += 1
			if cur == cnt // 2:
				pos = i
	ans = 0
	cur = pos - cnt // 2
	for i in range(n):
		if s[i] == '*':
			ans += abs(cur - i)
			cur += 1
	print(ans)
t = int(input())
for i in range(t):
	solve_the_problem()


import os
import sys
from io import BytesIO, IOBase
from collections import Counter

def main():
	for _ in range(int(input())):
		n = int(input())
		s = list(input().rstrip())
		right = [0] * (n + 1)
		z = 0
		for i in range(n - 1, -1, -1):
			right[i] += right[i + 1]
			if s[i] == '*':
				z += 1
			else:
				right[i] += z
		left = [0] * (n + 1)
		z = 0
		for i in range(n):
			left[i + 1] = left[i]
			if s[i] == '*':
				z += 1
			else:
				left[i + 1] += z
		mi = left[-1]
		for i in range(n):
			mi = min(mi, left[i] + right[i])
		print(mi)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


tc = int(input())
for _ in range(tc):
	n = int(input())
	s = input()
	o = []
	for i in range(n):
		if s[i] == '*':
			o.append(i)
	m = (len(o) + 1) // 2 - 1
	s = 0
	for i in range(len(o)):
		s += abs(o[m] - o[i]) - abs(m - i)
	print(s)


def solve(n: int, s: str) -> int:
	locs = []
	for i in range(n):
		if s[i] == '*':
			locs.append(i)
	if not locs:
		return 0
	median = locs[len(locs) // 2]
	split = len(locs) // 2
	ans = 0
	for x in locs:
		ans += abs(median - split - x)
		split -= 1
	return ans
test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	s = input()
	print(solve(n, s))


for _ in range(int(input())):
	l = int(input())
	a = input()
	c = a.count('*')
	start = a.index('*') if '*' in a else 0
	e = a[::-1].index('*') if '*' in a else 0
	end = l - e - 1
	dif = end - start + 1
	if dif == c or dif == 0:
		print(0)
	else:
		left = 0
		ans = 0
		for i in range(start, end):
			if a[i] == '*':
				left += 1
			else:
				ans += min(left, c - left)
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = []
	for i in range(n):
		if s[i] == '*':
			l.append(i)
	mid = len(l) // 2
	if mid > 0:
		mid = l[mid]
		c = 0
		ans = 0
		for i in range(mid, -1, -1):
			if s[i] == '.':
				c += 1
			elif s[i] == '*':
				ans += c
		c = 0
		for i in range(mid + 1, n):
			if s[i] == '.':
				c += 1
			elif s[i] == '*':
				ans += c
		print(ans)
	else:
		print(0)


def main():
	t = int(input().strip())
	for _ in range(t):
		n = int(input().strip())
		s = input().strip()
		idx = []
		for (i, c) in enumerate(s):
			if c == '*':
				idx.append(i)
		res = 0
		for i in range(int(len(idx) // 2)):
			res += idx[-i - 1] - idx[i]
		if len(idx) % 2:
			res -= len(idx) // 2 * (len(idx) // 2 + 1)
		else:
			res -= len(idx) // 2 * len(idx) // 2
		print(res)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [1 if i == '*' else 0 for i in input()]
	ships = sum(arr)
	left = 0
	right = n - 1
	ans = 0
	i = 1
	while right - left > 0 and ships >= 2:
		ships -= 2
		while arr[left] != 1:
			left += 1
		while arr[right] != 1:
			right -= 1
		ans += right - left - 1 - ships
		right -= 1
		left += 1
	print(ans)


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	list1 = list(input())
	dots = list1.count('.')
	left = 0
	right = n - 1
	count = 0
	while left < right:
		if list1[left] == '*' and list1[right] == '*':
			count += dots
			left += 1
			right -= 1
		if list1[left] == '.':
			left += 1
			dots -= 1
		if list1[right] == '.':
			right -= 1
			dots -= 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = s.count('*')
	if x == 0:
		print(0)
	else:
		c = 0
		mid = 0
		ans = 0
		for i in range(n):
			if s[i] == '*':
				c += 1
			if c == x // 2:
				mid = i
		c = 0
		for i in range(mid, -1, -1):
			if s[i] == '*':
				ans += c
			else:
				c += 1
		c = 0
		for i in range(mid + 1, n):
			if s[i] == '*':
				ans += c
			else:
				c += 1
		print(ans)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = []
	ans2 = 0
	for i in range(n):
		if s[i] == '*':
			ans.append(i)
	if len(ans) < 2:
		print(0)
		continue
	for i in range(len(ans)):
		k = len(ans) // 2
		ans2 += abs(ans[k] - ans[i]) - abs(k - i)
	print(ans2)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	s = S()
	a = [0] * n
	b = [0] * n
	cnt = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '*':
			cnt += 1
			a[i] = a[min(n - 1, i + 1)]
		else:
			a[i] = cnt + a[min(n - 1, i + 1)]
	ans = inf
	cnt = 0
	for i in range(n):
		if s[i] == '*':
			cnt += 1
			b[i] = b[max(0, i - 1)]
		else:
			b[i] = cnt + b[max(0, i - 1)]
			ans = min(b[max(0, i - 1)] + a[i], a[min(n - 1, i + 1)] + b[i], ans)
	print(0 if ans == inf else ans)


t = int(input())
for abracadabra in range(t):
	N = int(input())
	s = input()
	ship = []
	n = 0
	for i in range(N):
		if s[i] == '*':
			ship.append(i)
			n += 1
	if n == 0:
		print(0)
	else:
		pref = [0] * n
		suff = [0] * n
		for i in range(1, n):
			pref[i] = pref[i - 1] + (ship[i] - ship[i - 1] - 1) * i
		for i in range(n - 2, -1, -1):
			suff[i] = suff[i + 1] + (ship[i + 1] - ship[i] - 1) * (n - i - 1)
		ans = 1000000000000000
		for i in range(n):
			ans = min(ans, pref[i] + suff[i])
		print(ans)


for a0 in range(int(input())):
	n = int(input())
	l = [x for x in input().strip()]
	ss = []
	s = 0
	ans = 0
	for i in l:
		if i == '*':
			s += 1
		elif s > 0:
			ss.append(s)
	for i in ss:
		ans += min(i, s - i)
	print(ans)


import sys
from os import path
import math
import time
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)
MOD = 10 ** 9 + 7
INT_MAX = 10 ** 9
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def test_case():
	t = int(input())
	for _ in range(t):
		n = int(input())
		level = input()
		s_indx = []
		count = 0
		for i in range(n):
			if level[i] == '*':
				s_indx.append(i)
				count += 1
		l = len(s_indx)
		mid_s = int((count + 1) // 2)
		count = 0
		for i in range(n):
			if level[i] == '*':
				count += 1
				if count == mid_s:
					break
		count = 0
		ans = 0
		for j in range(i, -1, -1):
			if level[j] == '.':
				count += 1
			else:
				ans += count
		count = 0
		for j in range(i + 1, n):
			if level[j] == '.':
				count += 1
			else:
				ans += count
		print(ans)
test_case()


from sys import stdin
from bisect import bisect_left
from math import inf

def solve(tc):
	n = int(stdin.readline().strip())
	sea = stdin.readline().strip()
	ships = []
	for i in range(n):
		if sea[i] == '*':
			ships.append(i)
	if len(ships) <= 1:
		print(0)
		return
	m = len(ships)
	pick = m // 2
	ans = inf
	cnt = 0
	ref = ships[pick] + 1
	for i in range(pick + 1, m):
		cnt += ships[i] - ref
		ref += 1
	ref = ships[pick] - 1
	for i in range(pick - 1, -1, -1):
		cnt += ref - ships[i]
		ref -= 1
	ans = min(ans, cnt)
	if m & 1 == 0 and pick + 1 < m:
		pick += 1
		cnt = 0
		ref = ships[pick] + 1
		for i in range(pick + 1, m):
			cnt += ships[i] - ref
			ref += 1
		ref = ships[pick] - 1
		for i in range(pick - 1, -1, -1):
			cnt += ref - ships[i]
			ref -= 1
		ans = min(ans, cnt)
	print(ans)
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


for s in [*open(0)][2::2]:
	a = [i for (i, x) in enumerate(s) if '*' == x]
	m = len(a)
	r = 0
	for i in range(m // 2):
		r += a[~i] - a[i] - m + i * 2 + 1
	print(r)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		a = []
		cnt = 0
		for i in range(n):
			if s[i] == '*':
				a.append(i - cnt)
				cnt += 1
		if not a:
			print(0)
		else:
			median = a[len(a) // 2]
			ans = 0
			for elem in a:
				ans += abs(elem - median)
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = [0] * n
	b = [0] * n
	l = 0
	r = n - 1
	for i in range(n):
		if s[i] == '.':
			a[i] = i - l
			l += 1
	for i in range(n - 1, -1, -1):
		if s[i] == '.':
			b[i] = r - i
			r -= 1
	ans = 0
	for i in range(n):
		ans += min(a[i], b[i])
	print(ans)


import sys, math, bisect
from heapq import *
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def SieveOfEratosthenes(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	cnt = 0
	for i in s:
		if i == '*':
			cnt += 1
	if cnt == 0 or cnt == n:
		print(0)
	else:
		mid = (cnt + 1) // 2
		l_ind = -1
		r_ind = -1
		c = 0
		indMid = -1
		for i in range(n):
			if s[i] == '*':
				c += 1
				if c == mid:
					indMid = i
					break
		cnt = 0
		rz = 0
		for j in range(indMid, -1, -1):
			if s[j] == '.':
				cnt += 1
			else:
				rz += cnt
		cnt = 0
		for j in range(i + 1, n):
			if s[j] == '.':
				cnt += 1
			else:
				rz += cnt
		print(rz)


def main():
	import sys
	read = sys.stdin.read
	readline = sys.stdin.readline
	INF = float('INF')
	MOD = 10 ** 9 + 7
	sys.setrecursionlimit(10 ** 5)
	from itertools import accumulate
	T = int(readline())
	for _ in range(T):
		N = int(readline())
		S = readline().rstrip()
		A = [i for i in range(N) if S[i] == '*']
		if not A:
			print(0)
			continue
		l = len(A)
		L = [0] * l
		R = [0] * l
		for i in range(1, l):
			L[i] = L[i - 1] + A[i - 1]
		for i in reversed(range(l - 1)):
			R[i] = R[i + 1] + A[i + 1]
		ans = INF
		for i in range(l):
			x = i
			y = l - (i + 1)
			score = 0
			score += x * A[i]
			score -= L[i]
			score -= x * (x + 1) // 2
			score += R[i]
			score -= y * A[i]
			score -= y * (y + 1) // 2
			ans = min(ans, score)
		print(ans)
main()


t = int(input())

def arrange(s, length):
	A = []
	count = 0
	for i in range(length):
		if s[i] == '*':
			A.append(i)
	mid = len(A) // 2
	for x in A:
		count += abs(x - A[mid])
	l = len(A)
	if l % 2 == 0:
		sub = l * l // 4
	else:
		sub = (l * l - 1) // 4
	return count - sub
for i in range(t):
	length = int(input())
	string = str(input())
	print(arrange(string, length))


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def main():
	t = inpu()
	for _ in range(t):
		n = inpu()
		s = inp()
		X = []
		Y = 0
		for i in range(n):
			if s[i] == '*':
				X.append(i - Y)
				Y += 1
		if len(X) == 0:
			print(0)
			continue
		Z = X[len(X) // 2]
		ANS = 0
		for i in range(len(X)):
			ANS += abs(X[i] - Z)
		print(ANS)
main()


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	c = 0
	for i in range(n):
		if s[i] == '*':
			c += 1
	b = 0
	for i in range(n):
		if s[i] == '*':
			b += 1
			if b == (c + 1) // 2:
				b = i
				break
	d = i
	i = b - 1
	sol = 0
	while i >= 0:
		if s[i] == '*':
			sol += b - i - 1
			b -= 1
		i -= 1
	i = d + 1
	d += 1
	while i < n:
		if s[i] == '*':
			sol += i - d
			d += 1
		i += 1
	print(sol)


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	s = input()
	c = 0
	for i in range(len(s)):
		if s[i] == '*':
			c += 1
	k = c // 2 + 1
	c = 0
	for i in range(len(s)):
		if s[i] == '*':
			c += 1
		if c == k:
			break
	median = i
	j = median - 1
	i = median
	c = 0
	while j >= 0:
		if s[j] == '*':
			c += i - j - 1
			i = i - 1
		j -= 1
	i = median
	j = median + 1
	while j < len(s):
		if s[j] == '*':
			c += j - i - 1
			i = i + 1
		j += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	psl = [0]
	cc = 0
	for i in range(n):
		if s[i] == '*':
			psl.append(psl[-1])
			cc += 1
		else:
			psl.append(psl[-1] + cc)
	s = s[::-1]
	psr = [0]
	cc = 0
	for i in range(n):
		if s[i] == '*':
			psr.append(psr[-1])
			cc += 1
		else:
			psr.append(psr[-1] + cc)
	ans = 1000000000000
	psl = psl[1:]
	psr = psr[1:]
	psr = psr[::-1]
	for i in range(n):
		ans = min(ans, psl[i] + psr[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = [i for i in range(n) if s[i] == '*']
	if a:
		i = len(a) // 2
		print(sum((abs(a[i] - a[j] - (i - j)) for j in range(len(a)))))
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(done, c) = (0, s.count('*'))
	min_moves = 0
	for char in s:
		if char == '*':
			done += 1
		else:
			min_moves += min(done, c - done)
	print(min_moves)


for s in [*open(0)][2::2]:
	a = [i for (i, x) in enumerate(s) if '*' == x]
	m = len(a)
	r = 0
	for (x, y) in zip(a[:m // 2], a[::-1]):
		r += y - x - m + 1
		m -= 2
	print(r)


for v in range(int(input())):
	n = int(input())
	a = list(input())
	ans = []
	for i in range(n):
		if a[i] == '*':
			ans.append(i)
	if ans == []:
		print(0)
		continue
	fans = 0
	fans1 = 0
	lans = len(ans)
	strike = lans // 2
	strika = ans[strike]
	for i in range(lans):
		fans += abs(strika - ans[i]) - abs(strike - i)
	print(fans)


from itertools import combinations, accumulate, groupby, count
from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
num = int(z())
for _ in range(num):
	n = int(z())
	arr = fast()
	cnt = 0
	for i in arr:
		cnt += 1 if i == '*' else 0
	pos = -1
	cur = -1
	for i in range(n):
		if arr[i] == '*':
			cur += 1
			if cur == cnt // 2:
				pos = i
	ans = 0
	cur = pos - cnt // 2
	for i in range(n):
		if arr[i] == '*':
			ans += abs(cur - i)
			cur += 1
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def lsi():
	return list(msi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def ceil2(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, factorial, cos, tan, sin, radians, floor, sqrt, ceil, log2
import bisect
import random
import string
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def gcd1(a):
	if len(a) == 1:
		return a[0]
	ans = a[0]
	for i in range(1, len(a)):
		ans = gcd(ans, a[i])
	return ans

def mykey(x):
	return len(x)

def main():
	for _ in range(ii()):
		n = ii()
		s = si()
		l = []
		for i in range(n):
			if s[i] == '*':
				l.append(i)
		if len(l) <= 1:
			print(0)
			continue
		x = len(l)
		c = x // 2
		y = l[c] - c
		ans = 0
		for i in range(len(l)):
			ans += abs(y - l[i])
			y += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, os, io
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [i for i in input().strip()]
	pref = [0] * n
	suff = [0] * n
	cnt = 0
	for i in range(n):
		if a[i] == '*':
			cnt += 1
		else:
			pref[i] = cnt
	cnt = 0
	for i in range(n - 1, -1, -1):
		if a[i] == '*':
			cnt += 1
		else:
			suff[i] = cnt
	for i in range(1, n):
		pref[i] += pref[i - 1]
		suff[n - i - 1] += suff[n - i]
	ans = pref[-1]
	for i in range(n - 1):
		ans = min(pref[i] + suff[i + 1], ans)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	sheep = 0
	for i in s:
		if i == '*':
			sheep += 1
	ans = 0
	count = 0
	idx = -1
	for i in range(n):
		if s[i] == '*':
			count += 1
			if count > sheep / 2:
				idx = i
				break
		else:
			ans += count
	count = 0
	for i in range(n - 1, idx, -1):
		if s[i] == '*':
			count += 1
		else:
			ans += count
	print(ans)


import math

def solve(n: int, s: str) -> int:
	locs = []
	for i in range(n):
		if s[i] == '*':
			locs.append(i)
	if not locs:
		return 0
	if len(locs) % 2:
		median = locs[len(locs) // 2]
		u_median = l_median = median
		u_split = 1
		l_split = len(locs) // 2
	else:
		median = (locs[len(locs) // 2] + locs[len(locs) // 2 - 1]) / 2
		if median % 1:
			u_median = math.ceil(median)
			l_median = math.floor(median)
		else:
			u_median = median + 1
			l_median = median
		u_split = 0
		l_split = len(locs) // 2 - 1
	ans = 0
	for x in locs:
		if x <= l_median:
			ans += abs(l_median - l_split - x)
			l_split -= 1
		else:
			ans += abs(u_median + u_split - x)
			u_split += 1
	return int(ans)
test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	s = input()
	print(solve(n, s))


import re
t = int(input())
while t:
	n = int(input())
	s = input()
	s = s.replace('.', ' ')
	s = s.strip()
	s = s.replace(' ', '.')
	l = s
	s = s.split('.')
	if len(s) == 1:
		print(0)
	else:
		count = len(re.findall('[*]', l))
		c = 0
		steps = 0
		for i in l:
			if i == '*':
				c += 1
			elif c > count - c:
				steps += count - c
			else:
				steps += c
		print(steps)
	t -= 1


import os, sys, threading
from io import BytesIO, IOBase
threading.stack_size(2 ** 25)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
from bisect import bisect_right
mod = 10 ** 9 + 7

def check(a, t):
	ans = 0
	n = len(a)
	z = a[t] - 1
	for i in range(t - 1, -1, -1):
		ans += abs(z - a[i])
		z -= 1
	z = a[t] + 1
	for i in range(t + 1, n):
		ans += abs(a[i] - z)
		z += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	a = input()
	ct = 0
	ck = []
	tot = 0
	for i in range(n):
		if a[i] == '*':
			ck.append(i)
			tot += i
			ct += 1
	if ct == 0:
		print(0)
		continue
	z1 = ct // 2
	cka = []
	cka.append(check(ck, z1))
	print(min(cka))


import sys, os
try:
	(sys.stdin, sys.stdout) = (open('pyar_do.txt', 'r'), open('pyar_lo.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
from collections import defaultdict
for test in range(ii1()):
	n = ii1()
	s = is1()
	arr = []
	for (idx, v) in enumerate(s):
		if v == '*':
			arr.append(idx + 1)
	N = len(arr)
	if N <= 1:
		print(0)
		continue
	idx = N // 2
	val = arr[idx]
	ans = 0
	temp = val
	for i in range(idx + 1, N):
		temp += 1
		ans += abs(arr[i] - temp)
	temp = val
	for i in range(idx - 1, -1, -1):
		temp -= 1
		ans += abs(arr[i] - temp)
	print(ans)


import math
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	s = input()
	c = s.count('*')
	c = math.ceil(c / 2)
	if c == 0:
		print(0)
		continue
	temp = 0
	ind = 0
	for i in range(n):
		if s[i] == '*':
			temp += 1
		if temp == c:
			ind = i
			break
	stack = []
	ans = 0
	temp = 0
	for i in range(ind, -1, -1):
		if s[i] == '*':
			if not stack:
				stack.append(i)
			else:
				ans += abs(i - stack[-1]) - 1
				stack.append(stack[-1] - 1)
	tempans = ans
	ans = 0
	stack = []
	for i in range(ind, n, 1):
		if s[i] == '*':
			if not stack:
				stack.append(i)
			else:
				ans += i - stack[-1] - 1
				stack.append(stack[-1] + 1)
	print(tempans + ans)


def solve():
	cases = int(input())
	for t in range(cases):
		input()
		sequence = input().strip('.')
		gap = 0
		gaps = []
		for s in sequence[1:]:
			if s == '*':
				gaps.append(gap)
				gap = 0
			else:
				gap += 1
		sum = 0
		length = len(gaps)
		for i in range(length // 2):
			sum += (i + 1) * (gaps[i] + gaps[-1 - i])
		if length % 2 == 1:
			sum += (length + 1) * gaps[length // 2] // 2
		print(sum)
solve()


for _ in range(int(input())):
	n = int(input())
	s = input().strip('.')
	n = len(s)
	ans = 0
	cnt = s.count('*')
	if 0 < cnt < n:
		stars_passed = 0
		for ch in s:
			if ch == '*':
				stars_passed += 1
			else:
				ans += min(stars_passed, cnt - stars_passed)
	print(ans)


def test_case():
	n = int(input())
	s = input()
	if '*' not in s:
		return 0
	(l, r) = (s.find('*'), s.rfind('*'))
	(l_cur, r_cur) = (1, 1)
	ans = 0
	while r > l:
		if l_cur < r_cur:
			l += 1
			if l >= r:
				break
			if s[l] == '*':
				l_cur += 1
			else:
				ans += l_cur
		else:
			r -= 1
			if l >= r:
				break
			if s[r] == '*':
				r_cur += 1
			else:
				ans += r_cur
	return ans
t = int(input())
for i in range(t):
	print(test_case())


def func():
	n = int(input())
	s = input()
	sheep_arr = []
	step = 0
	for i in range(n):
		if s[i] == '*':
			sheep_arr.append(i)
	if len(sheep_arr) == 0:
		print(0)
	else:
		sheep_count = len(sheep_arr)
		middle = sheep_count // 2
		left = sheep_arr[:middle]
		right = sheep_arr[middle + 1:]
		middle_pos = sheep_arr[middle]
		leff_plan = [i for i in range(middle_pos - len(left), middle_pos)]
		right_plan = [i for i in range(middle_pos + 1, middle_pos + len(right) + 1)]
		l = zip(left, leff_plan)
		r = zip(right, right_plan)
		for (a, b) in l:
			step += b - a
		for (a, b) in r:
			step += a - b
		print(step)
t = int(input())
for i in range(t):
	func()


from collections import defaultdict
import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	b = []
	ind = [0]
	for j in s:
		b.append(j)
	l = b.count('*')
	if l == 0:
		print(0)
	else:
		pre = [0]
		suff = [0]
		cs = 0
		cd = 0
		j = 0
		while j < n:
			if b[j] == '*':
				pre.append(pre[-1] + cs * cd)
				cs += 1
				cd = 0
			else:
				cd += 1
			j += 1
		cs = 0
		cd = 0
		j = n - 1
		while j >= 0:
			if b[j] == '*':
				suff.append(suff[-1] + cs * cd)
				cs += 1
				cd = 0
			else:
				cd += 1
			j += -1
		suff.reverse()
		ans = float('inf')
		for i in range(1, l + 1):
			ans = min(ans, pre[i] + suff[i - 1])
		print(ans)


num = int(input())
for n in range(num):
	ln = int(input())
	strn = input()
	sheep = 0
	lft = 0
	cnt = 0
	for i in strn:
		if i == '*':
			sheep += 1
	for i in strn:
		if i == '*':
			lft += 1
		else:
			cnt += min(lft, sheep - lft)
	print(cnt)


def solve():
	n = int(input())
	s = input()
	cnt = s.count('*')
	pos = -1
	cur = -1
	for i in range(n):
		if s[i] == '*':
			cur += 1
			if cur == cnt // 2:
				pos = i * 1
	ans = 0
	cur = pos - cnt // 2
	for i in range(n):
		if s[i] == '*':
			ans += abs(cur - i)
			cur += 1
	print(ans)

def main():
	testCases = int(input())
	for i in range(testCases):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	ll = []
	lr = []
	kp = 0
	for i in range(n):
		if s[i] == '*':
			kp += 1
		ll.append(kp)
	kp = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '*':
			kp += 1
		lr.append(kp)
	lr = lr[::-1]
	ans = 0
	for i in range(n):
		if s[i] == '.':
			if ll[i] > lr[i]:
				ans += lr[i]
			else:
				ans += ll[i]
	print(ans)


import sys
input = sys.stdin.readline

def calc(x):
	ANS = 0
	for i in range(len(B)):
		ANS += abs(B[i] - (x + i))
	return ANS
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(input().strip())
	B = []
	for i in range(n):
		if A[i] == '*':
			B.append(i)
	left = 0
	right = n - len(B)
	while right - left > 3:
		mid = left + (right - left) // 3
		mid2 = left + (right - left) * 2 // 3
		c = calc(mid)
		c2 = calc(mid2)
		if c == c2:
			left = mid
			right = mid2
		elif c > c2:
			left = mid
		else:
			right = mid2
	ANS = 1 << 60
	for i in range(left, right + 1):
		ANS = min(ANS, calc(i))
	print(ANS)


for _ in range(int(input())):
	n = int(input())
	st = input()
	dist = []
	for i in range(n):
		if st[i] == '*':
			dist.append(i)
	if dist:
		med = len(dist) // 2
		ans = 0
		med_dist = dist[med]
		for i in dist[med + 1:]:
			ans += i - med_dist - 1
			med_dist += 1
		med_dist = dist[med]
		for i in dist[:med][::-1]:
			ans += med_dist - i - 1
			med_dist -= 1
		print(ans)
	else:
		print(0)


import math
test = int(input())
for t in range(test):
	n = int(input())
	s = input()
	x = []
	for i in range(n):
		if s[i] == '*':
			x.append(i + 1)
	a = len(x) // 2
	y = [x[a] - a + i for i in range(len(x))]
	p = 0
	for i in range(len(x)):
		p += abs(x[i] - y[i])
	print(p)


for _ in range(int(input())):
	n = int(input())
	m = input()
	c = 0
	for i in range(n):
		if m[i] == '*':
			c += 1
	c = c // 2 + c % 2
	ind = 0
	for i in range(n):
		if m[i] == '*':
			ind += 1
		if ind == c:
			ind = i
			break
	indl = ind
	indr = ind
	il = indl
	ir = indr
	summ = 0
	while il > 0:
		il -= 1
		if m[il] == '*':
			indl -= 1
			summ += indl - il
	while ir < len(m) - 1:
		ir += 1
		if m[ir] == '*':
			indr += 1
			summ += ir - indr
	print(summ)


def process():
	N = int(input().strip())
	inp_arr = input().strip()
	first = -1
	last = -1
	count = 0
	left_side_sheep_count = 0
	answer = 0
	for i in range(N):
		if inp_arr[i] == '*':
			count += 1
			last = i
			if first == -1:
				first = i
	if count == 0 or count == N or count == 1:
		print(str(0))
		return
	for i in range(first, last + 1):
		if inp_arr[i] == '*':
			left_side_sheep_count += 1
		else:
			answer = answer + min(left_side_sheep_count, count - left_side_sheep_count)
	print(str(answer))
	return

def main():
	T = int(input().strip())
	for i in range(T):
		process()
main()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = input().strip()
	b = []
	for i in range(n):
		if a[i] == '*':
			b.append(i)
	if len(b) == 0:
		print(0)
		return
	c = b[len(b) // 2]
	m = len(b) // 2
	r = 0
	for i in range(1, m + 1):
		r += c - i - b[m - i]
	for i in range(1, len(b) - m):
		r += b[m + i] - c - i
	print(r)
for i in range(int(input())):
	solve()


def solve(s):
	sheep_num = s.count('*')
	if sheep_num == 0:
		return 0
	l = []
	for i in range(len(s)):
		if s[i] == '*':
			l.append(i)
	middle = len(l) // 2
	middle_value = l[middle]
	step = 0
	pos = middle_value
	for i in range(0, middle):
		pos -= 1
		step += pos - l[i]
	pos = middle_value
	for i in range(middle + 1, len(l)):
		pos += 1
		step += l[i] - pos
	return step
for _ in range(int(input())):
	n = input()
	s = input()
	print(solve(s))


from sys import stdin, stdout

def arrin():
	return list(map(int, stdin.readline().split()))

def num1in():
	return int(stdin.readline())

def num2in():
	(a, b) = map(int, stdin.readline().split())
	return (a, b)

def num3in():
	(a, b, c) = map(int, stdin.readline().split())
	return (a, b, c)

def num4in():
	(a, b, c, d) = map(int, stdin.readline().split())
	return (a, b, c, d)

def num5in():
	(a, b, c, d, e) = map(int, stdin.readline().split())
	return (a, b, c, d, e)

def getMinJumps(s):
	ones = []
	(jumps, median, ind) = (0, 0, 0)
	for i in range(len(s)):
		if s[i] == '*':
			ones.append(i)
	if len(ones) == 0:
		return jumps
	median = ones[len(ones) // 2]
	ind = median
	for i in range(ind, -1, -1):
		if s[i] == '*':
			jumps += ind - i
			ind -= 1
	ind = median
	for i in range(ind, len(s)):
		if s[i] == '*':
			jumps += i - ind
			ind += 1
	return jumps
t = num1in()
for test in range(t):
	n = num1in()
	s = stdin.readline()
	print(getMinJumps(s))


T = int(input())
for _ in range(T):
	n = int(input())
	a = [i for i in input()]
	sheeps = []
	for i in range(n):
		if a[i] == '*':
			sheeps.append(i)
	mid = len(sheeps) // 2
	out = 0
	for i in range(len(sheeps)):
		a = abs(sheeps[mid] - sheeps[i])
		a -= abs(mid - i)
		out += a
	print(out)


import statistics
for _ in range(int(input())):
	n = int(input())
	a = input()
	ones = []
	for i in range(len(a)):
		if a[i] == '*':
			ones.append(i)
	if len(ones) == 0:
		print(0)
	else:
		median = int(statistics.median(ones))
		n = len(ones)
		if n % 2 == 0:
			ans = list(range(median - n // 2 + 1, median + n // 2 + 1))
		else:
			ans = list(range(median - n // 2, median + n // 2 + 1))
		swaps = 0
		for i in range(len(ones)):
			swaps += abs(ans[i] - ones[i])
		print(swaps)


from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd

def read():
	return list(map(int, input().strip().split()))
ans_ = []

def f(s):
	last = -1
	dp = [0] * len(s)
	count = 0
	for i in range(len(s)):
		dp[i] += dp[last]
		if last != -1:
			dp[i] += count * (i - last - [0, 1][s[i] == '*'])
		if s[i] == '*':
			last = i
			count += 1
	return dp
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	a = f(s)
	b = f(s[::-1])[::-1]
	ca = s.count('*')
	ans = float('inf')
	c = 0
	for i in range(n):
		if s[i] == '*':
			c += 1
			ans = min(ans, a[i] + b[i])
		else:
			ans = min(ans, a[i] + b[i] - max(c, ca - c))
	if c != 0:
		ans_.append(ans)
	else:
		ans_.append(0)
for i in ans_:
	print(i)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
from bisect import bisect_left, bisect_left
from time import perf_counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def intin():
	return int(input())

def solve():
	n = intin()
	s = input()
	forward_jumps = [0] * n
	backward_jumps = [0] * n
	sheeps = 0
	cost = 0
	for i in range(n):
		if s[i] == '*':
			sheeps += 1
		else:
			cost += sheeps
		forward_jumps[i] = cost
	sheeps = 0
	cost = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '*':
			sheeps += 1
		else:
			cost += sheeps
		backward_jumps[i] = cost
	print(min((i + j for (i, j) in zip(forward_jumps, backward_jumps))))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


def solve(x, n):
	itemno = 0
	y = []
	for i in range(n):
		if x[i] == '*':
			y.append(i - itemno)
			itemno += 1
	if y == []:
		return 0
	y.sort()
	m = len(y)
	med = y[m // 2]
	ans = 0
	for i in range(m):
		ans += abs(y[i] - med)
	return ans
for q in range(int(input())):
	n = int(input())
	x = input()
	print(solve(x, n))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, s, ans) = (int(input()), input().strip(), 0)
	sheep = [i for i in range(n) if s[i] == '*']
	try:
		middle = sheep[len(sheep) // 2]
		(left, right) = (middle - 1, middle + 1)
		for i in sheep:
			if i < middle:
				ans += left - i
				left -= 1
			elif i > middle:
				ans += i - right
				right += 1
		print(ans)
	except:
		print(0)


import sys
from math import gcd, ceil, sqrt
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7
from collections import Counter, defaultdict as df
from functools import reduce

def counter(l):
	return dict(Counter(l))

def printm(l):
	for i in range(len(l[0])):
		print(*l[i])

def P(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def so(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def rev(l):
	return list(reversed(l))

def ini():
	return int(sys.stdin.readline())

def inp():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()

def inputm(n, m):
	return [li() for i in range(m)]

def aa(n):
	return n * (n + 1) // 2
for i in range(ini()):
	n = int(input())
	s = input()
	l = []
	for i in range(n):
		if s[i] == '*':
			l.append(i + 1)
	t = len(l) // 2
	tt = [l[i] for i in range(len(l))]
	k = 1
	for i in range(t - 1, -1, -1):
		tt[i] = l[t] - k
		k = k + 1
	k = 1
	for i in range(t + 1, len(l)):
		tt[i] = l[t] + k
		k = k + 1
	count = 0
	for i in range(len(l)):
		count += abs(l[i] - tt[i])
	print(count)


import sys
t = int(input())
for _ in range(t):
	N = int(input())
	S = sys.stdin.readline().strip()
	arr = []
	l_sum = r_sum = 0
	l_count = r_count = 0
	for i in range(N):
		if S[i] == '*':
			arr.append(i + 1)
			r_sum += i + 1
			r_count += 1
	if r_count > 0:
		r_count -= 1
	if r_sum > 0:
		r_sum -= arr[0]
	cost_arr = []
	for i in range(len(arr)):
		cost = r_sum - r_count * arr[i] - r_count * (r_count + 1) // 2
		cost += l_count * arr[i] - l_sum - l_count * (l_count + 1) // 2
		cost_arr.append(cost)
		l_count += 1
		r_count -= 1
		if r_sum > 0:
			r_sum -= arr[i + 1]
		l_sum += arr[i]
	print(min(cost_arr) if len(cost_arr) > 0 else 0)
	sys.stdout.flush()


t = int(input())
for h in range(t):
	ha = input()
	s = input()
	lis = list(s)
	l = len(s)
	lis1 = []
	co = s.count('*')
	for i in range(l):
		if lis[i] == '*':
			lis1.append(i + 1)
	for i in range(co):
		lis1[i] = lis1[i] - i
	ans = 0
	if co % 2 != 0:
		if co == 1:
			print(0)
		else:
			cos = co + 1
			cos = cos / 2
			cos = lis1[int(cos) - 1]
			for i in range(co):
				ans += abs(lis1[i] - cos)
			print(ans)
	elif co == 0:
		print(0)
	else:
		cos1 = co / 2
		cos1 = lis1[int(cos1) - 1]
		for i in range(co):
			ans += abs(lis1[i] - cos1)
		cos2 = co / 2 + 1
		cos2 = lis1[int(cos2) - 1]
		ans1 = 0
		for i in range(co):
			ans1 += abs(lis1[i] - cos2)
		print(max(ans, ans1))