Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

There are n villages in a line in an area. There are two kinds of tribes A and B that reside there. A village can be either empty or occupied by one of the tribes. An empty village is said to be controlled by a tribe of village A if it is surrounded by villages of tribes A from the left and from the right. Same goes for the tribe B.

Find out the number of villages that are either occupied by or controlled by tribes A and B, respectively.

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases.
The first line of the input contains a string s denoting the configuration of the villages, each character of which can be 'A', 'B' or '.'.

------ Output ------ 

For each test case, output two space-separated integers denoting the number of villages either occupied by or controlled by tribe A and B, respectively.

------ Constraints ------ 

$1 ≤ T ≤ 20$
$1 ≤ |s| ≤ 10^{5}$

------ Subtasks ------ 

$Subtask #1 (40 points): 1 ≤ |s| ≤ 10^{3}$
$Subtask #2 (60 points): Original constraints$

----- Sample Input 1 ------ 
4
A..A..B...B
..A..
A....A
..B..B..B..
----- Sample Output 1 ------ 
4 5
1 0
6 0
0 7

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	s = input()
	(a, b, c) = (0, 0, 0)
	l = ''
	for i in s:
		if i == '.':
			c += 1
		else:
			if i != l:
				c = 1
			if i == 'A':
				a += c
			else:
				b += c
			l = i
			c = 1
	print(a, b)


t = int(input())
for ni in range(t):
	s = input()
	(ca, cb, cib) = (0, 0, 0)
	n = len(s)
	(prevpos, prevAB) = (s[0], '')
	for i in range(n):
		if s[i] == '.':
			cib = cib + 1
		if s[i] == 'A':
			if prevAB == 'A':
				ca = ca + cib
			ca = ca + 1
			cib = 0
			prevAB = 'A'
		elif s[i] == 'B':
			if prevAB == 'B':
				cb = cb + cib
			cb = cb + 1
			cib = 0
			prevAB = 'B'
		prevpos = s[i]
	print(ca, cb)


for _ in range(int(input())):
	s = input().strip('.')
	village = {'A': 0, 'B': 0}
	(current_tribe, current_tribe_index) = ('', None)
	for (i, x) in enumerate(s):
		if x != '.':
			village[x] += 1
			if x == current_tribe:
				village[x] += i - current_tribe_index - 1
			current_tribe = x
			current_tribe_index = i
	print(village['A'], village['B'])


for _ in range(int(input())):
	str1 = input()
	dict1 = {'A': 0, 'B': 0}
	lasttribe = None
	lastindex = None
	for (i, x) in enumerate(str1):
		if x == lasttribe:
			dict1[x] += i - lastindex - 1
		if x != '.':
			dict1[x] += 1
			lasttribe = x
			lastindex = i
	print(dict1['A'], dict1['B'])


for tc in range(int(input())):
	s = input()
	prev = ''
	cur = ''
	(acnt, bcnt, dotcnt) = (0, 0, 0)
	for i in s:
		if i == 'A' or i == 'B':
			if i == '.':
				dotcnt += 1
			elif i == 'A':
				acnt += 1
				if prev == 'A':
					acnt += dotcnt
					dotcnt = 0
				elif prev == 'B':
					dotcnt = 0
					prev = 'B' or prev == ''
				else:
					dotcnt = 0
				prev = 'A'
			elif i == 'B':
				bcnt += 1
				if prev == 'B':
					bcnt += dotcnt
					dotcnt = 0
					prev = 'B'
				elif prev == 'A' or prev == '':
					dotcnt = 0
					prev = 'A'
				else:
					dotcnt = 0
				prev = 'B'
		else:
			dotcnt += 1
	print(acnt, bcnt)


for _ in range(int(input())):
	s = input().strip()
	(A, B, dotsA, dotsB) = (0, 0, -1, -1)
	for c in s:
		if c == 'A':
			A += 1 + dotsA * (dotsA > -1)
			(dotsA, dotsB) = (0, -1)
		elif c == 'B':
			B += 1 + dotsB * (dotsB > -1)
			(dotsA, dotsB) = (-1, 0)
		elif c == '.' and dotsA >= 0:
			dotsA += 1
		elif c == '.' and dotsB >= 0:
			dotsB += 1
	print(A, B)


T = int(input())
for i in range(0, T):
	s = str(input().strip('.'))
	a = 0
	b = 0
	d = 0
	l = ''
	for w in s:
		if w == '.':
			d += 1
		else:
			if w != l:
				d = 1
			if w == 'A':
				a += d
			else:
				b += d
			l = w
			d = 1
	print(a, b)


t = int(input())
while t != 0:
	s = input()
	a = b = c = 0
	v = ''
	for vll in s:
		if vll == 'A':
			a += 1
			if c != 0 and v == 'A':
				a += c
			c = 0
			v = 'A'
		elif vll == 'B':
			b += 1
			if c != 0 and v == 'B':
				b += c
			c = 0
			v = 'B'
		else:
			c += 1
	print(a, b)
	t -= 1


for _ in range(int(input())):
	s = input().strip('.')
	na = 0
	nb = 0
	dots = 0
	last = '?'
	for c in s:
		if c == '.':
			dots += 1
		else:
			if c != last:
				dots = 1
			if c == 'A':
				na += dots
			else:
				nb += dots
			last = c
			dots = 1
	print(na, nb)


for t in range(int(input())):
	(a, b, c, x) = (0, 0, '', 0)
	s = input()
	for i in range(len(s)):
		if s[i] == 'A':
			a += 1
			if c == 'A':
				a += x
			else:
				c = 'A'
			x = 0
		if s[i] == 'B':
			b += 1
			if c == 'B':
				b += x
			else:
				c = 'B'
			x = 0
		if s[i] == '.':
			x += 1
	print(a, b)


for i in range(int(input())):
	s = input()
	(l1, l2, l3, l4) = ([], [], [], [])
	(count1, count2) = (0, 0)
	for j in range(len(s)):
		if s[j] == 'A':
			l1.append(j)
		elif s[j] == 'B':
			l2.append(j)
	for j in range(len(l1) - 1):
		l3 = s[l1[j]:l1[j + 1] + 1]
		if 'B' not in l3:
			count1 += l1[j + 1] - l1[j] - 1
	for j in range(len(l2) - 1):
		l4 = s[l2[j]:l2[j + 1] + 1]
		if 'A' not in l4:
			count2 += l2[j + 1] - l2[j] - 1
	print(count1 + s.count('A'), end=' ')
	print(count2 + s.count('B'))


for _ in range(int(input())):
	(a, b, x) = (0, 0, 0)
	temp = ' '
	s = str(input())
	for i in s:
		if i == 'A':
			a = a + 1
			if temp == 'A':
				a = a + x
			else:
				temp = 'A'
			x = 0
		elif i == 'B':
			b = b + 1
			if temp == 'B':
				b = b + x
			else:
				temp = 'B'
			x = 0
		else:
			x = x + 1
	print(a, b)


for _ in range(int(input())):
	s = input()
	(fa, fb, ca, cb) = (None, None, 0, 0)
	for i in range(len(s)):
		if s[i] == 'A':
			if fa is not None:
				ca += i - fa
			else:
				ca += 1
			fa = i
			fb = None
		if s[i] == 'B':
			if fb is not None:
				cb += i - fb
			else:
				cb += 1
			fb = i
			fa = None
	print(ca, cb)


t = input()
for c in range(0, int(t)):
	s = input()
	a = 0
	b = 0
	u = 0
	prev = ''
	for x in range(0, len(s)):
		if s[x] == 'A':
			a = a + 1
		if s[x] == 'B':
			b = b + 1
		if s[x] == '.':
			u = u + 1
		if u > 0 and s[x] == prev and (s[x] != '.'):
			if prev == 'A':
				a = a + u
			else:
				b = b + u
			u = 0
		elif u > 0 and s[x] != prev and (s[x] != '.'):
			u = 0
		if s[x] != '.':
			prev = s[x]
	print(a, b)


tests = int(input())
for i in range(tests):
	string = input()
	A_start = False
	B_start = False
	temp = 0
	ans_a = 0
	ans_b = 0
	for x in string:
		if x == 'A':
			if not A_start:
				A_start = True
				B_start = False
				temp = 0
				ans_a += 1
			else:
				ans_a += temp + 1
				temp = 0
		if x == 'B':
			if not B_start:
				A_start = False
				B_start = True
				temp = 0
				ans_b += 1
			else:
				ans_b += temp + 1
				temp = 0
		if x == '.':
			temp += 1
	print(ans_a, ans_b)


import sys

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

def main():
	for _ in range(int(_input())):
		s = str(_input())
		a = 0
		b = 0
		temp = 0
		ctr = 0
		for i in range(len(s)):
			if temp > 0 and s[i] == '.':
				ctr += 1
			if s[i] == 'A':
				a += 1
				if temp == 1:
					a += ctr
					ctr = 0
				elif temp == 2:
					ctr = 0
				temp = 1
			if s[i] == 'B':
				b += 1
				if temp == 2:
					b += ctr
					ctr = 0
				elif temp == 1:
					ctr = 0
				temp = 2
		print(a, b)
main()


for _ in range(int(input())):
	s = input()
	(l, a, b, c) = ([], 0, 0, 0)
	for i in s:
		if i == 'A':
			l.append(i)
			a += 1
			if len(l) > 1 and l[len(l) - 2] == i:
				a += c
			c = 0
		elif i == 'B':
			if i == 'B':
				l.append(i)
				b += 1
				if len(l) > 1 and l[len(l) - 2] == i:
					b += c
			c = 0
		else:
			c += 1
	print(a, b)


for _ in range(int(input())):
	l = input()
	n = len(l)
	k = l[::-1]
	(p, q) = (0, 0)
	for i in range(n):
		if l[i] != '.':
			p = i
			break
	for j in range(n):
		if k[j] != '.':
			q = j
			break
	m = l[p:n - q]
	(a, b, v) = (0, 0, 0)
	for z in range(len(m)):
		if m[z] == 'A':
			a += 1
		elif m[z] == 'B':
			b += 1
	for g in range(1, len(m)):
		if m[g] == m[v]:
			if m[g] == 'A':
				a = a + (g - v - 1)
			else:
				b = b + g - v - 1
			v = g
		elif m[g] != '.':
			v = g
	print(a, b)


def solve(array):
	flaga = 0
	a = 0
	b = 0
	x = 0
	while x < len(array):
		if array[x] == 'A':
			flaga = x
			x += 1
			while x < len(array):
				if array[x] == 'A':
					a += x - flaga - 1
					break
				elif array[x] == 'B':
					break
				else:
					x += 1
		elif array[x] == 'B':
			flaga = x
			x += 1
			while x < len(array):
				if array[x] == 'B':
					b += x - flaga - 1
					break
				elif array[x] == 'A':
					break
				else:
					x += 1
		else:
			x += 1
	print(f"{a + array.count('A')} {b + array.count('B')}")
for _ in range(int(input(''))):
	str_list = [x for x in input('')]
	solve(str_list)


for _ in range(int(input())):
	s = list(input())
	n = len(s)
	(a, b) = (s.count('A'), s.count('B'))
	i = 0
	t = []
	for i in range(n):
		if s[i] != '.':
			t.append([i, s[i]])
	for i in range(1, len(t)):
		if t[i][1] == t[i - 1][1] and t[i][0] - t[i - 1][0] > 1:
			if t[i][1] == 'A':
				a += t[i][0] - t[i - 1][0] - 1
			else:
				b += t[i][0] - t[i - 1][0] - 1
	print(a, b)


t = int(input())
for i in range(t):
	lst = list(input())
	a = lst.count('A')
	b = lst.count('B')
	if lst.count('.') == 0:
		print(a, b)
	else:
		k = 0
		while k < len(lst) - 1:
			if lst[k] == '.':
				j = k
				while j < len(lst) - 1 and lst[j] == '.':
					j = j + 1
				if k > 0 and lst[k - 1] == 'A' and (lst[j] == 'A'):
					a = a + (j - k)
				if k > 0 and lst[k - 1] == 'B' and (lst[j] == 'B'):
					b = b + (j - k)
				k = j
			else:
				k = k + 1
		print(a, b)


for _ in range(int(input())):
	s = input()
	(a, b, c) = (0, 0, 0)
	ch = 0
	for i in s:
		if i == 'A':
			a += 1
			if c > 0 and ch == i:
				a += c
			c = 0
			ch = i
		elif i == 'B':
			b += 1
			if c > 0 and ch == i:
				b += c
			c = 0
			ch = i
		else:
			c += 1
	print(a, b)


testcase = int(input())
for i in range(testcase):
	gstri = input()
	A = 0
	B = 0
	countdots = 0
	strnow = ''
	for stri in gstri:
		if stri == 'A' and strnow == 'B':
			B -= countdots
		if stri == 'B' and strnow == 'A':
			A -= countdots
		if stri == '.' and strnow == 'A':
			A += 1
			countdots += 1
		if stri == '.' and strnow == 'B':
			B += 1
			countdots += 1
		if stri == 'A':
			strnow = 'A'
			A += 1
			countdots = 0
		if stri == 'B':
			strnow = 'B'
			B += 1
			countdots = 0
	if gstri[-1] == '.' and strnow == 'A':
		A -= countdots
	if gstri[-1] == '.' and strnow == 'B':
		B -= countdots
	print(A, B)


test = int(input())
while test > 0:
	data = [i for i in input()]
	(a, b) = (0, 0)
	prev = -1
	t = -1
	for i in range(len(data)):
		if data[i] == 'A' and t == 1:
			a += i - prev - 1
		elif data[i] == 'B' and t == 2:
			b += i - prev - 1
		if data[i] == 'A':
			prev = i
			a += 1
			t = 1
		elif data[i] == 'B':
			prev = i
			b += 1
			t = 2
	print(a, b)
	test -= 1


T = int(input())
for tj in range(T):
	s = input()
	N = len(s)
	count_A = 0
	count_B = 0
	last_letter = ''
	i = 0
	while i <= N - 1:
		if s[i] == 'A':
			count_A += 1
			last_letter = 'A'
			i += 1
		elif s[i] == 'B':
			count_B += 1
			last_letter = 'B'
			i += 1
		else:
			k = i
			count_dots = 0
			while k <= N - 1 and s[k] != 'A' and (s[k] != 'B'):
				k += 1
				count_dots += 1
			i = k
			if k <= N - 1:
				if last_letter == s[k] and s[k] == 'A':
					count_A += count_dots
				elif last_letter == s[k] and s[k] == 'B':
					count_B += count_dots
	print(count_A, count_B)


for t in range(int(input())):
	s = input()
	A = 0
	B = 0
	n = len(s)
	i = 0
	while i < n:
		if s[i] == 'A':
			A += 1
			i += 1
		elif s[i] == 'B':
			B += 1
			i += 1
		else:
			j = i
			while j < n:
				if s[j] != '.':
					break
				j += 1
			if i != 0 and j != n:
				if s[i - 1] == 'A' and s[j] == 'A':
					A += j - i
				elif s[i - 1] == 'B' and s[j] == 'B':
					B += j - i
			i = j
	print(A, B)


for item in range(int(input())):
	st = input()
	v = st[0]
	d = {'A': 0, 'B': 0}
	d['A'] = st.count('A')
	d['B'] = st.count('B')
	c = 0
	for i in range(1, len(st)):
		if st[i] == '.':
			c += 1
		elif st[i] == v:
			d[v] += c
			c = 0
		else:
			v = st[i]
			c = 0
	print(d['A'], d['B'])


for i in range(int(input())):
	s = input()
	a = s.count('A')
	b = s.count('B')
	l = []
	l1 = []
	for i in range(len(s)):
		if s[i] == 'A' or s[i] == 'B':
			l.append(s[i])
			l1.append(i)
	for i in range(len(l) - 1):
		if l[i] == l[i + 1]:
			if l[i] == 'A':
				a = a + l1[i + 1] - l1[i] - 1
			else:
				b = b + l1[i + 1] - l1[i] - 1
	print(a, b)


t = int(input())
for i in range(t):
	s = input()
	ctra = s.count('A')
	ctrb = s.count('B')
	z = []
	ind = []
	for j in range(len(s)):
		if s[j] == 'A' or s[j] == 'B':
			z.append(s[j])
			ind.append(j)
	for j in range(len(z) - 1):
		if z[j] == z[j + 1]:
			if z[j] == 'A':
				ctra = ctra + ind[j + 1] - ind[j] - 1
			else:
				ctrb = ctrb + ind[j + 1] - ind[j] - 1
	print(ctra, ctrb)


from math import *
import sys

def input():
	return sys.stdin.readline().replace('\n', '').strip()
sys.setrecursionlimit(10 ** 9)
for _ in range(int(input())):
	l = list(input())
	n = len(l)
	(a, b) = (0, 0)
	cur_a = -1
	cur_b = -1
	cur_block = 0
	for i in range(n):
		if l[i] == 'A':
			a += 1
			if cur_a == 1:
				a += cur_block
			cur_block = 0
			cur_a = 1
			cur_b = -1
		elif l[i] == 'B':
			b += 1
			if cur_b == 1:
				b += cur_block
			cur_block = 0
			cur_a = -1
			cur_b = 1
		elif cur_a == 1 or cur_b == 1:
			cur_block += 1
	print(a, b)


n = int(input().strip())
for i in range(n):
	area = list(input().rstrip().strip('0').strip('.'))
	A = 0
	B = 0
	A_index = []
	B_index = []
	A_subset = []
	B_subset = []
	current_letter = ''
	for i in range(len(area)):
		if area[i] == 'A':
			A_index.append(i)
		if area[i] == 'B':
			B_index.append(i)
	for i in range(0, len(A_index) - 1):
		flag = 0
		for j in range(A_index[i], A_index[i + 1] + 1):
			if area[j] == 'B':
				flag = 1
		if flag == 0:
			A_subset.append([A_index[i], A_index[i + 1]])
	for i in range(0, len(B_index) - 1):
		flag = 0
		for j in range(B_index[i], B_index[i + 1] + 1):
			if area[j] == 'A':
				flag = 1
		if flag == 0:
			B_subset.append([B_index[i], B_index[i + 1]])
	for (a, b) in A_subset:
		for i in range(a, b + 1):
			area[i] = 'A'
	for (a, b) in B_subset:
		for i in range(a, b + 1):
			area[i] = 'B'
	print(area.count('A'), area.count('B'))


for _ in range(int(input())):
	s = input()
	xd = {}
	xd['A'] = s.count('A')
	xd['B'] = s.count('B')
	if xd['A'] >= 2 or xd['B'] >= 2:
		for i in range(len(s)):
			if s[i] == 'A' or s[i] == 'B':
				break
		char = s[i]
		temp = 0
		for j in range(i + 1, len(s)):
			if s[j] == '.':
				temp += 1
			elif s[j] == char:
				xd[char] += temp
				temp = 0
			else:
				temp = 0
				char = s[j]
	print(xd['A'], xd['B'])


t = int(input())
for i in range(t):
	s = input()
	d = {'A': 0, 'B': 0}
	d['A'] = s.count('A')
	d['B'] = s.count('B')
	c = s[0]
	a = 0
	for j in range(len(s)):
		if s[j] == '.':
			a += 1
		elif s[j] == c:
			d[c] += a
			a = 0
		else:
			c = s[j]
			a = 0
	print(d['A'], d['B'])


for tc in range(int(input())):
	s = input()
	d = {'A': 0, 'B': 0}
	d['A'] = s.count('A')
	d['B'] = s.count('B')
	c = s[0]
	vb = 0
	for i in range(1, len(s)):
		if s[i] == '.':
			vb += 1
		elif s[i] == c:
			d[c] += vb
			vb = 0
		else:
			c = s[i]
			vb = 0
	print(d['A'], d['B'])


for tc in range(int(input())):
	s = input()
	l = []
	A = 0
	B = 0
	for (i, c) in enumerate(s):
		if c.isalpha():
			l.append(i)
	for j in range(len(l) - 1):
		if s[l[j]] == s[l[j + 1]]:
			if s[l[j]] == 'A':
				A += l[j + 1] - l[j] - 1
			else:
				B += l[j + 1] - l[j] - 1
	A += s.count('A')
	B += s.count('B')
	print(A, B)


for test in range(int(input())):
	village = input()
	dot = village.count('.')
	check = village[0]
	counter = {'A': 0, 'B': 0}
	counter['A'] = village.count('A')
	counter['B'] = village.count('B')
	count = 0
	for i in village[1:]:
		if i == '.':
			count += 1
		elif i == check:
			counter[i] += count
			count = 0
		else:
			check = i
			count = 0
	print(counter['A'], counter['B'])


try:
	n = int(input().strip())
	for p in range(n):
		s = input().strip()
		c1 = 0
		l = []
		for i in range(len(s)):
			if s[i] != '.':
				l.append([s[i], i + 1])
		i = 0
		b = 0
		b_count = 0
		a = 0
		a_count = 0
		while i < len(l) - 1:
			if l[i][0] == l[i + 1][0] and l[i][0] == 'A':
				a_count = a_count + l[i + 1][1] - l[i][1] - 1
			elif l[i][0] == l[i + 1][0] and l[i][0] == 'B':
				b_count = b_count + l[i + 1][1] - l[i][1] - 1
			i += 1
		for i in range(len(l)):
			if l[i][0] == 'A':
				a_count += 1
			else:
				b_count += 1
		print(a_count, b_count)
except:
	pass


try:
	t = int(input())
	while t:
		st = input()
		v = st[0]
		d = {'A': 0, 'B': 0}
		d['A'] = st.count('A')
		d['B'] = st.count('B')
		c = 0
		for i in range(1, len(st)):
			if st[i] == '.':
				c += 1
			elif st[i] == v:
				d[v] += c
				c = 0
			else:
				v = st[i]
				c = 0
		print(d['A'], d['B'])
		t -= 1
except EOFError:
	pass


for _ in range(int(input())):
	s = input()
	m = s[0]
	d = {'A': 0, 'B': 0}
	d['A'] = s.count('A')
	d['B'] = s.count('B')
	count = 0
	for i in range(1, len(s)):
		if s[i] == '.':
			count += 1
		elif s[i] == m:
			d[m] += count
			count = 0
		else:
			m = s[i]
			count = 0
	print(d['A'], d['B'])


T = int(input())
for i in range(T):
	n = input()
	dot = n.count('.')
	m = n[0]
	k = {'A': 0, 'B': 0}
	k['A'] = n.count('A')
	k['B'] = n.count('B')
	count = 0
	for i in n[1:]:
		if i == '.':
			count += 1
		elif i == m:
			k[i] += count
			count = 0
		else:
			m = i
			count = 0
	print(k['A'], k['B'])


n = int(input())
for _ in range(n):
	x = input()
	last = ['', 0]
	A = 0
	B = 0
	for i in range(len(x)):
		if x[i] == 'A':
			if last[0] == 'A':
				A += i - last[1]
				last[0] = 'A'
				last[1] = i
			else:
				A += 1
				last[0] = 'A'
				last[1] = i
		if x[i] == 'B':
			if last[0] == 'B':
				B += i - last[1]
				last[0] = 'B'
				last[1] = i
			else:
				B += 1
				last[0] = 'B'
				last[1] = i
	print(A, B)


t = int(input())
while t != 0:
	ac = bc = pc = i = 0
	str = input()
	n = len(str)
	while i < n:
		if str[i] == 'A':
			ac += 1
			i += 1
			while i < n:
				if str[i] == 'A':
					ac += pc + 1
					pc = 0
					i += 1
				elif str[i] == '.':
					pc += 1
					i += 1
				else:
					pc = 0
					i -= 1
					break
		elif str[i] == 'B':
			bc += 1
			i += 1
			while i < n:
				if str[i] == 'B':
					bc += pc + 1
					pc = 0
					i += 1
				elif str[i] == '.':
					pc += 1
					i += 1
				else:
					pc = 0
					i -= 1
					break
		i += 1
	print('{} {}'.format(ac, bc))
	t -= 1


for _ in range(int(input())):
	s = input()
	a = b = 0
	for i in range(len(s)):
		if s[i] == 'A':
			a += 1
			for j in range(i + 1, len(s)):
				if s[j] == 'B':
					break
				elif s[j] == 'A':
					a += j - i - 1
					i = j
					break
		elif s[i] == 'B':
			b += 1
			for j in range(i + 1, len(s)):
				if s[j] == 'A':
					break
				elif s[j] == 'B':
					b += j - i - 1
					i = j
					break
	print(a, b)


def Check1():
	(a, b, c) = (0, 0, 0)
	(a1, b1) = (-1, -1)
	x = input()
	for y in range(len(x)):
		if x[y] == 'A':
			if a1 != -1:
				a += y - a1
			else:
				a += 1
			(a1, b1) = (y, -1)
		elif x[y] == 'B':
			if b1 != -1:
				b += y - b1
			else:
				b += 1
			(a1, b1) = (-1, y)
	print(a, b)
t = int(input())
while t > 0:
	Check1()
	t -= 1


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	(l, r) = ([s[0]], [0] * n)
	r[-1] = s[-1]
	pr = s[0]
	(c1, c2) = (0, 0)
	for i in range(1, n):
		if s[i] == 'A':
			l.append('A')
			pr = 'A'
		elif s[i] == 'B':
			l.append('B')
			pr = 'B'
		else:
			l.append(pr)
	pr = s[-1]
	for i in range(n - 2, -1, -1):
		if s[i] == 'A':
			r[i] = 'A'
			pr = 'A'
		elif s[i] == 'B':
			r[i] = 'B'
			pr = 'B'
		else:
			r[i] = pr
	for i in range(n):
		if l[i] == r[i]:
			if l[i] == 'A':
				c1 += 1
			elif l[i] == 'B':
				c2 += 1
	print(c1, c2)


n = int(input())
for i in range(n):
	s = input()
	count = 0
	sount = 0
	a = ['v', -1]
	for j in range(len(s)):
		if s[j] == 'A':
			if a[0] != 'A':
				count += 1
				a[0] = 'A'
				a[1] = j
			else:
				count += j - a[1]
				a[1] = j
		if s[j] == 'B':
			if a[0] != 'B':
				sount += 1
				a[0] = 'B'
				a[1] = j
			else:
				sount += j - a[1]
				a[1] = j
	print(count, sount)


def Check1():
	(a, b) = (0, 0)
	(a1, b1) = (-1, -1)
	x = input()
	for y in range(len(x)):
		if x[y] == 'A':
			if a1 < 0:
				a1 = y - 1
			a += y - a1
			(a1, b1) = (y, -1)
		elif x[y] == 'B':
			if b1 < 0:
				b1 = y - 1
			b += y - b1
			(a1, b1) = (-1, y)
	print(a, b)
for x in range(int(input())):
	Check1()


def Check():
	(a, b, c) = (0, 0, 0)
	(a1, b1) = (False, False)
	x = input()
	for y in x:
		if y == 'A':
			a += 1
			if a1 and b1 == False:
				a += c
			c = 0
			(a1, b1) = (True, False)
		elif y == 'B':
			b += 1
			if b1 and a1 == False:
				b += c
			c = 0
			(a1, b1) = (False, True)
		elif y == '.':
			c += 1
	print(a, b)
t = int(input())
while t > 0:
	Check()
	t -= 1


from sys import stdin

def Check():
	a = 0
	b = 0
	c = 0
	a1 = False
	b1 = False
	x = stdin.readline()
	for y in range(len(x)):
		if x[y] == 'A':
			a += 1
			if b1:
				c = 0
			if a1:
				a += c
				c = 0
			else:
				c = 0
			b1 = False
			a1 = True
		elif x[y] == 'B':
			b += 1
			if a1:
				c = 0
			if b1:
				b += c
				c = 0
			else:
				c = 0
			a1 = False
			b1 = True
		elif x[y] == '.':
			c += 1
	print(a, b)
t = int(stdin.readline())
while t > 0:
	Check()
	t -= 1


from sys import stdin, stdout
for x1 in range(int(stdin.readline())):
	a = 0
	b = 0
	c = 0
	a1 = False
	b1 = False
	x = str(stdin.readline())
	for y in range(len(x)):
		if x[y] == 'A':
			a += 1
			if b1:
				c = 0
			if a1:
				a += c
				c = 0
			else:
				c = 0
			b1 = False
			a1 = True
		elif x[y] == 'B':
			b += 1
			if a1:
				c = 0
			if b1:
				b += c
				c = 0
			else:
				c = 0
			a1 = False
			b1 = True
		elif x[y] == '.':
			c += 1
	print(a, b)


c = []
for x in range(int(input())):
	c.append(str(input()))
for x in c:
	a = 0
	b = 0
	c = 0
	a1 = False
	b1 = False
	for y in range(len(x)):
		if x[y] == 'A':
			a += 1
			if b1:
				c = 0
			if a1:
				a += c
				c = 0
			else:
				c = 0
			b1 = False
			a1 = True
		elif x[y] == 'B':
			b += 1
			if a1:
				c = 0
			if b1:
				b += c
				c = 0
			else:
				c = 0
			a1 = False
			b1 = True
		elif x[y] == '.':
			c += 1
	print(a, b)


for t in range(int(input())):
	(a, b, c) = (0, 0, 0)
	s = list(input())
	(a, b) = (s.count('A'), s.count('B'))
	for i in range(len(s)):
		if s[i] == 'A' or s[i] == 'B':
			(x, xi) = (s[i], i)
			break
	for i in range(xi, len(s)):
		if s[i] == '.':
			c += 1
		elif s[i] == x and x == 'A':
			(a, c, x) = (a + c, 0, 'A')
		elif s[i] == x and x == 'B':
			(b, c, x) = (b + c, 0, 'B')
		else:
			(c, x) = (0, s[i])
	print(a, b)