You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.

String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even).

In one operation you can reverse any substring of $s$. A substring of a string is a contiguous subsequence of that string.

What is the minimum number of operations you need to make string $s$ alternating? A string is alternating if $s_i \neq s_{i + 1}$ for all $i$. There are two types of alternating strings in general: 01010101... or 10101010...


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($2 \le n \le 10^5$; $n$ is even) — the length of string $s$.

The second line of each test case contains a binary string $s$ of length $n$ ($s_i \in$ {0, 1}). String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones.

It's guaranteed that the total sum of $n$ over test cases doesn't exceed $10^5$.


-----Output-----

For each test case, print the minimum number of operations to make $s$ alternating.


-----Example-----
Input
3
2
10
4
0110
8
11101000

Output
0
1
2



-----Note-----

In the first test case, string 10 is already alternating.

In the second test case, we can, for example, reverse the last two elements of $s$ and get: 0110 $\rightarrow$ 0101.

In the third test case, we can, for example, make the following two operations:   11101000 $\rightarrow$ 10101100;  10101100 $\rightarrow$ 10101010.

Difficulty: EASY
Tags: Greedy algorithms

Constructive algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import sys
from collections import defaultdict
from sys import maxsize

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()))
for _ in range(ini()):
	n = ini()
	s = sys.stdin.readline()
	t = 0
	if s[0] == '1':
		t = 1
	o = []
	c = 0
	for i in range(n):
		if s[i] == '1':
			c += 1
		else:
			if c != 0:
				o += [c]
			c = 0
	if c != 0:
		o += [c]
	t = 0
	x = sum(o) - len(o)
	if s[0] == '0':
		t = 1
	o = []
	c = 0
	for i in range(n):
		if s[i] == '0':
			c += 1
		else:
			if c != 0:
				o += [c]
			c = 0
	if c != 0:
		o += [c]
	y = sum(o) - len(o)
	print(max(x, y))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	count = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			count += 1
	print(int((count + 1) // 2))


import sys
for test in range(int(input())):
	n = int(input())
	s = input()
	zac = s[0]
	p = zac
	c = []
	d = []
	np = 0
	for i in range(1, len(s)):
		if s[i] == p:
			np += 1
		else:
			if p != zac:
				c.append(np)
			p = s[i]
			np = 0
	if p != zac:
		c.append(np)
	print(sum(c))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	c = [0, 0]
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '1':
				c[1] += 1
			else:
				c[0] += 1
	if s[-1] == s[0]:
		c[int(s[0])] += 1
	print(sum(c) // 2)


for s in [*open(0)][2::2]:
	print(len(s) - 1 - s.count('01') - s.count('10') >> 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = 0
	for i in s.split('0'):
		p = len(i)
		if p - 1 > 0:
			a += p - 1
	b = 0
	for i in s.split('1'):
		p = len(i)
		if p - 1 > 0:
			b += p - 1
	print(max(a, b))


for j in range(int(input())):
	n = int(input())
	g = 0
	a = list(input())
	for i in range(n):
		if a[i] == '1':
			if a[i - 1] != '0':
				g += 1
	print(g)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ones = 0
	zeros = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '1':
				ones += 1
			else:
				zeros += 1
	print(max(ones, zeros))


ans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, list(input())))
	cnt1 = cnt0 = 0
	for i in range(1, n):
		if u[i] == u[i - 1]:
			if u[i] == 0:
				cnt0 += 1
			else:
				cnt1 += 1
	ans.append(max(cnt1, cnt0))
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	k = 0
	while i < n:
		if s[i] == '1':
			i += 1
			while i < n and s[i] == '1':
				k += 1
				i += 1
		i += 1
	i = 0
	k1 = 0
	while i < n:
		if s[i] == '0':
			i += 1
			while i < n and s[i] == '0':
				k1 += 1
				i += 1
		i += 1
	print(max(k, k1))


for i in range(int(input())):
	n = int(input())
	s = input()
	c1 = 0
	c0 = 0
	l1 = []
	l0 = []
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '1':
				c1 += 1
			else:
				c0 += 1
		elif s[i] == '0':
			l1.append(c1)
			c1 = 0
		else:
			l0.append(c0)
			c0 = 0
	print(max(sum(l1), sum(l0)))


import sys
t = int(input())
for tc in range(t):
	n = int(input())
	string = input()
	ans = 0
	for i in range(n):
		if string[i] == '1' and string[i] == string[(i + 1) % n]:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input()]
	(sum_, ans) = (-1, 0)
	for i in l:
		if i == 1:
			sum_ += 1
		else:
			ans += max(0, sum_)
			sum_ = -1
	(sum2, ans2) = (-1, 0)
	for i in l:
		if i == 0:
			sum2 += 1
		else:
			ans2 += max(0, sum2)
			sum2 = -1
	print(max(ans2, ans))


for _ in range(int(input())):
	l = int(input())
	s = input()
	c = 0
	for i in range(l):
		if s[i] == '1' and s[(i + 1) % l] == '1':
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	x = s.count('10')
	y = s.count('01')
	print((n - x - y) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	for i in range(1, n):
		c += s[i] == s[i - 1]
	print((c + 1) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	(*s,) = map(int, list(input()))
	cnt = 0
	for i in range(n - 1):
		cnt += s[i] == s[i + 1]
	print((cnt + 1) // 2)


import math
import string
import random
from random import randrange
from collections import deque
from collections import defaultdict

def solve(n, arr, x, y, s):
	ans = []
	ans1 = []
	st = 0
	i = 0
	one = False
	while i < n:
		if s[i] == '1' and (not one):
			one = True
			st = i
		elif s[i] == '0' and one:
			ans.append([st, i - 1])
			one = False
		i += 1
	if one:
		ans.append([st, n - 1])
	st = 0
	zero = False
	i = 0
	while i < n:
		if s[i] == '0' and (not zero):
			zero = True
			st = i
		elif s[i] == '1' and zero:
			ans1.append([st, i - 1])
			zero = False
		i += 1
	if zero:
		ans1.append([st, n - 1])
	fa = 0
	for i in ans:
		fa += i[1] - i[0]
	fb = 0
	for i in ans1:
		fb += i[1] - i[0]
	print(max(fa, fb))
	return

def main():
	t = int(input())
	while t > 0:
		t -= 1
		(x, y) = (0, 0)
		arr = []
		s = ''
		n = int(input())
		s = input().strip()
		solve(n, arr, x, y, s)
	return

def test():
	arr_size = 25
	test_cases = 100
	min_range = -100
	max_range = 100
	str_size = 30
	step = 1
	for i in range(test_cases):
		k = []
		for j in range(arr_size):
			num = randrange(min_range, max_range, step)
			k.append(num)
		solve(n, arr)
		print('<-------- DEBUG ----------->')
	return
main()


for _ in range(int(input())):
	a = int(input())
	b = input()
	(c, d) = (0, 0)
	for _ in range(0, a - 1):
		if b[_] == '0' and b[_ + 1] == '0':
			c += 1
	for _ in range(0, a - 1):
		if b[_] == '1' and b[_ + 1] == '1':
			d += 1
	print(max(c, d))


import sys, os
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve_(lst):
	res1 = 0
	res0 = 0
	for (a, b) in zip(lst, lst[1:]):
		if a == b == '1':
			res1 += 1
		if a == b == '0':
			res0 += 1
	return max(res1, res0)

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	pass
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def console(*args):
		pass

def solve(*args):
	console('----- solving ------')
	console(*args)
	console('----- ------- ------')
	return solve_(*args)
if True:
	inp = iter(sys.stdin.buffer.readlines())
	input = lambda : next(inp)
else:
	input = sys.stdin.buffer.readline
for case_num in range(int(input())):
	_ = input()
	strr = input()
	strr = [chr(x) for x in strr.strip()]
	res = solve(strr)
	print(res)


for p in [*open(0)][2::2]:
	print(len(p) // 2 - p.count(p[0] + '01'[p[0] < '1']))


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	s = input().strip()
	cnt = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print((cnt + 1) // 2)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = input()
	blocks = [[s[0], 1]]
	for i in range(1, n):
		if s[i] == blocks[-1][0]:
			blocks[-1][1] += 1
		else:
			blocks += [[s[i], 1]]
	one = 0
	zero = 0
	for i in range(len(blocks)):
		if blocks[i][0] == '0':
			zero += blocks[i][1] - 1
		else:
			one += blocks[i][1] - 1
	print(max(one, zero))


for _ in range(int(input())):
	n = int(input())
	s = input()
	(a, b) = ('10' * (n // 2), '01' * (n // 2))
	cnt = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print((cnt + 1) // 2)


try:
	test = int(input())
	for _ in range(test):
		n = int(input())
		str = input()
		ans = ''
		str1 = str.replace('10', '')
		str2 = str.replace('01', '')
		if len(str1) <= len(str2):
			ans = str1
		else:
			ans = str2
		print(len(ans) // 2)
except:
	pass


from math import ceil
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	cntt = 0
	for i in range(1, n):
		if int(s[i]) != 1 - int(s[i - 1]):
			cntt += 1
	print(ceil(cntt / 2))


for _ in range(int(input().strip())):
	n = int(input().strip())
	s = input().strip(' ')
	copy = '01' * (n // 2) if s[0] == '0' else '10' * (n // 2)
	(i, ans) = (0, 0)
	while i < n:
		if s[i] != copy[i]:
			ans += 1
			while i < n and s[i] != copy[i]:
				i += 1
		else:
			i += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	ans0 = 0
	ans1 = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '0':
			ans0 += 1
		if s[i] == s[i + 1] and s[i] == '1':
			ans1 += 1
	print(max(ans1, ans0))


for _ in ' ' * int(input()):
	n = int(input())
	s = input()
	cntone = 0
	cntzero = 0
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			cntone += 1
	for i in range(1, n):
		if s[i] == '0' and s[i - 1] == '0':
			cntzero += 1
	print(max(cntone, cntzero))


for irjfr in range(int(input())):
	input()
	s = input()
	res = int(s[0] == s[-1] == '1')
	for i in range(len(s) - 1):
		res += int(s[i] == s[i + 1] == '1')
	print(res)


for _ in range(int(input())):
	input()
	l = input()
	sone = 0
	szero = 0
	cones = 0
	czeros = 0
	for x in l:
		if x == '1':
			cones += 1
			if czeros > 0:
				szero += czeros - 1
				czeros = 0
		else:
			czeros += 1
			if cones > 0:
				sone += cones - 1
				cones = 0
	if czeros > 0:
		szero += czeros - 1
	if cones > 0:
		sone += cones - 1
	print(max(szero, sone))


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	o = 0
	z = 0
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i] == s[i + 1]:
			z += 1
		elif s[i] == '1' and s[i] == s[i + 1]:
			o += 1
	if z == 0 and o != 0:
		print(o)
	elif z != 0 and o == 0:
		print(z)
	else:
		print(max(z, o))


for _ in range(int(input())):
	n = int(input())
	l = list(input())
	res = 0
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			res += 1
	print(res // 2 + res % 2)


for i in range(int(input())):
	x = int(input())
	s = input()
	sum = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			sum += 1
	print((sum + 1) // 2)


T = int(input())
while T:
	n = int(input())
	s = input()
	res = 0
	for i in range(1, len(s)):
		res += s[i] == s[i - 1]
	print((res + 1) // 2)
	T -= 1


from sys import setrecursionlimit
setrecursionlimit(150000)

def findLeftRecursively(string, index, counter, choice):
	if index != 0:
		if string[index - 1] == choice:
			return [counter, index]
		else:
			counter += 1
			return findLeftRecursively(string, index - 1, counter, choice)
	else:
		return [counter, index]

def findRightRecursively(string, index, counter, choice):
	if index + 1 != len(string):
		if string[index + 1] == choice:
			return [counter, index]
		else:
			counter += 1
			return findRightRecursively(string, index + 1, counter, choice)
	else:
		return [counter, index]

def findRecursively(string, index, choice):
	first = findLeftRecursively(string, index, 0, choice) + findRightRecursively(string, index, 0, choice)
	return first

def findMiddleLs(string):
	ignore1 = [0, 0]
	ignore0 = [0, 0]
	totalCount1 = 0
	totalCount2 = 0
	for (i, v) in enumerate(string):
		if int(v) == 1 and (i > ignore1[1] or i < ignore1[0]):
			findLs = findRecursively(string, i, '0')
			ignore1 = [findLs[1], findLs[3]]
			totalCount1 += findLs[0] + findLs[2]
		elif v == '0' and (i > ignore0[1] or i < ignore0[0]):
			findWs = findRecursively(string, i, '1')
			ignore0 = [findWs[1], findWs[3]]
			totalCount2 += findWs[0] + findWs[2]
	if totalCount1 >= totalCount2:
		return totalCount1
	else:
		return totalCount2
strings = []
for i in range(int(input())):
	input()
	strings.append(input())
for i in strings:
	if len(i) < 1000:
		print(findMiddleLs(i))
	else:
		print(49999)


for tc in range(int(input())):
	n = int(input())
	string = input()
	currentChanges = 0
	for i in range(len(string) - 1):
		if string[i + 1] == string[i]:
			currentChanges += 1
	print((currentChanges + 1) // 2)


t = int(input())
for ii in range(t):
	n = int(input())
	s = input()
	d = 0
	a = [1]
	t = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			t += 1
	print((t + 1) // 2)


for cnt in range(int(input())):
	n = int(input())
	s = input()
	cn1 = 0
	cn0 = 0
	for i in range(n - 1):
		if s[i] == s[i + 1] == '1':
			cn1 += 1
		if s[i] == s[i + 1] == '0':
			cn0 += 1
	print(max(cn1, cn0))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = s.count('10')
	b = s.count('01')
	c = int((n - a - b) / 2)
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	for i in range(0, n - 1):
		if s[i] == s[i + 1]:
			c += 1
	print((c + 1) // 2)


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	y = inp()
	s = insr()
	prev = s[0]
	ans1 = 0
	ans0 = 0
	for j in range(1, len(s)):
		if prev == '1' and s[j] == '1':
			ans1 += 1
		if prev == '0' and s[j] == '0':
			ans0 += 1
		prev = s[j]
	print(max(ans1, ans0))


ans = []
for t in range(int(input())):
	n = int(input())
	s = input()
	ans += [n // 2 - max(s.count('10'), s.count('01'))]
print(*ans, sep='\n')


t = int(input())
for k in range(t):
	lenS = int(input())
	string = list(input())
	type1 = ['0'] + string + ['1']
	type2 = ['1'] + string + ['0']
	equalSubstrings_Type1 = 0
	equalSubstrings_Type2 = 0
	for i in range(lenS + 1):
		if type1[i] == type1[i + 1]:
			equalSubstrings_Type1 += 1
		if type2[i] == type2[i + 1]:
			equalSubstrings_Type2 += 1
	if equalSubstrings_Type1 < equalSubstrings_Type2:
		print(equalSubstrings_Type1 // 2)
	else:
		print(equalSubstrings_Type2 // 2)


t = int(input())
for i in range(t):
	n = input()
	s = input()
	knots = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			knots += 1
	print(int((knots + 1) / 2))


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 + 7

def solve():
	n = II()
	s = input()
	cnt = 0
	ans = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt > 0:
				ans += cnt - 1
			cnt = 0
	if s[n - 1] == '1' and cnt > 0:
		ans += cnt - 1
	ans2 = 0
	cnt = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			if cnt > 0:
				ans2 += cnt - 1
			cnt = 0
	if s[n - 1] == '0' and cnt > 0:
		ans2 += cnt - 1
	print(max(ans, ans2))
	return
t = II()
for i in range(t):
	solve()


a = int(input())
for i in range(a):
	s = int(input())
	s = input()
	cnt = 0
	b = 1
	ans = []
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			b += 1
		else:
			ans.append(b)
			b = 1
	ans.append(b)
	total = 0
	dec = 0
	for i in range(len(ans)):
		if ans[i] % 2 == 1:
			total += ans[i] // 2
		else:
			dec += 1
			total += (ans[i] - 1) // 2
	total += dec // 2
	if dec % 2 == 1:
		total += 1
	print(total)


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


from collections import deque
from collections import OrderedDict
from queue import PriorityQueue
from operator import attrgetter
import math
import sys
import os
import threading
import bisect
import operator
import queue
import heapq
from atexit import register
from io import BytesIO
import io
from sys import stdin, stdout
import os
import sys
from io import BytesIO, IOBase
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')
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	s = input()
	nonMetZF = 0
	nonMetOF = 0
	for i in range(n):
		if i % 2 == 0:
			if s[i] == '0':
				nonMetOF += 1
			else:
				nonMetZF += 1
		elif s[i] == '1':
			nonMetOF += 1
		else:
			nonMetZF += 1
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '0' and (i % 2 == 1):
			nonMetOF -= 1
		elif s[i] == '0' and s[i - 1] == '1' and (i % 2 == 0):
			nonMetOF -= 1
	for i in range(1, n):
		if s[i] == '0' and s[i - 1] == '1' and (i % 2 == 1):
			nonMetZF -= 1
		elif s[i] == '1' and s[i - 1] == '0' and (i % 2 == 0):
			nonMetZF -= 1
	print(min(nonMetZF, nonMetOF))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	s = [ch for ch in input()]
	c = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			c += 1
	print(ceil(c / 2))


def Solve():
	n = ri()
	a = rs()
	(o, z) = (0, 0)
	i = 0
	while i < n - 1:
		if a[i] != a[i + 1]:
			i += 1
			continue
		else:
			if a[i] == '1':
				o += 1
			if a[i] == '0':
				z += 1
			i += 1
	print(max(z, o))
import sys
inp = sys.stdin.buffer.readline
rl = lambda : list(map(int, inp().split()))
ri = lambda : int(inp())
rs = lambda : inp().decode().strip()
Testcase = 1
Testcase = ri()
for Test in range(Testcase):
	Solve()


def solve(n, s):
	moves = 0
	temp = ''
	if s[0] == '0':
		need = n // 2
		count = 0
		for i in range(n - 1):
			if s[i] == '0' and s[i + 1] == '1':
				count += 1
		return need - count
	if s[0] == '1':
		need = n // 2
		count = 0
		for i in range(n - 1):
			if s[i] == '1' and s[i + 1] == '0':
				count += 1
		return need - count
t = int(input())
while t:
	n = int(input())
	s = input()
	print(solve(n, s))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = input()
	c = 0
	for i in range(n - 1):
		if l[i] != l[i + 1]:
			c += 1
	print((n - c) // 2)


t = int(input())
while t:
	n = int(input())
	s = input()
	count0 = count1 = 0
	for i in range(1, len(s) - 1):
		if s[i] == s[i - 1]:
			if s[i] == '0':
				count0 += 1
			else:
				count1 += 1
	print(max(count0, count1))
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		s = list((int(x) for x in input()))
		zero = 0
		one = 0
		for i in range(n - 1):
			if s[i] == s[i + 1]:
				if s[i] == 0:
					zero += 1
				else:
					one += 1
		print(max(one, zero))
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()


t = int(input())
for _t in range(t):
	n = int(input())
	s = input()
	(out1, out2) = (0, 0)
	for (i, l) in enumerate(s):
		if i % 2 == (l == '1') and (not i or s[i - 1] == l):
			out1 += 1
	for (i, l) in enumerate(s):
		if i % 2 == (l == '0') and (not i or s[i - 1] == l):
			out2 += 1
	print(min(out1, out2))


def get(s: str) -> int:
	(cnt1, cnt2) = (0, 0)
	is_cnt1_change = False
	is_cnt2_change = False
	for i in range(len(s)):
		if i % 2 == 1:
			if int(s[i]) == 1:
				if not is_cnt1_change:
					cnt1 += 1
					is_cnt1_change = True
				is_cnt2_change = False
			else:
				if not is_cnt2_change:
					cnt2 += 1
					is_cnt2_change = True
				is_cnt1_change = False
		elif int(s[i]) == 1:
			if not is_cnt2_change:
				cnt2 += 1
				is_cnt2_change = True
			is_cnt1_change = False
		else:
			if not is_cnt1_change:
				cnt1 += 1
				is_cnt1_change = True
			is_cnt2_change = False
	return min(cnt1, cnt2)
n = int(input())
for i in range(n):
	slen = int(input())
	s = input()
	print(get(s))


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

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 inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def split_consecutive(sorted_data, cmp=lambda a, b: a + 1 >= b):
	result = []
	group = []
	prev = None
	for item in sorted_data:
		if not group or cmp(prev, item):
			group.append(item)
		else:
			result.append(group)
			group = [item]
		prev = item
	if group:
		result.append(group)
	return result

def solve():
	n = itg()
	s = inp()
	pat = ['0', '1']
	correct = [c == pat[i & 1] for (i, c) in enumerate(s)]
	ans = len(split_consecutive(correct, cmp=lambda a, b: a == b)) >> 1
	pat = ['1', '0']
	correct = [c == pat[i & 1] for (i, c) in enumerate(s)]
	ans = min(ans, len(split_consecutive(correct, cmp=lambda a, b: a == b)) >> 1)
	return ans

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = ''
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


from collections import defaultdict
from functools import reduce
from bisect import bisect_right
from bisect import bisect_left
import copy

def main():
	for _ in range(int(input())):
		n = int(input())
		l = input()
		c1 = 0
		c0 = 0
		for i in range(1, n):
			if l[i] == '1' and l[i - 1] == '1':
				c1 += 1
			if l[i] == '0' and l[i - 1] == '0':
				c0 += 1
		print(max(c1, c0))
main()


for _ in range(int(input())):
	l = int(input())
	if l == 2:
		input()
		print('0')
		continue
	bi = input()
	moves = 0
	for i in range(1, l):
		if bi[i] == bi[i - 1]:
			moves += 1
	print(moves // 2 + moves % 2)


import sys
for t in range(0, int(sys.stdin.readline())):
	ls = sys.stdin.readline()
	s = list(sys.stdin.readline())
	s.pop(len(s) - 1)
	dup = [0, 0]
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			dup[int(s[i])] += 1
	sys.stdout.write(str(max(dup)))
	sys.stdout.write('\n')


for _ in range(int(input())):
	n = int(input())
	ar = input()
	print(n // 2 - max(ar.count('01'), ar.count('10')))


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i + 1] == '0':
			i += 1
			c += 1
	k = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			i += 1
			k += 1
	print(max(c, k))


t = int(input())
for i in range(t):
	n = int(input())
	s = input().strip()
	sch = 0
	sch2 = 0
	for j in range(n - 1):
		if s[j + 1] == s[j] == '1':
			sch += 1
		if s[j + 1] == s[j] == '0':
			sch2 += 1
	print(max(sch, sch2))


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	s = input().strip('\n')
	l1 = []
	l2 = []
	l = []
	for i in range(n):
		l.append(int(s[i]))
		if i % 2 == 0:
			l1.append(1)
			l2.append(0)
		else:
			l1.append(0)
			l2.append(1)
	index1 = []
	index2 = []
	for i in range(n):
		if l[i] != l1[i]:
			index1.append(i)
		if l[i] != l2[i]:
			index2.append(i)
	ans1 = 0
	ans2 = 0
	length1 = len(index1)
	length2 = len(index2)
	for i in range(length1 - 1):
		if index1[i] + 1 == index1[i + 1]:
			continue
		else:
			ans1 += 1
	for i in range(length2 - 1):
		if index2[i] + 1 == index2[i + 1]:
			continue
		else:
			ans2 += 1
	if length1 > 0:
		ans1 += 1
	if length2 > 0:
		ans2 += 1
	print(min(ans1, ans2))


test_cases = int(input())
res = []
for test in range(test_cases):
	c0 = 0
	c1 = 0
	n = int(input())
	st = input()
	for i in range(n - 1):
		if st[i] == st[i + 1]:
			if st[i] == '1':
				c1 += 1
			else:
				c0 += 1
	res.append(max(c0, c1))
for value in res:
	print(value)


def func():
	n = int(input())
	for _ in range(n):
		k = int(input())
		s = input()
		x = 0
		for i in range(k - 1):
			if s[i] == s[i + 1]:
				x += 1
		if x % 2 == 0:
			print(x // 2)
		else:
			print(x // 2 + 1)
func()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	binary = input()
	length = n // 2
	if binary[0] == '1':
		print(length - binary.count('10'))
	else:
		print(length - binary.count('01'))


import os
import sys
from io import BytesIO, IOBase

def solution():
	n = int(input())
	s = input()
	val = s.count('10')
	a1 = n // 2 - val
	val = s.count('01')
	a2 = n // 2 - val
	print(min(a1, a2))
	return

def main():
	testcases = 1
	testcases = int(input())
	for _ in range(testcases):
		solution()
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, s) = (int(input()), input())
	print((n - s.count('10') - s.count('01')) // 2)


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = input()
	L = []
	ans1 = 1
	k1 = '0'
	k2 = '1'
	for i in range(0, len(s)):
		if i % 2 == 0 and s[i] == k1:
			ans1 += 1
			temp = k1
			k1 = k2
			k2 = temp
		elif i % 2 != 0 and s[i] == k2:
			ans1 += 1
			temp = k1
			k1 = k2
			k2 = temp
	ans1 = ans1 // 2
	ans2 = 1
	k2 = '0'
	k1 = '1'
	for i in range(0, len(s)):
		if i % 2 == 0 and s[i] == k1:
			ans2 += 1
			temp = k1
			k1 = k2
			k2 = temp
		elif i % 2 != 0 and s[i] == k2:
			ans2 += 1
			temp = k1
			k1 = k2
			k2 = temp
	ans2 = ans2 // 2
	print(min(ans1, ans2))


t = int(input())
for test in range(t):
	n = input()
	s = input()
	count = 0
	consec1 = sum([1 if s[i] == s[i + 1] and s[i] == '1' else 0 for i in range(len(s) - 1)])
	consec0 = sum([1 if s[i] == s[i + 1] and s[i] == '0' else 0 for i in range(len(s) - 1)])
	print(max([consec0, consec1]))


import math

def main_function():
	test_cases = range(int(input()))
	for test in test_cases:
		n = int(input())
		s = input()
		v_0_1 = 0
		v_1_0 = 0
		for i in range(len(s) - 1):
			if s[i] == '1' and s[i + 1] == '0':
				v_1_0 += 1
			elif s[i] == '0' and s[i + 1] == '1':
				v_0_1 += 1
		print(n // 2 - max(v_1_0, v_0_1))
main_function()


for _ in range(int(input())):
	n = int(input())
	k = input()
	start = k[0]
	count1 = 0
	count0 = 0
	for i in range(1, n):
		if k[i] != start:
			start = k[i]
		elif start == '0':
			count0 += 1
		else:
			count1 += 1
	print(max(count0, count1))


t = int(input())
for _ in range(t):
	n = int(input())
	l = input()
	c = 0
	ind = l[0]
	for i in range(n - 1):
		if l[i] == ind and l[i + 1] != ind:
			c += 1
	print(n // 2 - c)


from sys import stdin
import math
rl = stdin.readline

def main(n, s):
	nb_pairs = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			nb_pairs += 1
	print(math.ceil(nb_pairs / 2))
t = int(rl())
cases = [(int(rl()), rl().rstrip()) for _ in range(t)]
for (n, s) in cases:
	main(n, s)


import sys, math
from heapq import *
from collections import defaultdict as dd
mod = 10 ** 9 + 7
modd = 998244353
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n,) = inp()
	a = str(input())
	one = []
	zero = []
	prev = -1
	c = 1
	flag = False if a[0] == '0' else True
	for i in range(n):
		if prev == a[i]:
			c += 1
		else:
			if flag == True:
				zero.append(c)
				flag = False
			else:
				one.append(c)
				flag = True
			c = 1
			prev = a[i]
	a1 = sum(one) - len(one)
	a2 = sum(zero) - len(zero)
	print(max(a1, a2))


inp = lambda : int(input())
strl = lambda : list(input().strip())
seq = lambda : list(map(int, input().strip().split()))

def f(arr, n):
	cnt = 0
	i = 0
	while i < n - 1:
		if arr[i] == arr[i + 1]:
			j = i + 1
			cnt += 1
			while j < n - 1:
				if arr[j] == arr[j + 1]:
					i = j
					break
				j += 1
		i += 1
	return cnt

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		a = strl()
		result = f(a, n)
		print(result)
main()


for _ in ' ' * int(input()):
	a = int(input())
	b = input()
	(ans, ans1) = (0, 0)
	for i in range(a - 1):
		if b[i] == b[i + 1]:
			if b[i] == '0':
				ans += 1
			else:
				ans1 += 1
	print(max(ans, ans1))


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

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
for _ in range(vary(1)):
	n = vary(1)
	s = input()
	count = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			count += 1
	print(count // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	count = 0
	for i in range(n):
		try:
			if s[i] == s[i + 1]:
				count += 1
		except:
			pass
	print((count + 1) // 2)


def compress(string):
	n = len(string)
	(begin, cnt) = (0, 0)
	ans = []
	if n == 0:
		return ans
	for end in range(n + 1):
		if end == n or string[begin] != string[end]:
			ans.append((string[begin], cnt))
			(begin, cnt) = (end, 1)
		else:
			cnt += 1
	return ans
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	ans0 = [i % 2 for i in range(n)]
	for i in range(n):
		ans0[i] ^= int(a[i])
	a0 = compress(ans0)
	res0 = 0
	res1 = 0
	for (val, cnt) in a0:
		if val == 0:
			res0 += 1
		else:
			res1 += 1
	print(min(res0, res1))


for t in range(int(input())):
	n = int(input())
	s = input()
	c = s.count('01') + s.count('10')
	print((n - c) // 2)


testCount = int(input())

def check(s, l):
	target1 = ['1' if i & 1 else '0' for i in range(l)]
	target2 = ['0' if i & 1 else '1' for i in range(l)]
	(p1, p2) = (0, 0)
	(cur1, cur2) = (-1, -1)
	for (i, x) in enumerate(s):
		if x != target1[i]:
			if i != cur1:
				p1 += 1
			cur1 = i + 1
		if x != target2[i]:
			if i != cur2:
				p2 += 1
			cur2 = i + 1
	return min(p1, p2)
for _ in range(testCount):
	l = int(input())
	s = list(input())
	print(check(s, l))


n = int(input())
for i in range(n):
	(c1, c2) = (0, 0)
	m = input()
	s = input()
	for j in range(len(s) - 1):
		if s[j] == '1' and s[j + 1] == '1':
			c1 += 1
		elif s[j] == '0' and s[j + 1] == '0':
			c2 += 1
	print(max(c1, c2))


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		st = input().strip()
		mx = 0
		check = ''
		ln = 0
		one = 0
		zero = 0
		for i in range(n):
			if i == 0:
				check = st[i]
				ln += 1
				continue
			if check == st[i]:
				ln += 1
			else:
				if check == '0':
					zero += ln - 1
				else:
					one += ln - 1
				ln = 1
				check = st[i]
		if check == '0':
			zero += ln - 1
		else:
			one += ln - 1
		print(max(one, zero))
main()


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right
import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	x = []
	y = []
	c = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			c += 1
		else:
			if s[i - 1] == '1':
				x.append(c)
			else:
				y.append(c)
			c = 1
	if s[n - 1] == '1':
		x.append(c)
	else:
		y.append(c)
	print(max(sum(x) - len(x), sum(y) - len(y)))


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	c = 0
	ans = 0
	anss = 0
	k = 0
	for i in range(n - 1):
		if s[i] == '1':
			if s[i + 1] == '1':
				c += 1
			else:
				if c != 0:
					ans += c
				c = 0
		else:
			ans += c
			c = 0
		if s[i] == '0':
			if s[i + 1] == '0':
				k += 1
			else:
				if k != 0:
					anss += k
				k = 0
		else:
			anss += k
			k = 0
	ans += c
	anss += k
	print(max(ans, anss))


for j in range(int(input())):
	k = input()
	s = input()
	a = 0
	b = 0
	for i in range(1, len(s)):
		if s[i - 1] == '1' and s[i] == '1':
			a += 1
		elif s[i - 1] == '0' and s[i] == '0':
			b += 1
	print(max(a, b))


def solve(s, n, c):
	count = 0
	s = s.split(c)
	for i in s:
		if len(i) > 1:
			count += len(i) - 1
	return count
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(max(solve(s, n, '0'), solve(s, n, '1')))


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	s = input().strip()
	x = y = 0
	for (a, b) in zip(s, s[1:]):
		if a == '1' and b == '1':
			x += 1
		if a == '0' and b == '0':
			y += 1
	print(max(x, y))


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 si():
	return input()

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

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

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

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

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

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

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

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

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

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

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 read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	I = lambda : list(map(int, input().split()))
	for tc in range(int(input())):
		(n,) = I()
		s = input().strip()
		cnt = 1
		st = s[0]
		temp = []
		for i in s[1:]:
			if i == st:
				cnt += 1
			else:
				temp.append(cnt)
				st = i
				cnt = 1
		if cnt:
			temp.append(cnt)
		od = ev = 0
		for i in range(len(temp)):
			temp[i] -= 1
			if i % 2:
				od += temp[i]
			else:
				ev += temp[i]
		print(max(od, ev))
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()


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	if s[0] == '0':
		c = s.count('01')
	else:
		c = s.count('10')
	print(n // 2 - c)


T = int(input())
for i in range(T):
	N = int(input())
	s = input()
	c1 = 0
	c2 = 0
	for i in range(1, N):
		if s[i - 1] == s[i] and s[i] == '1':
			c1 += 1
		elif s[i - 1] == s[i] and s[i] == '0':
			c2 += 1
	print(max(c1, c2))


t = int(input())
for _ in range(t):
	n = int(input())
	min = n / 2
	s = input()
	if s[0] == '1':
		num = s.count('10')
	else:
		num = s.count('01')
	min -= num
	print(int(min))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	c11 = 0
	c00 = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '0':
				c00 += 1
			else:
				c11 += 1
	print(max(c11, c00))


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from typing import List
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
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')

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

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x, mod=0):
	if x < 2:
		return 1
	if not mod:
		return fact(x - 1) * x
	return fact(x - 1, mod) * x % mod

@lru_cache(None)
def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	ans = 1
	for k in range(i - j + 1, i + 1):
		ans = ans * k % mod
	return ans

@lru_cache(None)
def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j) * inverse(fact(j), mod) % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	n = N()
	s = input()
	res = []
	for (ch, g) in groupby(s):
		res.append((ch, len(list(g))))
	a = b = 0
	for (ch, l) in res:
		if ch == '1':
			a += l - 1
		else:
			b += l - 1
	ans = max(a, b)
	print(ans)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		s = input().strip()
		one = 0
		zero = 0
		for i in range(n - 1):
			if s[i] == '0' and s[i] == s[i + 1]:
				zero += 1
			elif s[i] == '1' and s[i] == s[i + 1]:
				one += 1
		print(max(zero, one))
prog()


for _ti in range(int(input())):
	n = int(input())
	s = input()
	a = 0
	b = 0
	for (p, i) in enumerate(s[1:]):
		if i == s[p] and i == '0':
			a += 1
		if i == s[p] and i == '1':
			b += 1
	print(max(a, b))


for T in range(int(input())):
	n = int(input())
	s = input()
	all_1 = s.split('0')
	all_1 = [len(a) - 1 for a in all_1 if a != '']
	all_0 = s.split('1')
	all_0 = [len(a) - 1 for a in all_0 if a != '']
	print(max(sum(all_1), sum(all_0)))


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	c = 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			c += 1
	print(c // 2)


t = int(input())
for t in range(0, t):
	n = int(input())
	str = input()
	a = str.count('01')
	b = str.count('10')
	max1 = max(a, b)
	print(n // 2 - max1)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	s = sys.stdin.readline().strip()
	res = 0
	i = 0
	while i < n:
		while i < n and s[i] != '1':
			i += 1
		if i >= n:
			break
		while i < n and s[i] == '1':
			i += 1
			res += 1
		i += 1
		res -= 1
	i = 0
	ans = 0
	while i < n:
		while i < n and s[i] != '0':
			i += 1
		if i >= n:
			break
		while i < n and s[i] == '0':
			i += 1
			ans += 1
		i += 1
		ans -= 1
	print(max(ans, res))
for i in range(int(sys.stdin.readline().strip())):
	main()


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
from statistics import *
inf = float('inf')
ninf = -float('inf')
ip = input
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

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

def ipn():
	return int(input())

def ipf():
	return float(input())

def solve():
	n = ipn()
	s = ip()
	print(n // 2 - max(s.count('01'), s.count('10')))
for _ in range(ipn()):
	solve()


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	result = 0
	result2 = 0
	temp = 0
	temp2 = 0
	for i in s:
		if i == '1':
			temp += 1
			if temp2 > 1:
				result2 += temp2 - 1
			temp2 = 0
		else:
			temp2 += 1
			if temp > 1:
				result += temp - 1
			temp = 0
	print(max(result, result2))


import math
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	x = s.count('10')
	y = s.count('01')
	tmp = n - x - y
	if tmp == 1:
		print(0)
	elif n % 2 == 0:
		print(tmp // 2)
	else:
		print(math.ceil(tmp / 2))


for i in range(int(input())):
	n = int(input())
	s = input()
	a = s.split('0')
	b = s.split('1')
	ans1 = 0
	ans2 = 0
	for i in a:
		if len(i) > 0:
			ans1 += len(i) - 1
	for i in b:
		if len(i) > 0:
			ans2 += len(i) - 1
	print(max(ans1, ans2))


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

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

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	n = II()
	s = BI()
	ans = 0
	for (a0, a1) in zip(s, s[1:]):
		if a0 == a1:
			ans += 1
	print((ans + 1) // 2)


mod = 10 ** 9 + 7

def solve():
	n = int(input())
	s = list(input())
	ans = 0
	for i in range(n):
		if s[i] == s[(i + 1) % n]:
			ans += 1
	print(ans // 2)
t = 1
t = int(input())
while t > 0:
	solve()
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			ans += 1
	print((ans + 1) // 2)


t = int(input())
for case in range(t):
	n = int(input())
	s = input()
	c = [0, 0]
	for i in range(1, n):
		if s[i] == s[i - 1] == '1':
			c[1] += 1
		elif s[i] == s[i - 1] == '0':
			c[0] += 1
	ans = max(c)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print((cnt + 1) // 2)


from sys import stdin, stdout
from collections import deque
import bisect
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
T = int(input())
for _ in range(T):
	n = int(input())
	s = R()
	ans1 = 0
	ans2 = 0
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			ans1 += 1
		if s[i] == '0' and s[i - 1] == '0':
			ans2 += 1
	print(max(ans1, ans2))


t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	zero = 0
	one = 0
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			zero += 1
		if s[i] == '1' and s[i + 1] == '1':
			one += 1
	print(max(zero, one))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		count = 0
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				count += 1
		print((count + 1) // 2)
main()


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	s = input()
	res = INF
	cnt = 0
	f = False
	for (i, x) in enumerate(s):
		if i % 2 == int(x):
			if not f:
				cnt += 1
				f = True
		else:
			f = False
	res = min(res, cnt)
	cnt = 0
	f = False
	for (i, x) in enumerate(s):
		if i % 2 != int(x):
			if not f:
				cnt += 1
				f = True
		else:
			f = False
	print(min(res, cnt))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	S = input().strip()
	A = 0
	for i in range(1, n):
		if S[i] == S[i - 1]:
			A += 1
	print((A + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(oneZero, zeroOne) = (s.count('10'), s.count('01'))
	print((n - 2 * max(oneZero, zeroOne)) // 2)


import math
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = zero = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '1':
				one += 1
			else:
				zero += 1
	print(max(zero, one))


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	c0 = 0
	c1 = 0
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			if l[i] == '0':
				c0 += 1
			else:
				c1 += 1
	print(max(c0, c1))


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

def li():
	return [int(i) for i in input().split()]
for tt in range(ii()):
	N = ii()
	s = input()
	zm = 0
	zo = 0
	for i in range(N - 1):
		if s[i] == '0':
			if s[i] == s[i + 1]:
				zm += 1
		elif s[i] == s[i + 1]:
			zo += 1
	print(max(zm, zo))


import sys, math, itertools, collections, copy
input = sys.stdin.readline

def solve():
	N = int(input())
	s = input()
	s = s[:-1]
	zero_blocks = []
	ones_blocks = []
	cur = 1
	ones = False
	for i in range(1, N):
		if s[i] == s[i - 1]:
			cur += 1
			if s[i] == '1':
				ones = True
			else:
				ones = False
		else:
			if cur >= 2:
				if ones:
					ones_blocks.append(cur)
				else:
					zero_blocks.append(cur)
			if s[i] == '1':
				ones = True
				cur = 1
			else:
				ones = False
				cur = 1
	if cur > 1:
		if ones:
			ones_blocks.append(cur)
		else:
			zero_blocks.append(cur)
	if len(ones_blocks) == 0 and len(zero_blocks) == 0:
		print(0)
		return
	else:
		(cur1, cur2) = (0, 0)
		for i in range(len(ones_blocks)):
			cur1 += ones_blocks[i] - 1
		for i in range(len(zero_blocks)):
			cur2 += zero_blocks[i] - 1
		print(max(cur1, cur2, 0))
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	x = s.replace('01', '')
	ans = len(x) // 2
	y = s.replace('10', '')
	ans2 = len(y) // 2
	print(min(ans, ans2))


for _ in range(0, int(input())):
	n = int(input())
	a = input()
	i = 0
	o = 0
	e = 0
	for i in range(0, n - 1):
		if a[i] == a[i + 1] and a[i] == '1':
			o = o + 1
		elif a[i] == a[i + 1] and a[i] == '0':
			e = e + 1
	print(max(e, o))


import math
for j in range(int(input())):
	n = int(input())
	s = input()
	r = 0
	for i in range(1, n):
		if s[i - 1] == s[i]:
			r += 1
	print(math.ceil(r / 2))


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

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

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	n = read_int()
	s = read_line()
	cons_one = 1 if s[0] == '1' else 0
	cons_zer = 1 if s[0] == '0' else 0
	use_one = 0
	use_zer = 0
	for c in s[1:]:
		if c == '0':
			use_one += max(cons_one - 1, 0)
			cons_one = 0
			cons_zer += 1
		else:
			use_zer += max(cons_zer - 1, 0)
			cons_zer = 0
			cons_one += 1
	else:
		use_one += max(cons_one - 1, 0)
		use_zer += max(cons_zer - 1, 0)
	print(max(use_one, use_zer))

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


t = int(input())
while t:
	t += -1
	n = int(input())
	s = input()
	(cnt0, cnt1) = (0, 0)
	(zero, one) = (0, 0)
	for i in s:
		if i == '0':
			if zero == 0 and one:
				cnt1 += one - 1
				one = 0
			zero -= -1
		else:
			if one == 0 and zero:
				cnt0 += zero - 1
				zero = 0
			one -= -1
	if one:
		cnt1 += one - 1
	if zero:
		cnt0 += zero - 1
	print(max(cnt0, cnt1))


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	sz = 0
	ans = 0
	for i in range(n):
		if s[i] == '1':
			sz += 1
		else:
			ans += max(0, sz - 1)
			sz = 0
	ans += max(0, sz - 1)
	ans2 = 0
	sz = 0
	for i in range(n):
		if s[i] == '0':
			sz += 1
		else:
			ans2 += max(0, sz - 1)
			sz = 0
	ans2 += max(0, sz - 1)
	print(max(ans2, ans))


import math

def solve():
	n = int(input())
	s = input()
	count_zeroes = 0
	count_ones = 0
	current_ones = 0
	current_zeroes = 0
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			current_ones += 1
		else:
			count_ones += current_ones
			current_ones = 0
		if s[i] == '0' and s[i - 1] == '0':
			current_zeroes += 1
		else:
			count_zeroes += current_zeroes
			current_zeroes = 0
	count_ones += current_ones
	count_zeroes += current_zeroes
	return max(count_ones, count_zeroes)
t = int(input())
while t > 0:
	t -= 1
	print(solve())


for _ in [0] * int(input()):
	n = int(input())
	s = input()
	k = p = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			k = k + 1
		if s[i] == '0' and s[i + 1] == '0':
			p = p + 1
	print(max(k, p))


def solve(n, s):
	count = 0
	for i in range(n):
		if s[i] == s[(i + 1) % n]:
			count += 1
	return count // 2
T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	ans = solve(n, s)
	print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 32, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

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 countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			ans += 1
	print(int(math.ceil(ans / 2)))


for _ in range(int(input())):
	n = int(input())
	s = input()
	(zo, oz) = (s.count('01'), s.count('10'))
	if zo == n or oz == n:
		print(0)
	else:
		m = min(zo, oz)
		t = n - 2 * (oz + zo - m)
		print(t // 2)


for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input()))
	c = 0
	for i in range(0, n - 1):
		if ar[i] == ar[i + 1]:
			c += 1
	print((c + 1) // 2)


import sys

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		s = get_string()
		print((n - s.count('10') - s.count('01')) // 2)
solve()


import math
t = int(input())
for i in range(t):
	counter = 0
	codd = 0
	ceven = 0
	n = int(input())
	s = input()
	g = s[0]
	s = s[1:]
	for i in s:
		if i == g:
			counter += 1
		g = i
	print(math.ceil(counter / 2))


def solve():
	n = int(input())
	s = input()
	w = ''
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			w += s[i]
	c1 = 0
	c0 = 0
	for i in w:
		if i == '1':
			c1 += 1
		else:
			c0 += 1
	print(max(c1, c0))
t = int(input())
for i in range(t):
	solve()


from itertools import groupby
T = int(input())
for _ in range(T):
	N = int(input())
	S = list(map(int, input()))
	S1 = [c == i % 2 for (i, c) in enumerate(S)]
	ans1 = sum((v for (v, gr) in groupby(S1)))
	S2 = [c == i % 2 for (i, c) in enumerate(S, 1)]
	ans2 = sum((v for (v, gr) in groupby(S2)))
	print(min(ans1, ans2))


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	r = 0
	for i in range(1, n):
		if s[i - 1] != s[i]:
			continue
		else:
			r += 1
	print(math.ceil(r / 2))


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	count = 0
	for j in range(0, n):
		if j != n - 1:
			if s[j] == s[j + 1]:
				count = count + 1
		elif s[j] == s[0]:
			count = count + 1
	print(count // 2)


import collections
import math
from itertools import permutations as p
for t in range(int(input())):
	n = int(input())
	s = input()
	stack = []
	for i in s:
		if i == '1':
			if stack and stack[-1] == '0':
				stack.pop()
		elif stack and stack[-1] == '1':
			stack.pop()
		stack.append(i)
	print(len(stack) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(zo, oz) = (s.count('01'), s.count('10'))
	t = n - 2 * max(zo, oz)
	print(t // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 2:
		print(0)
	else:
		s1 = '1' + s + '0'
		s2 = '0' + s + '1'
		(ans1, ans2) = (0, 0)
		for i in range(len(s1) - 1):
			if s1[i] == s1[i + 1]:
				ans1 += 1
		else:
			ans1 //= 2
		for i in range(len(s2) - 1):
			if s2[i] == s2[i + 1]:
				ans2 += 1
		else:
			ans2 //= 2
		print(min(ans1, ans2))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = s.count('10')
	b = s.count('01')
	print((n - a - b) // 2)


for i in range(int(input())):
	n = int(input())
	s = input()
	count = 1
	for j in range(1, n):
		if s[j] == s[j - 1]:
			count += 1
	print(count // 2)


for _ in range(int(input())):
	n = int(input())
	(*s,) = list(map(int, input()))
	cnt = [0, 0]
	for i in range(len(s)):
		if i > 0 and s[i] == s[i - 1]:
			cnt[s[i]] += 1
	print(max(cnt))


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	ans = 0
	for i in range(-1, n - 1):
		if int(s[i + 1]) - int(s[i]) == 0 and int(s[i + 1]) == int(s[i]) == 1:
			ans += 1
		else:
			continue
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = 0
	b = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '0':
				a = a + 1
			else:
				b = b + 1
	print(max(a, b))


for _ in range(int(input())):
	n = int(input())
	a = input()
	one = 0
	zero = 0
	for i in range(n - 1):
		if a[i] == '0' and a[i + 1] == '0':
			zero += 1
		elif a[i] == '1' and a[i + 1] == '1':
			one += 1
	print(max(zero, one))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	c = f = 0
	if s[0] == '0':
		s1 = '01' * (n // 2)
	else:
		s1 = '10' * (n // 2)
	for i in range(n):
		if s[i] != s1[i]:
			if f == 0:
				c += 1
				f = 1
		else:
			f = 0
	print(c)


for i in range(int(input())):
	n = int(input())
	s = input()
	if s[0] == '0':
		z = '1' + s + '0'
		c = 0
		for i in range(1, len(z)):
			if z[i - 1] == z[i]:
				c += 1
		print(c // 2)
	elif s[0] == '1':
		z = '0' + s + '1'
		c = 0
		for i in range(1, len(z)):
			if z[i - 1] == z[i]:
				c += 1
		print(c // 2)


t = int(input())
while t > 0:
	n = int(input())
	s = str(input())
	ans = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			ans = ans + 1
	print((ans + 1) // 2)
	t = t - 1


def main():
	t = int(input())
	while t > 0:
		n = int(input())
		calc_ops()
		t -= 1

def calc_ops():
	s = input()
	i = 0
	ans = 0
	while i < len(s) - 1:
		if s[i] == '1' and s[i + 1] == '1':
			ans += 1
		i += 1
	if s[0] == '1' and s[len(s) - 1] == '1':
		ans += 1
	print(ans)
main()


t = int(input())
for w in range(t):
	sup = input()
	str = input()
	amount = 0 if str[0] != str[-1] else 1
	zero = 1 if str[0] == str[-1] and str[0] == '0' else 0
	one = 1 if str[0] == str[-1] and str[0] == '1' else 0
	for i in range(len(str) - 1):
		if str[i + 1] == str[i] and str[i] == '0':
			zero += 1
		if str[i + 1] == str[i] and str[i] == '1':
			one += 1
	print(zero if zero < one else one)


tcs = int(input())
result = []
for case in range(tcs):
	n = int(input())
	s = input()
	violation = 0
	nonviolation = 0
	violationflip = False
	oldviolation = 0
	doublevio = 0
	for i in range(len(s)):
		if s[i - 1] == s[i]:
			violation += 1
	if violation % 2 == 0:
		result.append(str(violation // 2))
	else:
		result.append(str(violation // 2 + 1))
for res in result:
	print(res)


def solve():
	n = int(input())
	s = input()
	answer = (n - s.count('10') - s.count('01')) // 2
	print(answer)
t = int(input())
while t:
	solve()
	t -= 1


for i in range(int(input())):
	n = int(input())
	s = list(input())
	a = 0
	for i in range(n):
		if s[i] == '1':
			if s[i - 1] != '0':
				a += 1
	print(a)


for test in range(int(input())):
	n = int(input())
	s = str(input())
	(one, zero) = (0, 0)
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			one += 1 if s[i] == '1' else 0
			zero += 1 if s[i] == '0' else 0
	print(max(one, zero))


t = int(input())
for tc in range(t):
	n = int(input())
	lst = input()
	cnt = 0
	bruh = 0
	bruh1 = 0
	cnt1 = 0
	for x in range(n):
		if lst[x] == '1':
			cnt += 1
			bruh += max(0, cnt1 - 1)
			cnt1 = 0
		else:
			bruh1 += max(0, cnt - 1)
			cnt = 0
			cnt1 += 1
	print(max(bruh, bruh1))


R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n,) = R()
	s = input()
	print(n // 2 - max(s.count('10'), s.count('01')))


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	s = input().strip()
	s1 = '1' + s + '0'
	s2 = '0' + s + '1'
	cnt1 = cnt2 = 0
	for i in range(n + 1):
		if s1[i] == s1[i + 1]:
			cnt1 += 1
		if s2[i] == s2[i + 1]:
			cnt2 += 1
	return min(cnt1 // 2, cnt2 // 2)
for _ in range(int(input())):
	print(solve())


t = int(input())
for _ in range(t):
	N = int(input())
	S = input()
	i = 0
	divide = []
	while i < N:
		l = i
		while i < N - 1 and S[i] != S[i + 1]:
			i += 1
		divide.append(S[l:i + 1])
		i += 1
	print(len(divide) // 2)


game = int(input())
for i in range(game):
	n = int(input())
	l = input()
	l.split()
	count = 0
	c = 0
	for i in range(n - 1):
		if int(l[i]) == 1 and int(l[i + 1]) == 1:
			count += 1
		if int(l[i]) == 0 and int(l[i + 1]) == 0:
			c += 1
	if c != count:
		print(max(c, count))
	else:
		print(c)


from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	s = input().strip()
	res = 1
	for (a, b) in zip(s, s[1:]):
		if a == b:
			res += 1
	print(res // 2)
t = int(input())
for _ in range(t):
	solve()


for s in [*open(0)][2::2]:
	print(len(s) // 2 - len(s.replace(s[0], ' ').split()))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1]
	a = s.count('01')
	b = s.count('10')
	print(n // 2 - max(a, b))


for q in range(int(input())):
	n = int(input())
	s = input()
	res = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			res += 1
	print((res + 1) // 2)


import sys
import math
import collections

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	string = list(input())
	count = 0
	for i in range(1, n):
		if string[i] == string[i - 1]:
			count += 1
	print((count + 1) // 2)


for _ in range(int(input())):
	lent = int(input())
	string = input()
	count = 0
	if string[0] == '0' and string[lent - 1] == '1':
		for i in range(lent - 1):
			if string[i] == '0' and string[i + 1] == '0':
				count += 1
	elif string[0] == '1' and string[lent - 1] == '0':
		for i in range(lent - 1):
			if string[i] == '1' and string[i + 1] == '1':
				count += 1
	elif string[0] == '1' and string[lent - 1] == '1':
		for i in range(lent - 1):
			if string[i] == '0' and string[i + 1] == '0':
				count += 1
	elif string[0] == '0' and string[lent - 1] == '0':
		for i in range(lent - 1):
			if string[i] == '1' and string[i + 1] == '1':
				count += 1
	print(count)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	s = input()
	tot = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			tot += 1
	print((tot + 1) // 2)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	s = input().strip()
	ru = []
	ct = 1
	s += '9'
	for i in range(n):
		if s[i] != s[i + 1]:
			ru.append(ct - 1)
			ct = 1
		else:
			ct += 1
	a = b = 0
	for i in range(len(ru)):
		if i % 2:
			a += ru[i]
		else:
			b += ru[i]
	print(max(a, b))


from time import time
from random import randint

def createArray(size):
	ones = [1 for _ in range(size // 2)]
	zeroes = [0 for _ in range(size // 2)]
	arr = []
	while len(ones) > 0 or len(zeroes) > 0:
		if randint(0, 1) == 1 and len(ones) > 0:
			arr.append(ones.pop())
		elif len(zeroes) > 0:
			arr.append(zeroes.pop())
	return arr

def count(arr):
	cnt = [0, 0]
	for i in range(len(arr) - 1):
		if arr[i] == arr[i + 1]:
			cnt[arr[i]] += 1
	return cnt

def trying():
	arr = createArray(8)
	print(*arr)
	a = count(arr)
	print(a)
for case in range(int(input())):
	input()
	arr = [int(c) for c in input()]
	t = count(arr)
	print(max(t))


from sys import stdout, stdin
from collections import defaultdict, deque
import math
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = input()
	st = s.replace('10', '')
	a = len(st) // 2
	stt = s.replace('01', '')
	b = len(stt) // 2
	print(min(a, b))


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	s = data()
	t1 = t0 = 0
	for i in range(1, n):
		if s[i] == s[i - 1] == '1':
			t1 += 1
		elif s[i] == s[i - 1] == '0':
			t0 += 1
	out(max(t1, t0))


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	a = [0 for i in range(n + 1)]
	b = [0 for i in range(n + 1)]
	(a_, b_) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			b[i + 1] = 1
			if b[i]:
				b[i + 1] += b[i]
				b[i] = 0
		else:
			a[i + 1] = a[i] + 1
			if a[i]:
				a[i] = 0
	for i in range(1, n + 1):
		if a[i] > 1:
			a_ += a[i] - 1
		if b[i] > 1:
			b_ += b[i] - 1
	print(max(b_, a_))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	zeroCnt = 0
	zeroAns = 0
	for i in range(n):
		if s[i] == '0':
			zeroCnt += 1
		else:
			zeroAns += max(0, zeroCnt - 1)
			zeroCnt = 0
	zeroAns += max(0, zeroCnt - 1)
	if s[0] == s[n - 1] == '0':
		zeroAns += 1
	print(zeroAns)


t = int(input())
while t != 0:
	n = int(input())
	s = input()
	cnt = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print((cnt + 1) // 2)
	t -= 1


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for t in range(int(input())):
		n = int(input())
		s = input().rstrip()
		o = s.count('1')
		z = n - o
		io = 0
		oi = 0
		for i in range(n - 1):
			if s[i] == '0' and s[i + 1] == '1':
				oi += 1
			elif s[i] == '1' and s[i + 1] == '0':
				io += 1
		print(min(o - io, z - oi))
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()


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	s = 'z' + s
	output = 0
	for i in range(1, n):
		if s[i] == s[i + 1]:
			output = output + 1
	print(math.ceil(output / 2))


from sys import stdin, stdout

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

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	n = INI()
	S = INS()
	x = 0
	y = 0
	ans1 = 0
	ans2 = 0
	for i in range(n):
		if S[i] == '1':
			x += 1
			if y != 0:
				ans2 += y - 1
			y = 0
		else:
			y += 1
			if x != 0:
				ans1 += x - 1
			x = 0
	if x != 0:
		ans1 += x - 1
	if y != 0:
		ans2 += y - 1
	OPS(max(ans1, ans2))


t = int(input())
for i in range(t):
	n = int(input())
	s = input().strip()
	o = 0
	z = 0
	for j in range(1, n):
		if s[j] == s[j - 1]:
			if s[j] == '1':
				o = o + 1
			else:
				z = z + 1
	print(max(z, o))


T = int(input())
for _ in range(T):
	n = int(input())
	string = input()
	count1 = 0
	count2 = 0
	wrong1 = 0
	wrong2 = 0
	for i in range(len(string)):
		if i % 2 == 0:
			if string[i] == '0':
				wrong1 = 0
			elif wrong1 == 0:
				wrong1 = 1
				count1 += 1
		elif string[i] == '1':
			wrong1 = 0
		elif wrong1 == 0:
			wrong1 = 1
			count1 += 1
	for i in range(len(string)):
		if i % 2 == 0:
			if string[i] == '1':
				wrong2 = 0
			elif wrong2 == 0:
				wrong2 = 1
				count2 += 1
		elif string[i] == '0':
			wrong2 = 0
		elif wrong2 == 0:
			wrong2 = 1
			count2 += 1
	print(min(count1, count2))


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	d = int(c[0] == c[-1] == '1')
	for j in range(b - 1):
		if c[j] == c[j + 1] == '1':
			d += 1
	print(d)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	cnt = 0
	for i in range(n - 1):
		if arr[i] == arr[i + 1]:
			cnt += 1
	print(ceil(cnt / 2))


def rx():
	return [s.rstrip() for s in open(0)]

def f(w):
	c = 0
	for i in range(len(w) - 1):
		if w[i] == w[i + 1]:
			c += 1
	return (c + 1) // 2
for s in rx()[2::2]:
	print(f(s))


for _ in range(int(input())):
	n = int(input())
	s = input()
	count = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			count += 1
	ans = (count + 1) // 2
	print(ans)


numTestCases = int(input())
stringArr = []
for i in range(0, numTestCases):
	a = input()
	stringArr.append(input())

def funct(string):
	toggle1 = True
	toggle2 = True
	count1 = 0
	for i in string:
		if toggle1:
			if i == '1' and (not toggle2):
				toggle2 = True
			if i == '0' and toggle2:
				toggle2 = False
				count1 += 1
			toggle1 = False
		else:
			if i == '0' and (not toggle2):
				toggle2 = True
			if i == '1' and toggle2:
				toggle2 = False
				count1 += 1
			toggle1 = True
	toggle1 = True
	toggle2 = True
	count2 = 0
	for i in string:
		if toggle1:
			if i == '0' and (not toggle2):
				toggle2 = True
			if i == '1' and toggle2:
				toggle2 = False
				count2 += 1
			toggle1 = False
		else:
			if i == '1' and (not toggle2):
				toggle2 = True
			if i == '0' and toggle2:
				toggle2 = False
				count2 += 1
			toggle1 = True
	if count1 > count2:
		return count2
	return count1
for i in stringArr:
	print(funct(i))


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.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()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from itertools import *

def fun(arr1, arr2, n):
	count = 0
	ans = 0
	for i in range(n):
		if arr1[i] != arr2[i]:
			count += 1
		elif count > 0:
			ans += 1
			count = 0
	if count > 0:
		ans += 1
	return ans
for _ in range(ii1()):
	n = ii1()
	arr = is1()
	pair = n // 2
	first = '01' * pair
	second = '10' * pair
	a = fun(first, arr, n)
	b = fun(second, arr, n)
	print(min(a, b))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n <= 2:
		print(0)
	else:
		c = s[0]
		for i in range(n - 1):
			if c[-1] == '0':
				c = c + '1'
			else:
				c = c + '0'
		i = 0
		j = 0
		s = s + 'x'
		c = c + 'x'
		while i < n:
			if s[i] != c[i]:
				j = j + 1
				while s[i + 1] != c[i + 1]:
					i = i + 1
			i = i + 1
		print(j)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = 0
	for y in range(1, n):
		if s[y] == s[y - 1]:
			ans += 1
	print((ans + ans % 2) // 2)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	ans1 = 0
	ans2 = 0
	i = 0
	while i < n:
		c = 1
		while s[i] == s[i - 1]:
			c = c + 1
			i = i + 1
		if s[i - 1] == '1':
			ans2 = ans2 + c - 1
		else:
			ans1 = ans1 + c - 1
		i = i + 1
	print(max(ans1, ans2))


for _ in range(int(input())):
	lim = int(input())
	arr = list(input())
	count = 0
	for i in range(len(arr) - 1):
		if arr[i] == '1' and arr[i + 1] == '1':
			count += 1
	counttwo = 0
	for i in range(len(arr) - 1):
		if arr[i] == '0' and arr[i + 1] == '0':
			counttwo += 1
	print(max(count, counttwo))


t = int(input())
for _ in range(t):
	(n, s) = (int(input()), input())
	c = sum((1 for i in range(n - 1) if s[i] == s[i + 1]))
	print((c + 1) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	l = input()
	x = l.count('01') + l.count('10')
	print((n - x) // 2)


import sys
import os
import math
import copy
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations, accumulate

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

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

def btod(n):
	return int(n, 2)

def watch(x):
	return print(x)

def common(l1, l2):
	return set(l1).intersection(l2)

def Most_frequent(list):
	return max(set(list), key=list.count)

def solution():
	for _ in range(Int()):
		n = Int()
		a = Str()
		o = 0
		z = 0
		for i in range(n - 1):
			if a[i] == a[i + 1] and a[i] == '0':
				z += 1
			elif a[i] == a[i + 1] and a[i] == '1':
				o += 1
		print(max(z, o))
solution()


from sys import stdin, stdout
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	cnt = 0
	cnt0 = 0
	for i in range(0, n - 1):
		if s[i] == '1' and s[i] == s[i + 1]:
			cnt = cnt + 1
		if s[i] == '0' and s[i] == s[i + 1]:
			cnt0 = cnt0 + 1
	print(max(cnt, cnt0))


for _ in range(int(input())):
	n = int(input())
	s = input()
	anss = 0
	l = ''
	for i in range(n):
		if i % 2 == 0:
			l += '1'
		else:
			l += '0'
	(i, j) = (0, 0)
	f = 0
	while i < n:
		if s[i] != l[j]:
			f = 1
		else:
			if f == 1:
				anss += 1
			f = 0
			temp = 0
		i += 1
		j += 1
	if f == 1:
		anss += 1
	ans = 0
	l = ''
	for i in range(n):
		if i % 2 == 0:
			l += '0'
		else:
			l += '1'
	(i, j) = (0, 0)
	f = 0
	while i < n:
		if s[i] != l[j]:
			f = 1
		else:
			if f == 1:
				ans += 1
			f = 0
		i += 1
		j += 1
	if f == 1:
		ans += 1
	print(min(ans, anss))


def solve(n, s):
	l = 0
	r = n - 1
	s = list(s)
	moves = 0
	need = n // 2
	if s[0] == '0':
		have = 0
		for i in range(n - 1):
			if s[i] == '0' and s[i + 1] == '1':
				have += 1
		return need - have
	if s[0] == '1':
		have = 0
		for i in range(n - 1):
			if s[i] == '1' and s[i + 1] == '0':
				have += 1
		return need - have
t = int(input())
while t:
	n = int(input())
	s = input()
	print(solve(n, s))
	t -= 1


for nt in range(int(input())):
	n = int(input())
	s = input()
	(o, z) = (0, 0)
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			z += 1
		if s[i] == '1' and s[i + 1] == '1':
			o += 1
	print(max(o, z))


t = int(input())
n = 0
s = ''
l = []
count = 0
top = 0
for i in range(t):
	n = int(input())
	s = input()
	count1 = 0
	count0 = 0
	max1 = 0
	top = 0
	for j in range(1, n):
		if s[j] == s[top]:
			if s[j] == '1':
				count1 += 1
			else:
				count0 += 1
		else:
			top = j
	if count0 >= count1:
		print(count0)
	else:
		print(count1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 0
	ans = 0
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			if cnt >= 1:
				ans += cnt - 1
			cnt = 0
	if s[-1] == '1':
		ans += cnt - 1
	cnt = 0
	ans1 = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			if cnt >= 1:
				ans1 += cnt - 1
			cnt = 0
	if s[-1] == '0':
		ans1 += cnt - 1
	print(max(ans, ans1))


t = int(input())
for q in range(t):
	n = int(input())
	ch = input()
	L1 = ch.split('0')
	L2 = ch.split('1')
	nb1 = nb2 = 0
	for i in L1:
		if len(i) > 0:
			nb1 += len(i) - 1
	for i in L2:
		if len(i) > 0:
			nb2 += len(i) - 1
	print(max(nb1, nb2))


for __ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			ans += 1
	print((ans + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	ss = 0
	while i < n:
		if s[i] == '1':
			i += 1
			while i < n and s[i] == '1':
				ss += 1
				i += 1
		i += 1
	if s[0] == s[-1] == '1':
		ss += 1
	print(ss)


from sys import stdin, stdout
from collections import *
from math import *
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	s = st()
	ans = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			ans += 1
	pr(ceil(ans / 2))
for _ in range(inp()):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	c1 = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			if s[i] == '0':
				c += 1
			else:
				c1 += 1
	print(max(c, c1))


t = int(input())
for i in range(t):
	k0 = 0
	k1 = 0
	i = 1
	j = 1
	n = int(input())
	s = input()
	s1 = s
	while i != -1:
		i = s.find('00')
		if i >= 0:
			k0 += 1
		s = s[i + 1:]
	while j != -1:
		j = s1.find('11')
		if j >= 0:
			k1 += 1
		s1 = s1[j + 1:]
	print(max(k0, k1))


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = stdin.readline()
	count = 0
	count0 = 0
	for i in range(n - 1):
		if arr[i] == arr[i + 1]:
			if arr[i] == '0':
				count0 += 1
			else:
				count += 1
	print(max(count, count0))


for _ in range(int(input())):
	a = int(input())
	b = input()
	k = b.split('0')
	t = b.split('1')
	fs = ze = 0
	for i in k:
		if len(i):
			fs += len(i) - 1
	for j in t:
		if len(j):
			ze += len(j) - 1
	print(max(fs, ze))


N = int(input())
for i in range(N):
	n = int(input())
	one = 0
	zero = 0
	s = input()
	for j in range(1, n):
		if s[j] == '1' and s[j - 1] == '1':
			one += 1
		elif s[j] == '0' and s[j - 1] == '0':
			zero += 1
	print(max(one, zero))


test = int(input())
for t in range(test):
	n = int(input())
	s = input()
	s = '-' + s + '-'
	l1 = []
	l2 = []
	i = 0
	while i <= n:
		if s[i] == '1':
			ans = 1
			while 1:
				i += 1
				if s[i] != '1':
					break
				ans += 1
			if ans:
				l1.append(ans)
		i += 1
	cx = 0
	for x in l1:
		cx += x - 1
	i = 0
	while i <= n:
		if s[i] == '0':
			ansz = 1
			while 1:
				i += 1
				if s[i] != '0':
					break
				ansz += 1
			if ansz:
				l2.append(ansz)
		i += 1
	cy = 0
	for x in l2:
		cy += x - 1
	print(max(cx, cy))


t = int(input())
for _ in range(t):
	n = int(input())
	s = [i for i in input().strip()]
	targ1 = '10' * (n // 2) + '1' * (n % 2)
	targ2 = '01' * (n // 2) + '0' * (n % 2)
	ct1 = 0
	ct2 = 0
	i = 0
	while i < n:
		j = i + 1
		if s[i] != targ1[i]:
			while j < n and s[j] != targ1[j]:
				j += 1
			ct1 += 1
		i = j
	i = 0
	while i < n:
		j = i + 1
		if s[i] != targ2[i]:
			while j < n and s[j] != targ2[j]:
				j += 1
			ct2 += 1
		i = j
	print(min(ct1, ct2))


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().rstrip()))
	one_st = []
	for i in range(n):
		if arr[i]:
			one_st.append((1, i))
		elif one_st and one_st[-1][1] == i - 1:
			one_st.pop()
	zero_st = []
	for i in range(n):
		if not arr[i]:
			zero_st.append((0, i))
		elif zero_st and zero_st[-1][1] == i - 1:
			zero_st.pop()
	print(min(len(zero_st), len(one_st)))


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))
import math

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math as M
MOD = 10 ** 9 + 7
from random import randint as R
for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	(q, k) = (0, 0)
	(er, pr) = (0, 0)
	while i < n:
		if s[i] == '0':
			k = 0
			while i < n and s[i] == '0' and (i < n):
				k += 1
				i += 1
			er += k - 1
		else:
			i += 1
	j = 0
	while j < n:
		if s[j] == '1':
			q = 0
			while j < n and s[j] == '1' and (j < n):
				q += 1
				j += 1
			pr += q - 1
		else:
			j += 1
	print(max(pr, er))


MOD = 1000000007
from collections import defaultdict as dd, Counter, deque

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 out(v):
	print(v)

def spout():
	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)
t = ii()
while t:
	t -= 1
	n = ii()
	a = si()
	c1 = c2 = 0
	zer = list(map(len, a.split('1')))
	one = list(map(len, a.split('0')))
	for i in range(len(zer)):
		if zer[i] > 0:
			c1 += zer[i] - 1
		if one[i] > 0:
			c2 += one[i] - 1
	print(max(c1, c2))


import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

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

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

def listt():
	return [int(i) for i in inputt().split()]

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

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

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True

def maxpower(n, x):
	B_max = int(math.log(n, x)) + 1
	return B_max
from itertools import groupby
t = int(inputt())
for _ in range(t):
	n = int(inputt())
	s = inputt()
	count = 0
	l1 = []
	l0 = []
	groups = groupby(s)
	result = [(label, sum((1 for _ in group))) for (label, group) in groups]
	for (i, j) in result:
		if i == '1':
			l1.append(j)
		else:
			l0.append(j)
	s1 = sum(l1) - len(l1)
	s2 = sum(l0) - len(l0)
	print(max(s1, s2))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = []
	for j in s:
		b.append(int(j))
	j = 0
	res1 = 0
	res2 = 0
	while j < n - 1:
		if b[j] == 0 and b[j + 1] == 0:
			res1 += 1
		elif b[j] == 1 and b[j + 1] == 1:
			res2 += 1
		j += 1
	print(max(res1, res2))


import math
for i in range(int(input())):
	n = int(input())
	st = input()
	l = len(st)
	s1 = []
	s2 = []
	s3 = []
	m = 1
	c = 0
	for j in range(2, l + 1):
		if st[j - 2] == st[j - 1]:
			c += 1
	print(math.ceil(c / 2))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	ans = 0
	a = []
	for i in range(n):
		if s[i] == '1':
			ans += 1
			if i == n - 1 and ans > 1:
				a.append(ans)
		if s[i] == '0':
			if ans != 0 and ans != 1:
				a.append(ans)
			ans = 0
	ans1 = sum(a) - len(a)
	ans = 0
	b = []
	for i in range(n):
		if s[i] == '0':
			ans += 1
			if i == n - 1 and ans > 1:
				b.append(ans)
		if s[i] == '1':
			if ans != 0 and ans != 1:
				b.append(ans)
			ans = 0
	ans2 = sum(b) - len(b)
	print(max(ans1, ans2))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	l = list(s)
	ans = 0
	for i in range(n):
		ans += l[i] == l[(i + 1) % n]
	print(ans // 2)


import sys
tc = int(sys.stdin.readline().strip())
for test in range(tc):
	n = int(sys.stdin.readline().strip())
	string = list(sys.stdin.readline().strip())
	zero_result = 0
	one_result = 0
	for bit in range(n - 1):
		if string[bit] != string[bit + 1]:
			continue
		if string[bit] == '1':
			one_result += 1
		else:
			zero_result += 1
	print(max(one_result, zero_result))


def solve(s):
	ans = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			ans += 1
	return ans // 2
for t in range(int(input())):
	n = int(input())
	s = input()
	if n <= 2:
		print('0')
	else:
		s1 = '1' + s + '0'
		s2 = '0' + s + '1'
		print(min(solve(s1), solve(s2)))


def main():
	n = int(input())
	s = input()
	ch1 = 0
	ch0 = 0
	f10 = 0
	t = [0] * n
	for i in range(n):
		if s[i] == '1' and i % 2 == 0:
			t[i] = 1
		if s[i] == '0' and i % 2 == 1:
			t[i] = 1
	if t[0] == 0:
		for i in range(1, n):
			if t[i] == 1 and t[i - 1] == 0:
				f10 += 1
	else:
		for i in range(1, n):
			if t[i] == 0 and t[i - 1] == 1:
				f10 += 1
	print(f10)
rw = int(input())
for wewq in range(rw):
	main()


for i in range(int(input())):
	n = int(input())
	s = input()
	c1 = 0
	c0 = 0
	j = 0
	while j < n - 1:
		if s[j] == s[j + 1] and s[j] == '0':
			c0 += 1
		elif s[j] == s[j + 1] and s[j] == '1':
			c1 += 1
		j += 1
	print(max(c0, c1))


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))
(t,) = I()
for t1 in range(t):
	(n,) = I()
	s = list(str(input()))
	one_count = 0
	zero_count = 0
	for i in range(len(s)):
		if i == 0:
			prev = s[i]
		elif prev == s[i]:
			if prev == '1':
				one_count = one_count + 1
			else:
				zero_count = zero_count + 1
		else:
			prev = s[i]
	print(max(one_count, zero_count))


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, list(input())))
	m = 99999999
	for g in range(2):
		tot = 0
		i = 0
		while i < n:
			fl = False
			while arr[i] != (i % 2 + g % 2) % 2:
				fl = True
				i += 1
				if i == n:
					break
			if fl:
				tot += 1
			i += 1
		m = min(tot, m)
	print(m)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	v1 = 0
	v2 = 0
	p = 0
	for i in range(len(s)):
		if int(s[i]) != i % 2:
			p += 1
		else:
			v1 += int(p > 0)
			p = 0
	v1 += int(p > 0)
	p = 0
	for i in range(len(s)):
		if int(s[i]) == i % 2:
			p += 1
		else:
			v2 += int(p > 0)
			p = 0
	v2 += int(p > 0)
	print(min(v1, v2))


import sys

def solve(S):
	zero_pairs = 0
	one_pairs = 0
	for (a, b) in zip(S[:-1], S[1:]):
		if a == b:
			if a == '0':
				zero_pairs += 1
			else:
				one_pairs += 1
	return max(zero_pairs, one_pairs)

def main():
	test_cases = int(sys.stdin.readline())
	for _ in range(test_cases):
		N = int(sys.stdin.readline())
		S = sys.stdin.readline().strip()
		print(solve(S))
main()


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	p1 = []
	p2 = []
	for i in range(n // 2):
		p1.append(0)
		p1.append(1)
		p2.append(1)
		p2.append(0)
	um1 = []
	um2 = []
	for i in range(n):
		if s[i] != p1[i]:
			um1.append(i)
		if s[i] != p2[i]:
			um2.append(i)
	c1 = 1
	c2 = 1
	for i in range(len(um1) - 1):
		if um1[i] + 1 == um1[i + 1]:
			do = 1
		else:
			c1 += 1
	for i in range(len(um2) - 1):
		if um2[i] + 1 == um2[i + 1]:
			do = 1
		else:
			c2 += 1
	if s == p1 or s == p2:
		c1 = 0
	print(min(c1, c2))


from sys import stdin
input = stdin.readline
T = int(input())
for Case in range(T):
	n = int(input())
	s = input()
	cnt = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			cnt += 1
	print((cnt + 1) // 2)


import sys, collections
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	vals = list(input().strip())
	ans = 0
	for i in range(n - 1):
		if vals[i] == vals[i + 1]:
			ans += 1
	print((ans + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	o = s.count('10')
	z = s.count('01')
	r = n // 2
	print(r - max(o, z))


t = int(input())
for case in range(t):
	n = int(input())
	s = input()
	z = 0
	o = 0
	last_ch = None
	for x in s:
		if x == last_ch:
			if x == '0':
				z += 1
			else:
				o += 1
		else:
			last_ch = x
	print(max(o, z))


import os
import sys
from io import BytesIO, IOBase
import math
from itertools import permutations
from decimal import Decimal, getcontext
getcontext().prec = 25
MOD = pow(10, 9) + 7
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')
for _ in range(int(input())):
	z = []
	o = []
	n = int(input())
	a = input()
	l = 0
	for i in range(n):
		if a[i] == '1':
			l += 1
		else:
			if l:
				z.append(l)
			l = 0
	if l:
		z.append(l)
	l = 0
	for i in range(n):
		if a[i] == '0':
			l += 1
		else:
			if l:
				o.append(l)
			l = 0
	if l:
		o.append(l)
	ans = 0
	for i in z:
		if i > 1:
			ans += i - 1
	ans1 = 0
	for i in o:
		if i > 1:
			ans1 += i - 1
	print(max(ans, ans1))


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	(o, z) = (0, 0)
	t = ''
	while i < n:
		if t == '':
			t += s[i]
		elif s[i] == t[-1]:
			t += s[i]
		else:
			if t[-1] == '1':
				o += len(t) - 1
			else:
				z += len(t) - 1
			t = s[i]
		i += 1
	if len(t) != 0:
		if t[-1] == '1':
			o += len(t) - 1
		else:
			z += len(t) - 1
	print(max(o, z))


cs = int(input())
for i in range(cs):
	n = int(input())
	s = input()
	fz = int(0)
	sum1 = int(0)
	sum2 = int(0)
	for j in range(n):
		if s[j] == '0':
			fz += 1
		else:
			if fz > 0:
				sum1 += fz - 1
			fz = 0
	fz = 0
	for j in range(n):
		if s[j] == '1':
			fz += 1
		else:
			if fz > 0:
				sum2 += fz - 1
			fz = 0
	print(max(sum1, sum2), end='')
	if i != cs - 1:
		print()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for _ in range(ii()):
		n = ii()
		s = input()
		m = 0
		for i in range(1, n, 1):
			if s[i] == s[i - 1]:
				m += 1
		print((m + 1) // 2)
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	y = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '1':
				x += 1
			else:
				y += 1
	print(max(x, y))


for _ in range(int(input())):
	n = int(input())
	s = input()
	prev = 0
	maxm = 0
	count = 0
	for i in s:
		if i == '1':
			maxm += 1
		else:
			prev = maxm
			maxm = 0
		if prev > 1:
			count += prev - 1
			prev = 0
	counti = 0
	maxm = 0
	prev = 0
	for i in s:
		if i == '0':
			maxm += 1
		else:
			prev = maxm
			maxm = 0
		if prev > 1:
			counti += prev - 1
			prev = 0
	print(max(count, counti))


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	s = input()
	res1 = res2 = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '0':
				res1 += 1
			else:
				res2 += 1
	print(max(res1, res2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	a1 = [i for i in s.split('0') if i != '']
	a2 = [i for i in s.split('1') if i != '']
	print(max(sum((len(i) - 1 for i in a1)), sum((len(i) - 1 for i in a2))))


test_cases = int(input())
for _ in range(test_cases):
	lenght = int(input())
	bin_string = input()
	num_10 = bin_string.count('10')
	num_01 = bin_string.count('01')
	aux = lenght - num_10 - num_01
	print(aux // 2)


for _ in range(int(input())):
	n = int(input())
	A = input()
	count = 0
	sum1 = 0
	for i in range(n - 1):
		if A[i] == A[i + 1] == '1':
			count += 1
		else:
			sum1 += count
			count = 0
	count = 0
	sum2 = 0
	for i in range(n - 1):
		if A[i] == A[i + 1] == '0':
			count += 1
		else:
			sum2 += count
			count = 0
	if sum2 > sum1:
		print(sum2)
	else:
		print(sum1)


import math
from collections import defaultdict

class Solution:

	def __init__(self):
		pass

	def run(self):
		n = int(input())
		s = input()
		ones = 0
		zeros = 0
		for i in range(1, len(s)):
			if s[i] == '1' and s[i - 1] == '1':
				ones += 1
			elif s[i] == '0' and s[i - 1] == '0':
				zeros += 1
		return max(ones, zeros)
t = int(input())
s = Solution()
for i in range(t):
	print(s.run())


def solve():
	n = int(input())
	s = input()
	que1 = []
	que2 = []
	for i in range(n):
		if i % 2 == 0 and s[i] == '0':
			que1.append(i)
		if i % 2 != 0 and s[i] == '1':
			que1.append(i)
	ans1 = 1
	if len(que1) == 0:
		ans1 = 0
	for i in range(len(que1) - 1):
		if que1[i] + 1 < que1[i + 1]:
			ans1 += 1
	for i in range(n):
		if i % 2 != 0 and s[i] == '0':
			que2.append(i)
		if i % 2 == 0 and s[i] == '1':
			que2.append(i)
	ans2 = 1
	if len(que2) == 0:
		ans2 = 0
	for i in range(len(que2) - 1):
		if que2[i] + 1 < que2[i + 1]:
			ans2 += 1
	ans = min(ans1, ans2)
	print(ans)
	return

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


for _ in range(int(input())):
	x = int(input())
	z = input()
	count = 0
	for a in range(len(z)):
		if z[a] == z[a - 1] == '1':
			count += 1
	print(count)


import sys
sys.setrecursionlimit(10 ** 5 + 5)
from collections import defaultdict as dft, deque

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

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

def solve():
	n = int(input())
	s = input()
	st = []
	ch = '10' * (n // 2)
	l = -1
	r = -1
	for i in range(n):
		if ch[i] != s[i]:
			if l != -1:
				r = i
			else:
				l = i
				r = i
		elif l != -1:
			st.append([l, r])
			l = -1
	if l != -1:
		st.append([l, r])
	mn = len(st)
	ch = '01' * (n // 2)
	st = []
	l = -1
	r = -1
	for i in range(n):
		if ch[i] != s[i]:
			if l != -1:
				r = i
			else:
				l = i
				r = i
		elif l != -1:
			st.append([l, r])
			l = -1
	if l != -1:
		st.append([l, r])
	mn1 = len(st)
	print(min(mn, mn1))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	st = input()
	count = 0
	for i in range(n - 1):
		if st[i] == st[i + 1]:
			count += 1
	count += 1
	print(count // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	S = 0
	for j in range(1, len(s)):
		if s[j - 1] == '1' and s[j] == '1':
			S += 1
	if s[0] == '1' and s[-1] == '1' and (len(s) > 2):
		S += 1
	print(S)


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	l = int(input())
	s = input()
	v = -1
	(t1, t0) = (0, 0)
	for i in range(len(s)):
		if s[i] == v and s[i] == '1':
			t1 += 1
		elif s[i] == v and s[i] == '0':
			t0 += 1
		else:
			v = s[i]
	print(max(t1, t0))


t = int(input())
for i in range(t):
	totalLen = int(input())
	totalList = list(map(int, list(input())))
	start = 1
	c = 0
	prev = 0
	for i in totalList:
		if i == start:
			if prev != 0:
				c += 1
				prev = 0
		else:
			prev += 1
		if start == 1:
			start = 0
		else:
			start = 1
	if prev != 0:
		c += 1
	start1 = 0
	c1 = 0
	prev = 0
	for i in totalList:
		if i == start1:
			if prev != 0:
				c1 += 1
				prev = 0
		else:
			prev += 1
		if start1 == 1:
			start1 = 0
		else:
			start1 = 1
	if prev != 0:
		c1 += 1
	print(min(c, c1))


def readGenerator():
	while True:
		tokens = input().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def solve(s, n):
	k = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			k += 1
	return (k + 1) // 2
t = readInt()
for _ in range(t):
	n = readInt()
	s = readLine()
	print(solve(s, n))


for x in range(int(input())):
	n = int(input())
	k = str(input())
	cnt = 0
	for i in range(1, n, 1):
		if k[i] == k[i - 1]:
			cnt += 1
	print(int((cnt + 1) / 2))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = 0
	d = 0
	x = 1
	a = '01' * (n // 2)
	b = '10' * (n // 2)
	for i in range(n - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			c += 1
		if s[i] == s[i + 1] and s[i] == '0':
			d += 1
	if c == 0 and d == 0:
		print(0)
	elif c == 0:
		print(d)
	elif d == 0:
		print(c)
	else:
		print(max(c, d))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		inputString = input()
		zCont = 0
		oCont = 0
		for i in range(n - 1):
			if inputString[i] == inputString[i + 1]:
				if inputString[i] == '0':
					zCont += 1
				else:
					oCont += 1
		yield max(zCont, oCont)
t = int(input())
ans = gift()
print(*ans, sep='\n')


import io, os
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, namedtuple
from math import gcd, ceil, floor, factorial
from itertools import combinations, permutations
input = sys.stdin.readline

def work(n, s, pat):
	t = 0
	ans = 0
	for i in range(n):
		if s[i] != pat[i]:
			t += 1
		else:
			ans += min(1, t)
			t = 0
	ans += min(1, t)
	return ans

def main():
	test = int(input())
	for idt in range(test):
		n = int(input())
		s = input().strip('\r\n')
		pat1 = '01' * (n // 2)
		pat2 = '10' * (n // 2)
		t1 = work(n, s, pat1)
		t2 = work(n, s, pat2)
		print(min(t1, t2))
	return
main()


from sys import stdin
_input = stdin.readline
(_range, _max, _int, _str) = (range, max, int, str)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = _input().rstrip('\n')
		zero = 0
		one = 0
		old = arr[0]
		current = 0
		for i in _range(1, n):
			if arr[i] == old:
				current += 1
			else:
				if old == '0':
					zero += current
				if old == '1':
					one += current
				current = 0
			old = arr[i]
		if old == '0' and zero < current:
			zero = current
		if old == '1' and one < current:
			one = current
		print(_max(zero, one))
solution()


t = int(input())
for j in range(t):
	ans1 = 0
	ans2 = 0
	n = int(input())
	s = input()
	cnt = 0
	for i in range(0, n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
		else:
			if s[i] == '1':
				ans1 += cnt
			else:
				ans2 += cnt
			cnt = 0
	print(max(ans1, ans2))


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	c0 = 0
	c1 = 0
	for i in range(1, n):
		if s[i - 1] == '0' and s[i] == '0':
			c0 += 1
		if s[i - 1] == '1' and s[i] == '1':
			c1 += 1
	print(max(c0, c1))


from sys import stdin, stdout

def main():
	for __ in range(int(stdin.readline().strip())):
		n = int(stdin.readline().strip())
		A = stdin.readline().strip()
		c = A[0]
		balance = [(A[0], 0)]
		for j in range(1, n):
			if A[j] == c:
				balance.append((A[j], j))
			elif balance:
				if balance[-1][0] != A[j] and j - balance[-1][-1] == 1:
					balance.pop()
				else:
					balance.append((A[j], j))
			else:
				balance.append((A[j], j))
		print(len(balance) // 2)
main()


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	s = input().strip()
	c = 0
	for i in range(n):
		if s[i] == '1' and s[i] == s[i - 1]:
			c += 1
	print(c)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	s = list(SI())
	m = 0
	temp = 1
	ans = []
	ans2 = []
	for i in range(1, n):
		if s[i] == s[i - 1]:
			temp += 1
		else:
			if s[i - 1] == '1':
				ans.append(temp - 1)
			else:
				ans2.append(temp - 1)
			temp = 1
	if s[-1] == '1':
		ans.append(temp - 1)
	else:
		ans2.append(temp - 1)
	print(max(sum(ans2), sum(ans)))


import math
for t in range(int(input())):
	n = int(input())
	a = input()
	count = 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			count += 1
	print(math.ceil(count / 2))


import os
import sys
from io import BytesIO, IOBase
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()

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	s = input().strip()
	r1 = 0
	r2 = 0
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			r1 += 1
		elif s[i] == '0' and s[i - 1] == '0':
			r2 += 1
	print(max(r1, r2))


t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	s = input()
	x = 0
	for j in range(n):
		if s[j] == s[j - 1]:
			x += 1
	answers.append(int(x / 2))
for i in range(t):
	print(answers[i])


def conta0(s):
	i = 0
	c = 0
	while i < len(s) - 1:
		if s[i] == s[i + 1]:
			c += 1
		i += 1
	return c / 2
t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	s0 = '0' + s + '1'
	s1 = '1' + s + '0'
	if conta0(s0) < conta0(s1):
		print(int(conta0(s0)))
	else:
		print(int(conta0(s1)))


t = int(input())
for i in range(0, t):
	x = int(input())
	str1 = input()
	ot = 0
	onet = 0
	for j in range(1, x):
		if str1[j] == str1[j - 1]:
			if str1[j] == '0':
				ot += 1
			else:
				onet += 1
	z = max(ot, onet)
	print(z)


D = ['0', '1']

def p1(S):
	N = len(S)
	ans = i = 0
	while i < N:
		while i < N and S[i] == D[i % 2]:
			i += 1
		if i < N:
			ans += 1
		while i < N and S[i] == D[1 - i % 2]:
			i += 1
	return ans

def p2(S):
	N = len(S)
	ans = i = 0
	while i < N:
		while i < N and S[i] == D[1 - i % 2]:
			i += 1
		if i < N:
			ans += 1
		while i < N and S[i] == D[i % 2]:
			i += 1
	return ans
for _ in range(int(input())):
	input()
	S = input()
	print(min(p1(S), p2(S)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	i = 0
	c = 0
	ans1 = 0
	while i < n:
		if a[i] == '1':
			c += 1
		elif c > 0:
			ans1 += c - 1
			c = 0
		i += 1
	if c > 0:
		ans1 += c - 1
	if a[0] == '1' and a[len(a) - 1] == '1':
		print(ans1 + 1)
	else:
		print(ans1)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for j in range(t):
	n = II()
	s = SI()
	m = 0
	cnt = 0
	for j in range(1, n):
		if s[j] == s[j - 1] and s[j] == '1':
			cnt += 1
		else:
			m = m + cnt
			cnt = 0
	m = m + cnt
	m1 = 0
	cnt1 = 0
	for j in range(1, n):
		if s[j] == s[j - 1] and s[j] == '0':
			cnt1 += 1
		else:
			m1 = m1 + cnt1
			cnt1 = 0
	m1 = m1 + cnt1
	print(max(m, m1))


for _ in range(int(input())):
	n = int(input())
	s = input()
	c1 = 0
	c2 = 0
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			c1 += 1
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			c2 += 1
	print(max(c1, c2))


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

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

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

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

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(getN()):
	n = getN()
	s = input()
	z_o = s.count('01')
	o_z = s.count('10')
	print(min((n - z_o * 2) // 2, (n - o_z * 2) // 2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = s[0]
	count = 0
	for i in range(n - 1):
		if s[i] == s[i + 1] and s[i] == x:
			count += 1
	if s[0] == s[n - 1]:
		count += 1
	print(count)


import sys
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n,) = I()
	s = input().strip()
	cnt = 1
	st = s[0]
	temp = []
	for i in s[1:]:
		if i == st:
			cnt += 1
		else:
			temp.append(cnt)
			st = i
			cnt = 1
	if cnt:
		temp.append(cnt)
	od = ev = 0
	for i in range(len(temp)):
		temp[i] -= 1
		if i % 2:
			od += temp[i]
		else:
			ev += temp[i]
	print(max(od, ev))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	s1 = []
	s2 = []
	count = 0
	for i in s:
		if len(s1) == 0 or i != s1[-1]:
			s1.append(i)
		elif len(s2) != 0 and i != s2[-1]:
			s1.append(s2.pop())
			s1.append(i)
		else:
			s2.append(i)
			count += 1
	print(count)


t = int(input())
for i in range(t):
	l = int(input())
	st = input()
	st1 = '01'
	st2 = '10'
	for j in range(2, l, 2):
		st1 = st1 + '01'
		st2 = st2 + '10'
	d1 = 0
	flg = 0
	for k in range(l):
		if flg == 1 and st[k] == st1[k]:
			d1 = d1 + 1
			flg = 0
		elif st[k] != st1[k]:
			flg = 1
	if flg == 1:
		d1 = d1 + 1
	flg = 0
	d2 = 0
	for m in range(l):
		if flg == 1 and st[m] == st2[m]:
			d2 = d2 + 1
			flg = 0
		elif st[m] != st2[m]:
			flg = 1
	if flg == 1:
		d2 = d2 + 1
	print(min(d1, d2))


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print(math.ceil(cnt / 2))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

def ria():
	return list(map(int, sys.stdin.readline().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')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		s = rs()
		nop = n // 2
		s1 = '01'
		s2 = '10'
		ns1 = 0
		ns2 = 0
		for i in range(n - 1):
			if s[i] + s[i + 1] == s1:
				ns1 += 1
			if s[i] + s[i + 1] == s2:
				ns2 += 1
		nopihave = max(ns1, ns2)
		bachein = nop - nopihave
		print(bachein)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import itertools
import math
import sys
import os
from collections import defaultdict

def is_debug():
	return 'PYPY3_HOME' not in os.environ

def stdin_wrapper():
	data = '3\n2\n10\n4\n0110\n8\n11101000\n\n'
	for line in data.split('\n'):
		yield line
if not is_debug():

	def stdin_wrapper():
		while True:
			yield sys.stdin.readline()
inputs = stdin_wrapper()

def input_wrapper():
	return next(inputs)

def get_str():
	if is_debug():
		return input_wrapper()
	return input()

def get(_type):
	if _type == str:
		return get_str()
	return _type(input_wrapper())

def get_arr(_type):
	return [_type(x) for x in input_wrapper().split()]

def tuplerize(method):

	def wrap(*args, **kwargs):
		res = method(*args, **kwargs)
		if not isinstance(res, (tuple, list)):
			res = (res,)
		return res
	return wrap

@tuplerize
def solve(s):
	return max(sum([len(x) - 1 for x in s.split('0') if len(x) > 1]), sum([len(x) - 1 for x in s.split('1') if len(x) > 1]))
t = get(int)
for _ in range(t):
	n = get(int)
	s = get_str()
	print(*solve(s))


import os
import sys
from io import BytesIO, IOBase
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 gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	s = input()
	start = s[0]
	ans = 0
	cur = 0
	for i in range(1, len(s)):
		if int(s[i]) % 2 != (int(start) + i) % 2:
			cur += 1
		else:
			if cur:
				ans += 1
			cur = 0
	if cur:
		ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = s.split('0')
	s2 = s.split('1')
	counter = 0
	for s_i in s1:
		counter += len(s_i) - 1 if len(s_i) > 1 else 0
	counter2 = 0
	for s_i in s2:
		counter2 += len(s_i) - 1 if len(s_i) > 1 else 0
	print(max(counter, counter2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	(contiguous1, sub1, contiguous0, sub0) = (0, 0, 0, 0)
	for i in range(1, n):
		if s[i] == '1' and s[i] == s[i - 1]:
			sub1 += 1
			contiguous0 += sub0
			sub0 = 0
		if s[i] == '0' and s[i] == s[i - 1]:
			sub0 += 1
			contiguous1 += sub1
			sub1 = 0
		else:
			contiguous1 += sub1
			contiguous0 += sub0
			sub0 = 0
			sub1 = 0
	print(max(contiguous1, contiguous0))


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans1 = 0
	ans2 = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '0':
				ans1 += 1
			else:
				ans2 += 1
	print(max(ans1, ans2))


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	same_chars = 0
	prev = s[0]
	for i in s[1:]:
		if i == prev:
			same_chars += 1
		prev = i
	print(math.ceil(same_chars / 2))


import sys
import math
input = sys.stdin.readline
t = int(input())
for w in range(t):
	n = int(input())
	s = list(input())
	l1 = []
	c = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			l1.append(c)
			c = 1
		else:
			c += 1
	l1.append(c)
	(k1, k2) = (0, 0)
	for i in range(len(l1)):
		if i % 2 == 0:
			k1 += l1[i] - 1
		else:
			k2 += l1[i] - 1
	print(max(k1, k2))


import math
import heapq
x = 120983019283
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	c = 0
	c1 = 0
	ans1 = 0
	for i in range(1, n):
		if s[i] == s[i - 1] == '1':
			c += 1
		else:
			ans += c
			c = 0
		if s[i] == s[i - 1] == '0':
			c1 += 1
		else:
			ans1 += c1
			c1 = 0
	if c1 > 0:
		ans1 += c1
	if c > 0:
		ans += c
	print(max(ans, ans1))


def check1(num):
	if num % 2 == 0:
		return '1'
	return '0'
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans1 = 0
	ans2 = 0
	temp = 0
	for i in range(n):
		if s[i] == '1':
			temp += 1
		else:
			if temp:
				ans1 += temp - 1
			temp = 0
	if temp:
		ans1 += temp - 1
	temp = 0
	for i in range(n):
		if s[i] == '0':
			temp += 1
		else:
			if temp:
				ans2 += temp - 1
			temp = 0
	if temp:
		ans2 += temp - 1
	print(max(ans1, ans2))


for _ in range(int(input())):
	n = int(input())
	s = list(str(input()))
	count = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			count += 1
	if count % 2 == 1:
		print(count // 2 + 1)
	else:
		print(count // 2)


for _ in range(int(input())):
	n = int(input())
	l = input()
	c = 0
	pre = ''
	for ele in l:
		if ele == '1' and pre == '1':
			c += 1
			pre = ele
		if ele == '0' and pre == '0':
			c += 1
			pre = ele
		else:
			pre = ele
	print((c + 1) // 2)


def countOne(s):
	c = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			c += 1
	return c

def countZero(s):
	c = 0
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i + 1] == '0':
			c += 1
	return c
for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 2:
		print(0)
	else:
		one = countOne(s)
		zero = countZero(s)
		if one > 0 or zero > 0:
			print(max(zero, one))
		else:
			print(0)


t = int(input())

def doWork(a):
	m = 0
	for i in range(1, len(a)):
		if int(a[i - 1]) == int(a[i]):
			m += 1
	if m % 2 == 0:
		return int(m / 2)
	else:
		return int((m + 1) / 2)
for i in range(t):
	n = int(input())
	a = input()
	print(doWork(a))


t = int(input())
for case in range(t):
	n = int(input())
	s = input()
	zeros = 0
	ones = 0
	for i in range(1, len(s)):
		if s[i] == '0' and s[i - 1] == '0':
			zeros += 1
		if s[i] == '1' and s[i - 1] == '1':
			ones += 1
	print(max(zeros, ones))


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = [0] * T
for t in range(T):
	N = int(input())
	S = input()
	T = [0] * N
	for i in range(N):
		T[i] = S[i] == str(i % 2)
	cnt = 1
	for i in range(N - 1):
		if T[i + 1] != T[i]:
			cnt += 1
	ans[t] = cnt // 2
print(*ans, sep='\n')


mod = 10 ** 9 + 7
from math import *
import threading
import sys

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	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, len(prime)):
		if prime[p]:
			li.append(p)
	return li
sys.setrecursionlimit(300000)
primes = SieveOfEratosthenes(1300000)

def fn(n):
	i = 2
	res = n - 1
	val = 0
	for i in range(int(sqrt(n)) + 1, 1, -1):
		val = i - 1 + int(ceil((n - i) / i))
		if val <= res:
			res = val
		else:
			break
	return res

def solve(a, b, c):
	dis = b ** 2 - 4 * a * c
	ans1 = (-b - sqrt(dis)) / (2 * a)
	print(int(ans1))
	return
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	to_change = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			to_change += 1
	print(to_change // 2)


def binstr(string):
	count1 = 0
	countz = 0
	for i in range(0, len(string) - 1):
		if string[i] == string[i + 1] and string[i] == '1':
			count1 += 1
		if string[i] == string[i + 1] and string[i] == '0':
			countz += 1
	return max(countz, count1)
t = int(input())
for i in range(t):
	a = input()
	print(binstr([i for i in input()]))


for i in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	d = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '0':
				c = c + 1
			else:
				d = d + 1
	print(max(c, d))


for z in range(int(input())):
	n = int(input())
	l = list(input())
	correct = int(l[0])
	inc = 0
	res = 0
	for i in range(n):
		if int(l[i]) != correct:
			inc += 1
		elif inc > 0:
			res += 1
			inc = 0
		correct = (correct + 1) % 2
	if inc > 0:
		res += 1
	correct = (int(l[0]) + 1) % 2
	inc = 0
	res2 = 0
	for i in range(n):
		if int(l[i]) != correct:
			inc += 1
		elif inc > 0:
			res2 += 1
			inc = 0
		correct = (correct + 1) % 2
	if inc > 0:
		res2 += 1
	print(min(res, res2))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	(ones, zeros) = (0, 0)
	for i in range(n - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			ones += 1
		if s[i] == s[i + 1] and s[i] == '0':
			zeros += 1
	print(max(ones, zeros))


import os
import sys
from io import BytesIO, IOBase
DEBUG_MODE = False

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		s = list(input())
		zo = 0
		on = 0
		ch = 0
		for i in range(n - 1):
			if s[i] == s[i + 1]:
				ch += 1
			else:
				if ch:
					if s[i] == '1':
						on += ch
					else:
						zo += ch
				ch = 0
		else:
			if ch:
				if s[-1] == '1':
					on += ch
				else:
					zo += ch
		print(max(zo, on))
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')

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
if DEBUG_MODE == True:
	import cProfile
	cProfile.run('main()')
else:
	main()


def solve(n):
	s = input()
	ans = 0
	flag = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if flag == 1:
				ans += 1
				flag = 0
			else:
				flag = 1
	if flag:
		ans += 1
	return ans
for _ in range(int(input())):
	print(solve(int(input())))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	c1 = 0
	for j in range(n - 1):
		if s[j] == '1' and s[j + 1] == '1':
			c = c + 1
		if s[j] == '0' and s[j + 1] == '0':
			c1 = c1 + 1
	print(max(c, c1))


for _ in range(int(input())):
	stringLength = int(input())
	binaryString = list(input())
	count = 0
	for i in range(stringLength - 1):
		if binaryString[i] == binaryString[i + 1]:
			count += 1
	print((count + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	maxi = 0
	temp1 = 0
	temp2 = 0
	for i in range(1, n):
		if s[i - 1] == '1' and s[i] == '1':
			temp1 += 1
			maxi = max(maxi, temp1)
		if s[i - 1] == '0' and s[i] == '0':
			temp2 += 1
			maxi = max(maxi, temp2)
	print(maxi)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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 collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	S = [int(s) for s in getStr()]
	gaps = 0
	gaps2 = 0
	for i in range(1, N):
		if S[i] == S[i - 1] and S[i] == 1:
			gaps += 1
		if S[i] == S[i - 1] and S[i] == 0:
			gaps2 += 1
	return max(gaps, gaps2)
for _ in range(getInt()):
	print(solve())


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	(cnt_1, cnt_0) = (0, 0)
	idx = 0
	while idx < n - 1:
		if s[idx] == '1' and s[idx + 1] == '0':
			cnt_1 += 1
		elif s[idx] == '0' and s[idx + 1] == '1':
			cnt_0 += 1
		idx += 1
	print(n // 2 - max(cnt_0, cnt_1))


for t in range(int(input())):
	n = int(input())
	s = input()
	s = '-' + s + '-'
	cnt = 0
	st = []
	i = 0
	while i <= n:
		if s[i] == '1':
			ans = 1
			while 1:
				i += 1
				if s[i] != '1':
					break
				ans += 1
			if ans:
				st.append(ans)
		i += 1
	stz = []
	ansz = 0
	i = 0
	while i <= n:
		if s[i] == '0':
			ansz = 1
			while 1:
				i += 1
				if s[i] != '0':
					break
				ansz += 1
			if ansz:
				stz.append(ansz)
		i += 1
	y = 0
	for i in stz:
		y += i - 1
	x = 0
	for i in st:
		x += i - 1
	print(max(x, y))


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	cnt = 0
	for j in range(1, n):
		if s[j - 1] == s[j]:
			cnt += 1
	print((cnt + 2 - 1) // 2)


for _ in range(int(input())):
	n = int(input())
	a = input()
	a1 = a.split('0')
	a2 = a.split('1')
	ans1 = 0
	ans2 = 0
	for i in a1:
		ans1 += max(0, len(i) - 1)
	for i in a2:
		ans2 += max(0, len(i) - 1)
	print(max(ans1, ans2))


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	s = input().strip()
	c = 0
	ans1 = 0
	for i in range(n):
		if s[i] == '1':
			c += 1
		else:
			ans1 += max(0, c - 1)
			c = 0
	c = 0
	ans2 = 0
	for i in range(n):
		if s[i] == '0':
			c += 1
		else:
			ans2 += max(0, c - 1)
			c = 0
	print(max(ans1, ans2))


for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	(zero, ones, k) = (0, 0, 0)
	while k < n:
		j = k
		while j < n and s[j] == s[k]:
			j += 1
		if s[k] == '1':
			ones += j - k - 1
		else:
			zero += j - k - 1
		k = j
	print(max(ones, zero))


for t in range(int(input())):
	n = int(input())
	s = input()
	o = 0
	e = 0
	for i in range(n - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			o = o + 1
		if s[i] == s[i + 1] and s[i] == '0':
			e = e + 1
	print(max(e, o))


import math, random, time
from collections import *
from itertools import *

def ass(a, b):
	print(f'Assertion error: {a} != {b}' if a != b else 'OK')

def nr():
	return int(input())

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

def nrss(n):
	return [nrs() for _ in range(n)]

def word():
	return input()

def words():
	return [w for w in input().split()]

def rx():
	return [s.rstrip() for s in open(0)]

def nrx(s):
	return int(s)

def nrxs(s):
	return [int(i) for i in s.split()]

def wrx(s):
	return s

def wrxs(s):
	return [w for w in s.split()]

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)

def gcd(x, y):
	return x if y == 0 else gcd(y, x % y)

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

def sign(a):
	return 0 if a == 0 else int(a / abs(a))

def f(w):
	b0 = 0
	b1 = 0
	for i in range(len(w) - 1):
		s = w[i:i + 2]
		if s == '00':
			b0 += 1
		if s == '11':
			b1 += 1
	return max(b0, b1)
for s in rx()[2::2]:
	print(f(wrx(s)))


test_cases_amount = int(input())
for test_case in range(test_cases_amount):
	n = [int(x) for x in input().split()]
	n = n[0]
	s = input()
	res = 0
	zeros = 0
	ones = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if s[i] == '0':
				zeros += 1
			else:
				ones += 1
	res = max(zeros, ones)
	print()
	print(res)
	print()


def solve(s, goal):
	global n
	arr = []
	count = 0
	ans = 0
	for i in range(n):
		if s[i] != goal[i]:
			count += 1
		else:
			if count != 0:
				if count % 2 == 0:
					ans += 1
				else:
					arr += [count]
			count = 0
	if count != 0:
		if count % 2 == 0:
			ans += 1
		else:
			arr += [count]
	return ans + len(arr)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = '01' * (n // 2)
	two = '10' * (n // 2)
	print(min(solve(s, one), solve(s, two)))


import sys
import math
import bisect
from sys import stdin, stdout
from math import floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
mod = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def mod_inverse(a, n):
	N = n
	xx = 0
	yy = 1
	y = 0
	x = 1
	while n > 0:
		q = a // n
		t = n
		n = a % n
		a = t
		t = xx
		xx = x - q * xx
		x = t
		t = yy
		yy = y - q * yy
		y = t
	x %= N
	x += N
	x %= N
	return x

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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	return prime

def solve():
	n = int(input())
	s = input()[:n]
	cnt = 0
	for i in range(1, n):
		if s[i] == '1':
			if s[i - 1] == '1':
				cnt += 1
	if s[0] == s[-1] == '1':
		cnt += 1
	print(cnt)
testcase = int(sys.stdin.readline())
for _ in range(testcase):
	solve()


cases = int(input())
for _ in range(cases):
	n = input()
	s = input()
	cnt_1 = 0
	cnt_0 = 0
	for i in range(1, len(s)):
		if s[i] == '1' and s[i - 1] == '1':
			cnt_1 += 1
		if s[i] == '0' and s[i - 1] == '0':
			cnt_0 += 1
	if cnt_1 == 0 and cnt_0 == 0:
		print(0)
	else:
		print(max(cnt_1, cnt_0))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c1 = 0
	c2 = 0
	cont = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '0':
				if cont == 1:
					c1 += 1
					cont = 0
			elif cont == 0:
				cont = 1
		elif s[i] == '1':
			if cont == 1:
				c1 += 1
				cont = 0
		elif cont == 0:
			cont = 1
	if cont == 1:
		c1 += 1
	cont = 0
	for i in range(len(s)):
		if i % 2 == 0:
			if s[i] == '1':
				if cont == 1:
					c2 += 1
					cont = 0
			elif cont == 0:
				cont = 1
		elif s[i] == '0':
			if cont == 1:
				c2 += 1
				cont = 0
		elif cont == 0:
			cont = 1
	if cont == 1:
		c2 += 1
	print(min(c1, c2))


_ = int(input())
for t in range(_):
	n = int(input())
	a = input()
	count = 0
	count1 = 0
	for i in range(1, n):
		if a[i] == '1' and a[i] == a[i - 1]:
			count += 1
		elif a[i] == '0' and a[i] == a[i - 1]:
			count1 += 1
	if count == 0:
		print(count1)
	elif count1 == 0:
		print(count)
	else:
		print(max(count, count1))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	op = 0
	on = 0
	for i in range(n):
		if i + 1 < n and a[i] == '1' and (a[i + 1] == '1'):
			on += 1
		if i + 1 < n and a[i] == '0' and (a[i + 1] == '0'):
			op += 1
	print(max(op, on))


y = []
for i in range(int(input())):
	x = int(input())
	s = input()
	sum = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			sum += 1
	y.append((sum + 1) // 2)
print(*y, sep='\n')


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, input()))
	ans1 = 0
	ans2 = 0
	for i in range(1, n):
		if a[i] == 1 and a[i - 1] == 1:
			ans1 += 1
		if a[i] == 0 and a[i - 1] == 0:
			ans2 += 1
	print(max(ans1, ans2))


import math
n = int(input())
for k in range(n):
	l = int(input())
	s = input()
	print(l // 2 - max(s.count('10'), s.count('01')))


import math as m
for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			c += 1
	print(int(m.ceil(c / 2)))


for t in range(int(input())):
	num = int(input())
	arr = input()
	flag = 0
	flag1 = 0
	for i in range(1, num):
		if arr[i] == '1' and arr[i] == arr[i - 1]:
			flag += 1
		elif arr[i] == '0' and arr[i] == arr[i - 1]:
			flag1 += 1
	if flag == 0:
		print(flag1)
	elif flag1 == 0:
		print(flag)
	else:
		print(max(flag, flag1))


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 si():
	return input()

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

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

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

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	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 phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	n = scanner()
	s = string()
	c = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			c += 1
	print(math.ceil(c / 2))
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')
t = scanner()
for i in range(t):
	solve()


def f():
	n = int(input())
	s = input()
	c0 = 0
	c1 = 0
	for i in range(1, n):
		if s[i] == s[i - 1] == '0':
			c0 += 1
		if s[i] == s[i - 1] == '1':
			c1 += 1
	print(max(c1, c0))
t = int(input())
for i in range(t):
	f()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = 0
	for _ in range(n - 1):
		if s[_] == s[_ + 1]:
			ans += 1
	if s[0] == s[n - 1]:
		ans += 1
	print(ans // 2)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input()))
	ans1 = 0
	i = 0
	flag = 0
	while i < n:
		if ar[i] != i % 2:
			flag = 1
		elif flag:
			ans1 += 1
			flag = 0
		i += 1
	if flag:
		ans1 += 1
	ans2 = 0
	i = 0
	flag = 0
	while i < n:
		if ar[i] == i % 2:
			flag = 1
		elif flag:
			ans2 += 1
			flag = 0
		i += 1
	if flag:
		ans2 += 1
	print(min(ans1, ans2))


import math
t = int(input())

def solve():
	n = int(input())
	s = input()
	ans = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			ans += 1
	print(int(math.ceil(ans / 2)))
for i in range(t):
	solve()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, S):
	pairZeroes = 0
	pairOnes = 0
	for (x, y) in zip(S, S[1:]):
		if x == y == '0':
			pairZeroes += 1
		if x == y == '1':
			pairOnes += 1
	return max(pairZeroes, pairOnes)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	S = input().decode().rstrip()
	ans = solve(N, S)
	print(ans)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	m = input()
	cnt = 0
	for i in range(0, n - 1):
		if m[i] == m[i + 1]:
			cnt += 1
	print(math.ceil(cnt / 2.0))


def solve(n, d):
	big = float('inf')
	small = float('-inf')
	oneStart = 0
	before = False
	for i in range(n):
		if i % 2 == 0:
			if d[i] == 0:
				if not before:
					oneStart += 1
					before = True
			else:
				before = False
		elif d[i] == 1:
			if not before:
				oneStart += 1
				before = True
		else:
			before = False
	zeroStart = 0
	before = False
	for i in range(n):
		if i % 2 == 0:
			if d[i] == 1:
				if not before:
					zeroStart += 1
					before = True
			else:
				before = False
		elif d[i] == 0:
			if not before:
				zeroStart += 1
				before = True
		else:
			before = False
	return min(zeroStart, oneStart)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		d = input()
		d = [int(i) for i in d]
		ans = solve(n, d)
		print(ans)
main()


def solve():
	n = int(input())
	s = input()
	c = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			c += 1
	return (c + 1) // 2
for _ in range(int(input())):
	print(solve())


def alternate_string(n, s):
	low = 1
	high = n - 2
	flag1 = flag2 = 0
	for i in range(n - 1):
		if s[low] == '0' and s[low - 1] == '1':
			flag1 += 1
		if s[high] == '0' and s[high + 1] == '1':
			flag2 += 1
		low += 1
		high -= 1
	return n // 2 - max(flag1, flag2)
for i in range(int(input())):
	n = int(input())
	s = input()
	print(alternate_string(n, s))


for u in range(int(input())):
	n = int(input())
	s = input()
	x = s[0]
	c = 0
	for i in range(1, n):
		if s[i] == x:
			c += 1
		elif x == '0':
			x = '1'
		else:
			x = '0'
	d = n - c
	ka = n - d
	if d % 2 == 0:
		print(ka // 2)
	else:
		print(ka // 2 + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	count1 = 0
	count0 = 0
	for i in range(n - 1):
		if s[i:i + 2] == '11':
			count1 += 1
		if s[i:i + 2] == '00':
			count0 += 1
	if count1 >= count0:
		print(count1)
	else:
		print(count0)


t = int(input())
for j in range(0, t):
	n = int(input())
	inp_str = input()
	ind = 0
	m = True
	last = inp_str[0]
	c = 0
	while ind < n - 1:
		if inp_str[ind] == inp_str[ind + 1]:
			c += 1
		ind += 1
	if c % 2 == 0:
		print(c // 2)
	else:
		print(c // 2 + 1)


import math

def main():
	t = int(input())
	for i in range(t):
		tam_string = int(input())
		string = input()
		par1 = string.count('01')
		par2 = string.count('10')
		resp = tam_string - (par1 + par2)
		print(resp // 2)
main()


def convert(n, a, b):
	l = [0] * n
	for i in range(n):
		if a[i] != b[i]:
			l[i] = 1
	cc = 0
	vl = 0
	for i in range(n):
		if l[i] == 0:
			if vl != 0:
				cc += 1
			vl = 0
		else:
			vl += 1
	if vl != 0:
		cc += 1
	return cc
for _ in range(int(input())):
	n = int(input())
	s = input()
	a1 = '10' * (n // 2)
	a2 = '01' * (n // 2)
	print(min(convert(n, s, a1), convert(n, s, a2)))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	i = 0
	z = 0
	o = 0
	while i < len(s):
		m = s[i]
		k = 0
		i += 1
		while i < len(s) and s[i] == m:
			i += 1
			k += 1
		if m == '0':
			z += k
		else:
			o += k
	print(max(z, o))


t = int(input())
arr = []
for _ in range(t):
	n = int(input())
	arr.append(input())

def reverse(s):
	(zero, one) = (0, 0)
	prev = ''
	for k in s:
		if prev == '':
			prev = k
		elif prev == k == '0':
			zero += 1
		elif prev == k == '1':
			one += 1
		else:
			prev = k
	return max(zero, one)
for s in arr:
	print(reverse(s))


t = int(input())
while t:
	n = int(input())
	s = input()
	last = -1
	c = 0
	for i in s:
		if i == last:
			c += 1
		last = i
	print((c + 1) // 2)
	t -= 1


t = int(input())
for i in range(t):
	ct = 0
	n = int(input())
	s = input()
	for j in range(n):
		if s[j] == s[j - 1]:
			ct += 1
	print(ct // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = 0
	b = 0
	temp = 0
	t = 1
	f1 = 0
	f2 = 2
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			a += 1
		if s[i] == '0' and s[i + 1] == '0':
			b += 1
	print(max(a, b))


import math
t = int(input())
while t > 0:
	n = int(input())
	a = input()
	c = 0
	for i in range(len(a) - 1):
		if a[i] == a[i + 1]:
			c = c + 1
	print(math.ceil(c / 2))
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	sol1 = 0
	sol2 = 0
	(c, d) = (0, 0)
	for i in range(n):
		if s[i] == '1':
			c += 1
		else:
			sol1 += max(0, c - 1)
			c = 0
	if c > 1:
		sol1 += max(0, c - 1)
	for i in range(n):
		if s[i] == '0':
			d += 1
		else:
			sol2 += max(0, d - 1)
			d = 0
	if d > 1:
		sol2 += max(0, d - 1)
	print(max(sol1, sol2))


def reversal(n, s):
	zero = 0
	Count = 0
	for i in range(n):
		if int(s[i]) != i % 2 and Count > 0:
			Count += 1
		elif int(s[i]) != i % 2:
			Count = 1
		else:
			if Count > 0:
				zero += 1
			Count = 0
	if Count > 0:
		zero += 1
	one = 0
	Count = 0
	for i in range(n):
		if int(s[i]) == i % 2 and Count > 0:
			Count += 1
		elif int(s[i]) == i % 2:
			Count = 1
		else:
			if Count > 0:
				one += 1
			Count = 0
	if Count > 0:
		one += 1
	return min(zero, one)
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(reversal(n, s))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	s = S() + '#'
	p = str(int(s[0]) ^ 1)
	a = [0, 0]
	cnt = 1
	for i in s:
		if p != i:
			a[int(p)] += cnt - 1
			p = i
			cnt = 0
		cnt += 1
	print(min(a) + abs(a[0] - a[1]))


import os
from heapq import heapify, heappop, heappush
import sys
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		(ar, br) = ([], [])
		(a, b) = (0, 0)
		for i in s:
			if i == '1':
				a += 1
				if b:
					br.append(b)
				b = 0
			else:
				if a:
					ar.append(a)
				a = 0
				b += 1
		if b:
			br.append(b)
		if a:
			ar.append(a)
		(t1, t2) = (0, 0)
		for i in ar:
			t1 += i - 1
		for i in br:
			t2 += i - 1
		print(max(t1, t2))
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()


cases = int(input())
for t in range(cases):
	n = int(input())
	s = input() + '!'
	mv = {'0': [], '1': []}
	c = 1
	for i in range(1, n + 1):
		if s[i] == s[i - 1]:
			c += 1
		else:
			mv[s[i - 1]].append(c)
			c = 1
	mv1 = sum([i - 1 for i in mv['1']])
	mv2 = sum([i - 1 for i in mv['0']])
	print(max(mv1, mv2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	print(max(sum((s[i] == s[i + 1] == '1' for i in range(n - 1))), sum((s[i] == s[i + 1] == '0' for i in range(n - 1)))))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
from types import GeneratorType

def iterative(f, stack=[]):

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

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 zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(input())
	a = list(inp())
	for i in range(n):
		a[i] = int(a[i])
	cnt1 = 0
	for i in range(0, n - 1):
		if a[i] == a[i + 1]:
			cnt1 += 1
	print(ceil(cnt1 / 2))
testcase(int(inp()))


import math
t = int(input())
for j in range(t):
	n = int(input())
	s = input()
	l = list(s)
	count = 0
	for i in range(0, len(l) - 1):
		if l[i] == l[i + 1]:
			count += 1
	if count == 0:
		print(count)
	elif count == 1:
		print(count)
	else:
		print(math.ceil(count / 2))


def main():
	n = int(input())
	l = input()
	res1 = 0
	res0 = 0
	cur1 = 0
	cur0 = 0
	is_1 = False
	is_0 = False
	for i in l:
		if i == '1':
			cur1 += 1
			if is_1 == True:
				pass
			else:
				res0 += max(0, cur0 - 1)
				cur0 = 0
				is_1 = True
				is_0 = False
		else:
			cur0 += 1
			if is_0 == True:
				pass
			else:
				res1 += max(0, cur1 - 1)
				cur1 = 0
				is_1 = False
				is_0 = True
	res1 += max(0, cur1 - 1)
	res0 += max(0, cur0 - 1)
	print(max(res0, res1))
t = int(input())
for i in range(t):
	main()


from collections import Counter
from collections import OrderedDict
from collections import defaultdict
import bisect

def freq_count(mylist):
	return Counter(mylist)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input()]
	t1 = []
	c1 = 0
	for each in arr:
		if each == 1:
			c1 += 1
		else:
			if c1 > 1:
				t1.append(c1 - 1)
			c1 = 0
	if c1 > 1:
		t1.append(c1 - 1)
	t0 = []
	c1 = 0
	for each in arr:
		if each == 0:
			c1 += 1
		else:
			if c1 > 1:
				t0.append(c1 - 1)
			c1 = 0
	if c1 > 1:
		t0.append(c1 - 1)
	ans1 = 0
	for each in t1:
		ans1 += each
	ans0 = 0
	ans0 = sum(t0)
	print(max(ans0, ans1))


def f(a, b):
	cnt = 0
	now = False
	for i in range(len(a)):
		if a[i] != b[i]:
			if not now:
				cnt += 1
				now = True
		else:
			now = False
	return cnt
for _ in range(int(input())):
	n = int(input())
	data = list(map(int, input()))
	one = [0] * n
	two = [0] * n
	for i in range(n):
		if i % 2 == 0:
			one[i] = 1
			two[i] = 0
		else:
			one[i] = 0
			two[i] = 1
	res = f(data, one)
	res = min(res, f(data, two))
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	onezero = 0
	zeroone = 0
	find = 1
	for i in range(n):
		if int(s[i]) == find:
			if find == 0:
				onezero += 1
			find = 1 - find
	find = 0
	for i in range(n):
		if int(s[i]) == find:
			if find == 1:
				zeroone += 1
			find = 1 - find
	print((n >> 1) - max(zeroone, onezero))


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

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

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

def lint():
	return [int(x) for x in stdin.readline().split()]

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

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
from collections import Counter, defaultdict
from itertools import permutations
import re
from math import floor, sqrt, ceil

def aps():
	for _ in range(I()):
		n = I()
		s = S()
		cnt = 0
		for i in range(n - 1):
			if s[i] != s[i + 1]:
				cnt += 1
		print((n - cnt) // 2)
aps()


for _ in range(int(input())):
	n = int(input())
	binary = input()
	first = '0' + binary + '1'
	second = '1' + binary + '0'
	cnt = 0
	res = []
	res_1 = []
	if n == 2:
		print(0)
	else:
		for i in range(len(first) - 1):
			if first[i] == first[i + 1]:
				res.append(1)
			if second[i] == second[i + 1]:
				res_1.append(1)
		print(min(sum(res), sum(res_1)) // 2)


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		c = 0
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				c += 1
		print(c // 2 + c % 2)
	return

def __starting_point():
	main()
__starting_point()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(zp, op) = (0, 0)
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			zp = zp + 1
		if s[i] == '1' and s[i + 1] == '1':
			op = op + 1
	print(max(zp, op))


import math
num_testcases = int(input())

def get_reversals(string):
	assert len(string) % 2 == 0
	num_boundaries = 0
	for i in range(len(string) - 1):
		if string[i] == string[i + 1]:
			num_boundaries += 1
	return math.ceil(num_boundaries / 2)
for num_testcase in range(num_testcases):
	len_string = input()
	testcase = input()
	reversals = get_reversals(testcase)
	print(reversals)


for t in range(int(input())):
	n = int(input())
	s = input()
	cur1 = 0
	cur0 = 0
	s += '2'
	ans1 = 0
	ans0 = 0
	for i in s:
		if i == '1':
			cur1 += 1
		else:
			ans1 += max(0, cur1 - 1)
			cur1 = 0
		if i == '0':
			cur0 += 1
		else:
			ans0 += max(0, cur0 - 1)
			cur0 = 0
	print(max(ans1, ans0))


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	ans1 = 0
	c = 0
	for c1 in s:
		if c1 == '1':
			if c == 1:
				ans += 1
			c = 1
		else:
			c = 0
	c = 0
	for c1 in s:
		if c1 == '0':
			if c == 1:
				ans1 += 1
			c = 1
		else:
			c = 0
	print(max(ans, ans1))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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))
from types import GeneratorType

def iterative(f, stack=[]):

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

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 nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(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
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = N()
	s = inp()
	temp0 = []
	temp1 = []
	for i in range(n):
		if i % 2 == 0:
			if s[i] == '1':
				temp0.append(1)
				temp1.append(0)
			else:
				temp0.append(0)
				temp1.append(1)
		elif s[i] == '0':
			temp0.append(1)
			temp1.append(0)
		else:
			temp0.append(0)
			temp1.append(1)

	def f(ar):
		n = len(ar)
		ar.append(0)
		t = []
		c = 0
		for i in ar:
			if i == 0:
				t.append(c)
				c = 0
			else:
				c = 1
		return sum(t)
	a = f(temp0)
	b = f(temp1)
	print(min(a, b))
testcase(int(inp()))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

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

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

def fun(st, poss, n):
	cnt1 = 0
	change = True if st[0] != poss[0] else False
	if change:
		cnt1 += 1
	for i in range(1, n):
		if st[i] != poss[i]:
			if not change:
				change = True
				cnt1 += 1
		else:
			change = False
	return cnt1

def solve():
	n = get_int()
	st = input()
	poss1 = '10' * (n // 2)
	poss2 = '01' * (n // 2)
	print(min(fun(st, poss1, n), fun(st, poss2, n)))

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


n = int(input())
for _ in range(n):
	l = int(input())
	s = input()
	previous = int(s[0])
	k = [0, 0]
	k[previous] = -1
	for i in range(l):
		if int(s[i]) == previous:
			k[previous] += 1
		else:
			previous = 1 - previous
	print(max(k))


t = int(input())
for i in range(t):
	n = int(input())
	binarr = input()
	prev = 0
	onecounter = 0
	zerocounter = 0
	if binarr[0] == '1':
		prev = 1
	for bit in binarr[1:]:
		if bit == '1' and prev:
			onecounter += 1
		elif bit == '1':
			prev = 1
		elif not prev:
			zerocounter += 1
		else:
			prev = 0
	print(max(zerocounter, onecounter))


import sys

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

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)

def RLE(data):
	from itertools import groupby
	return [(x, len(list(grp))) for (x, grp) in groupby(data)]

def check(S, T):
	A = [0] * N
	for i in range(N):
		if S[i] != T[i]:
			A[i] = 1
	rle = RLE(A)
	cnt = 0
	for (x, _) in rle:
		if x:
			cnt += 1
	return cnt
for _ in range(INT()):
	N = INT()
	S = input()
	T1 = '01' * (N // 2)
	T2 = '10' * (N // 2)
	ans = min(check(S, T1), check(S, T2))
	print(ans)


for s in [*open(0)][2::2]:
	print(len(s) // 2 - sum(map(bool, s.split(s[-2]))) + 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	(ct1, ct0) = (0, 0)
	for i in range(1, n):
		if s[i - 1] == s[i]:
			if s[i] == '1':
				ct1 += 1
			else:
				ct0 += 1
	print(max(ct1, ct0))


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	cnt = 0
	cnt1 = 0
	for i in range(1, n):
		if s[i] == '1' and s[i - 1] == '1':
			cnt += 1
	for i in range(1, n):
		if s[i] == '0' and s[i - 1] == '0':
			cnt1 += 1
	print(max(cnt, cnt1))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 2:
		print('0')
	else:
		p = 0
		q = 0
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				continue
			if s[i] == '0':
				p += 1
			else:
				q += 1
		print(n // 2 - max(p, q))


t = int(input())
for i in range(t):
	length = int(input())
	binary = list(input())
	c = 0
	prev = '2'
	dupZeros = 0
	dupOnes = 0
	for j in binary:
		if prev == j and j == '0':
			dupZeros = dupZeros + 1
		if prev == j and j == '1':
			dupOnes = dupOnes + 1
		prev = j
	if dupOnes > dupZeros:
		print(dupOnes)
	else:
		print(dupZeros)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = str(input())
		(a, b) = (0, 0)
		for i in range(1, n):
			if s[i - 1] == s[i] and s[i - 1] == '0':
				a += 1
			if s[i - 1] == s[i] and s[i - 1] == '1':
				b += 1
		print(max(a, b))
main()


def f(n, d):
	(a, b) = (0, 0)
	for i in range(n - 1):
		if d[i] == d[i + 1]:
			if d[i] == '1':
				a += 1
			else:
				b += 1
	print(max(a, b))
for i in range(int(input())):
	f(int(input()), input())


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = s.replace('01', '')
	ans1 = len(s1) // 2
	s2 = s.replace('10', '')
	ans2 = len(s2) // 2
	print(min(ans1, ans2))


from sys import stdin, stdout

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

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

def getOps(s, v, n):
	cnt = 0
	match = True
	for i in range(n):
		if s[i] != v[i]:
			if match:
				match = False
				cnt += 1
		elif not match:
			match = True
	return cnt

def solve():
	n = II()
	s = SI()
	s1 = [str(i % 2) for i in range(n)]
	s2 = [str((i + 1) % 2) for i in range(n)]
	s1 = ''.join(s1)
	s2 = ''.join(s2)
	ans = min(getOps(s, s1, n), getOps(s, s2, n))
	stdout.write(str(ans) + '\n')
t = II()
for _ in range(t):
	solve()


t = int(input())
for l in range(0, t):
	n = int(input())
	s = input()
	(n1, n0) = (0, 0)
	for i in range(0, n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			n1 += 1
		elif s[i] == '0' and s[i + 1] == '0':
			n0 += 1
	if n1 > n0:
		print(n1)
	else:
		print(n0)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

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

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		n = ii()
		s = si()
		(c, ans) = (0, 0)
		for i in range(n):
			if s[i] == '1':
				if c > 0:
					ans += c - 1
				c = 0
			else:
				c += 1
		if c > 0:
			ans += c - 1
		(ans1, c) = (0, 0)
		for i in range(n):
			if s[i] == '0':
				if c > 0:
					ans1 += c - 1
				c = 0
			else:
				c += 1
		if c > 0:
			ans1 += c - 1
		print(max(ans, ans1))
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


for i in range(int(input())):
	n = int(input())
	s = input()
	(a, b) = (0, 0)
	for j in range(n - 1):
		if s[j] == '0' and s[j + 1] == '1':
			a += 1
			j += 2
	for j in range(n - 1):
		if s[j] == '1' and s[j + 1] == '0':
			b += 1
			j += 2
	print(n // 2 - max(a, b))


for t in range(int(input())):
	n = int(input())
	s = input()
	c10 = 0
	c01 = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			c10 += 1
		elif s[i] == '0' and s[i + 1] == '1':
			c01 += 1
	z = n // 2
	m = max(c10, c01)
	print(z - m)


for tc in range(int(input())):
	n = int(input())
	s = input()
	(cnt, flag) = (0, 0)
	for i in range(1, n):
		if s[i] == s[i - 1]:
			flag += 1
	print((flag + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(pc, ctr) = (s[0], 0)
	(res, res1) = (0, 0)
	for i in range(1, len(s)):
		if s[i] == pc:
			ctr += 1
		else:
			if s[i] == '0':
				res += ctr
			else:
				res1 += ctr
			ctr = 0
		pc = s[i]
	if s[-1] == '1':
		res += ctr
	else:
		res1 += ctr
	print(max(res, res1))


for _ in range(int(input())):
	n = int(input())
	a = []
	an = []
	a = input()
	i = 0
	s = 0
	o = 0
	for i in range(1, n):
		if a[i] == '1' and a[i - 1] == a[i]:
			o += 1
	z = 0
	for i in range(1, n):
		if a[i] == '0' and a[i - 1] == a[i]:
			z += 1
	print(max(o, z))


n = int(input())
for i in range(n):
	t = int(input())
	s = input()
	lis = [[0, 0], [0, 0]]
	for i in range(t):
		if i % 2 == int(s[i]):
			lis[0][0] += 1
			if i > 0:
				if 1 - i % 2 == int(s[i - 1]):
					lis[0][1] += 1
		else:
			lis[1][0] += 1
			if i > 0:
				if i % 2 == int(s[i - 1]):
					lis[1][1] += 1
	print(min(lis[0][0] - lis[0][1], lis[1][0] - lis[1][1]))


for i in range(int(input())):
	n = int(input())
	s = input()
	z = s.count('10') + s.count('01')
	print((n - z) // 2)


t = int(input())
for _ in range(t):
	l = int(input())
	s = input()
	tot0 = 0
	tot1 = 0
	x = 0
	while x < l - 1:
		if s[x] == s[x + 1] and s[x] == '0':
			y = 1
			if y + x + 1 < l:
				while s[x + y] == s[x + y + 1]:
					y += 1
					if x + y + 1 > l - 1:
						break
			tot0 += y
			x += y
		elif s[x] == s[x + 1] and s[x] == '1':
			y = 1
			if y + x + 1 < l:
				while s[x + y] == s[x + y + 1]:
					y += 1
					if x + y + 1 > l - 1:
						break
			tot1 += y
			x += y
		x += 1
	print(max(tot0, tot1))


import os
import sys
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 = 1000000007
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()
	s = input()
	have = []
	c = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			have.append((s[i - 1], c))
			c = 0
		c += 1
	have.append((s[-1], c))
	ans = defaultdict(int)
	for (k, c) in have:
		ans[k] += c - 1
	print(max(ans.values()))


T = int(input())
for _ in range(T):
	N = int(input())
	s = input()
	S = sum([int(s[i] == s[i - 1]) for i in range(1, N)])
	print(S // 2 + S % 2)


test = int(input())
for _ in range(test):
	n = int(input())
	string = input()
	i = 0
	onezero = 0
	zeroone = 0
	while i < n - 1:
		if string[i] == '1' and string[i + 1] == '0':
			onezero += 1
		i += 1
	i = 0
	while i < n - 1:
		if string[i] == '0' and string[i + 1] == '1':
			zeroone += 1
		i += 1
	m = 2 * max(onezero, zeroone)
	res = (n - m) // 2
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	arr = s.split('0')
	c1 = 0
	for num in arr:
		if len(num) > 1:
			c1 += len(num) - 1
	arr = s.split('1')
	c2 = 0
	for num in arr:
		if len(num) > 1:
			c2 += len(num) - 1
	print(max(c1, c2))


tets_cases = int(input())
for _ in range(tets_cases):
	input()
	b_str = str(input())
	one_pairs = 0
	zero_pairs = 0
	for i in range(len(b_str) - 1):
		if b_str[i] == '1' and b_str[i + 1] == '1':
			one_pairs += 1
		elif b_str[i] == '0' and b_str[i + 1] == '0':
			zero_pairs += 1
	print(max(one_pairs, zero_pairs))


for i in range(int(input())):
	n = int(input())
	s = input()
	count1 = count2 = 0
	for i in range(1, n):
		if s[i] == s[i - 1] == '1':
			count1 += 1
		elif s[i] == s[i - 1] == '0':
			count2 += 1
	print(max(count1, count2))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	st = input()
	ans1 = 0
	ans0 = 0
	i = 0
	while i < n:
		ctv = 1
		while st[i] == st[i - 1]:
			ctv = ctv + 1
			i = i + 1
		if st[i - 1] == '1':
			ans0 = ans0 + ctv - 1
		else:
			ans1 = ans1 + ctv - 1
		i = i + 1
	ans = max(ans1, ans0)
	print(ans)


for __ in range(int(input())):
	n = int(input())
	s = input()
	(oz, zo) = (0, 0)
	for i in range(0, n - 1):
		if s[i] == '0' and s[i + 1] == '1':
			zo += 1
		if s[i] == '1' and s[i + 1] == '0':
			oz += 1
	print(n // 2 - max(zo, oz))


t = int(input())
inputs = []
for i in range(0, t):
	n = input()
	inputs.append(input())
for s in inputs:
	c = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			c += 1
	print((c + 1) // 2)


for _ in [0] * int(input()):
	n = int(input())
	s = input()
	s00 = 0
	s11 = 0
	for i in range(1, n):
		if s[i] == '0' and s[i - 1] == '0':
			s00 += 1
		elif s[i] == '1' and s[i - 1] == '1':
			s11 += 1
	print(max(s11, s00))


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
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')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

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

def primeFactors(n):
	sa = set()
	sa.add(n)
	while n % 2 == 0:
		sa.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.add(i)
			n = n // i
	return sa

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

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

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
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	i = 0
	ans1 = 0
	ans2 = 0
	while i < n:
		z = s[i]
		cnt = 0
		if z == '1':
			while i < n and s[i] == '1':
				i += 1
				cnt += 1
			ans1 += cnt - 1
		else:
			while i < n and s[i] == '0':
				i += 1
				cnt += 1
			ans2 += cnt - 1
	print(max(ans1, ans2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	d = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			c += 1
		if s[i] == '0' and s[i + 1] == '0':
			d += 1
	ans = max(c, d)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	x = y = 0
	for i in range(n - 1):
		if a[i] == '0' and a[i + 1] == '0':
			x += 1
		if a[i] == '1' and a[i + 1] == '1':
			y += 1
	print(max(x, y))


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = 0
	r = n - 1
	ans1 = 0
	boo = 0
	while 1:
		if l > r:
			break
		if l % 2 == boo and s[l] == '1':
			l += 1
			continue
		if l % 2 != boo and s[l] == '0':
			l += 1
			continue
		if r % 2 == boo and s[r] == '1':
			r -= 1
			continue
		if r % 2 != boo and s[r] == '0':
			r -= 1
			continue
		ans1 += 1
		boo = boo ^ 1
	ans2 = 0
	boo = 1
	l = 0
	r = n - 1
	while 1:
		if l > r:
			break
		if l % 2 == boo and s[l] == '1':
			l += 1
			continue
		if l % 2 != boo and s[l] == '0':
			l += 1
			continue
		if r % 2 == boo and s[r] == '1':
			r -= 1
			continue
		if r % 2 != boo and s[r] == '0':
			r -= 1
			continue
		ans2 += 1
		boo = boo ^ 1
	print(min(ans1, ans2))


from typing import *

def change_count(bits: str):
	(zeros, ones) = (0, 0)
	(delta_z, delta_o) = (-1, -1)
	last_bit = ''
	for bit in bits:
		if bit != last_bit:
			if delta_z > 0:
				zeros += delta_z
			elif delta_o > 0:
				ones += delta_o
			(delta_z, delta_o) = (-1, -1)
			last_bit = bit
		if bit == '1':
			delta_o += 1
		else:
			delta_z += 1
	return max(zeros, ones)

def main():
	result: List[int] = []
	for _ in range(int(input())):
		input()
		result.append(change_count(input().strip()))
	for r in result:
		print(r)
main()


import sys, collections, math, itertools, random
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()
	cnt = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			cnt += 1
	print((cnt + 1) // 2)


num = input()
for _ in range(int(num)):
	input()
	inputboi = input()
	zboi = inputboi.split('1')
	oboy = inputboi.split('0')
	kekw = sum([len(smolboi) - 1 if smolboi else 0 for smolboi in zboi])
	ecksdee = sum([len(smolboi) - 1 if smolboi else 0 for smolboi in oboy])
	print(max(kekw, ecksdee))


import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
	n = int(sys.stdin.readline().rstrip())
	s = sys.stdin.readline().rstrip()
	sol = 0
	so = s[0]
	for i in range(1, n):
		if s[i] == so:
			sol += 1
		else:
			so = s[i]
	if s[0] == s[-1]:
		sol += 1
	print(sol // 2)


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	ans1 = 0
	ans2 = 0
	temp = 0
	i = 0
	while i < n:
		temp = 0
		while i < n and a[i] == '0':
			temp += 1
			i += 1
		if temp:
			ans1 += temp - 1
		temp = 0
		while i < n and a[i] == '1':
			temp += 1
			i += 1
		if temp:
			ans2 += temp - 1
	print(max(ans1, ans2))


Q = int(input())
for _ in range(Q):
	n = int(input())
	s = input()
	cntone = 0
	cntzero = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			if s[i] == '1':
				cntone += 1
			else:
				cntzero += 1
	print(max(cntone, cntzero))


for _ in range(int(input())):
	n = int(input())
	s = input()
	one_count = 0
	zero_count = 0
	ans = 0
	ans2 = 0
	for i in s:
		if i == '1':
			one_count += 1
			if zero_count > 0:
				ans2 += zero_count - 1
				zero_count = 0
		else:
			zero_count += 1
			if one_count > 0:
				ans += one_count - 1
				one_count = 0
	if one_count > 0:
		ans += one_count - 1
	if zero_count > 0:
		ans2 += zero_count - 1
	print(max(ans, ans2))


from sys import stdin
I = stdin.readline
for _ in range(int(I())):
	n = int(I())
	s = input()
	cnt = 0
	i = 1
	prv = 0
	while i < n:
		if s[prv] == s[i]:
			var = i
			i += 1
			while 1:
				if i > n - 1 or s[var] == s[i]:
					break
				var = i
				i += 1
			cnt += 1
		prv = i
		i += 1
	print(cnt)


def kq(s):
	pre = 't'
	res = 0
	for i in s:
		if i == pre and i == '1':
			res += 1
		pre = i
	return res

def lat(i):
	if i == '1':
		return '0'
	return '1'
n = int(input())
for i in range(n):
	s = input()
	s = input()
	print(max(kq(s), kq(''.join([lat(i) for i in s]))))


for _ in range(int(input())):
	n = int(input())
	a = input()
	(z, o) = (0, 0)
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			if a[i + 1] == '1':
				o += 1
			else:
				z += 1
	print(max(z, o))


def get_cons_pair(key, s):
	pairs = []
	cnt = 0
	for i in range(len(s)):
		if s[i] == str(key):
			cnt += 1
		else:
			if cnt > 0:
				pairs.append(cnt - 1)
			cnt = 0
	if cnt > 0:
		pairs.append(cnt - 1)
	return sum(pairs)

def get_sol(s):
	a1 = get_cons_pair(1, s)
	a2 = get_cons_pair(0, s)
	return max([a1, a2])
for t in range(int(input())):
	n = int(input())
	s = input()
	print(get_sol(s))


for i in range(int(input())):
	n = int(input())
	coun1 = 0
	coun2 = 0
	s = input()
	for j in range(1, n):
		if s[j] == s[j - 1] == '1':
			coun1 += 1
		elif s[j] == s[j - 1] == '0':
			coun2 += 1
	print(max(coun1, coun2))


import math
from collections import deque
from sys import stdin, stdout, setrecursionlimit
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(input().strip())
	if n == 2:
		print(0)
		continue
	a = 0
	b = 0
	for i in range(len(arr) - 1):
		if arr[i] == arr[i + 1]:
			continue
		if arr[i] == '0':
			a += 1
		else:
			b += 1
	print(n // 2 - max(a, b))


import math
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ev = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			ev += 1
	print(math.ceil(ev / 2))


t = int(input())
for _ in range(t):
	n = int(input())
	stri = input()
	(cnt1, cnt2, cnt3, cnt4) = (0, 0, 0, 0)
	for i in stri:
		if i == '1':
			cnt2 += 1
			if cnt4 - 1 > 0:
				cnt3 += cnt4 - 1
			cnt4 = 0
		else:
			cnt4 += 1
			if cnt2 - 1 > 0:
				cnt1 += cnt2 - 1
			cnt2 = 0
	if cnt2 - 1 > 0:
		cnt1 += cnt2 - 1
	if cnt4 - 1 > 0:
		cnt3 += cnt4 - 1
	if cnt1 >= cnt3:
		print(cnt1)
	else:
		print(cnt3)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = s.count('01')
	b = s.count('10')
	numRepetidos = n - a - b
	print(math.floor(numRepetidos / 2))


for tc in range(int(input())):
	n = int(input())
	arr = []
	line = input()
	for i in range(n):
		arr.append(int(line[i]))
	count1 = 0
	count2 = 0
	for i in range(n - 1):
		if arr[i] == 1 and arr[i + 1] == 1:
			count1 += 1
		if arr[i] == 0 and arr[i + 1] == 0:
			count2 += 1
	print(max(count2, count1))


for i in range(int(input())):
	n = int(input())
	x = input()
	x1 = '0' + x + '1'
	x2 = '1' + x + '0'
	(m1, m2) = (0, 0)
	for i in range(1, n + 2):
		if x1[i] == x1[i - 1]:
			m1 += 1
		if x2[i] == x2[i - 1]:
			m2 += 1
	print(min(m1 // 2, m2 // 2))


for i in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	for i in range(n):
		if i == n - 1:
			break
		if s[i] == s[i + 1]:
			if s[i] == '1':
				x = x + 1
	y = 0
	for i in range(n):
		if i == n - 1:
			break
		if s[i] == s[i + 1]:
			if s[i] == '0':
				y = y + 1
	print(max(x, y))


t = int(input())
for tt in range(t):
	n = int(input())
	k1 = 0
	k0 = 0
	f = input()
	f += ' '
	for i in range(n):
		if f[i] == '1' and f[i + 1] == '1':
			k1 += 1
		elif f[i] == '0' and f[i + 1] == '0':
			k0 += 1
	print(max(k0, k1))


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
from heapq import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	s = st()
	p = s[0]
	v = []
	co = 0
	for i in range(n):
		if s[i] == p:
			co += 1
			continue
		v.append(co)
		co = 1
		p = s[i]
	if co:
		v.append(co)
	(s1, s2) = (0, 0)
	for i in range(len(v)):
		if i % 2:
			s1 += v[i] - 1
		else:
			s2 += v[i] - 1
	print(max(s1, s2))


t = int(input())
for o in range(t):
	n = int(input())
	s = input()
	(c1, c2) = (0, 0)
	(a, b) = ('', '')
	for i in range(n // 2):
		a += '1'
		a += '0'
	for i in range(n // 2):
		b += '0'
		b += '1'
	i = 0
	while i < n:
		if s[i] == a[i]:
			i += 1
			continue
		else:
			while i < n:
				if s[i] == a[i]:
					break
				i += 1
			c1 += 1
			i += 1
	i = 0
	while i < n:
		if s[i] == b[i]:
			i += 1
			continue
		else:
			while i < n:
				if s[i] == b[i]:
					break
				i += 1
			c2 += 1
			i += 1
	print(min(c1, c2))


T = int(input())

def Abs(x):
	if x < 0:
		return -x
	return x
for Tid in range(T):
	n = int(input())
	s = input()
	(sum0, sum1) = (0, 0)
	for i in range(1, n):
		if s[i] == '0' and s[i - 1] == '0':
			sum0 = sum0 + 1
		if s[i] == '1' and s[i - 1] == '1':
			sum1 = sum1 + 1
	print(max(sum0, sum1))


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	print(' '.join(list(map(str, a))))

def solve():
	n = I()
	s = S()
	ans = 0
	x = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			x += 1
		else:
			ans += x - 1
			x = 1
	ans += x - 1
	print((ans + 1) // 2)
for _ in range(I()):
	solve()


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	cnt = 0
	f = True
	for i in range(1, n):
		if s[i] == s[i - 1]:
			if f:
				cnt += 1
			f = not f
	print(cnt)


for t in range(int(input())):
	n = int(input())
	a = input()
	a = [int(i) for i in a]
	ans = 0
	ans1 = 0
	for i in range(n - 1):
		if a[i] == 1:
			if a[i + 1] == a[i]:
				ans += 1
		if a[i] == 0:
			if a[i + 1] == a[i]:
				ans1 += 1
	print(max(ans, ans1))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	ans = 0
	i = 0
	while i + 1 < n:
		if s[i] == s[i + 1]:
			ans += 1
		i += 1
	print((ans + 1) // 2)


n = int(input())
for j in range(n):
	t = int(input())
	s = input()
	if s[0] == '1':
		correct = '10' * (t // 2)
	else:
		correct = '01' * (t // 2)
	wrong = 0
	pre = 'correct'
	for i in range(t):
		if s[i] == correct[i]:
			pre = 'correct'
		elif s[i] != correct[i] and pre == 'correct':
			wrong += 1
			pre = 'wrong'
	print(wrong)


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for __ in range(t):
		(l, r) = map(int, input().split())
		if 2 * l > r:
			print('YES')
		else:
			print('NO')

def B():
	t = int(input())
	for __ in range(t):
		n = int(input())
		s = [bool(int(x)) for x in input().rstrip()]
		currT = 0
		currF = 0
		Ts = []
		Fs = []
		for i in s:
			if i:
				if currF > 1:
					Fs.append(currF - 1)
				currF = 0
				currT += 1
			else:
				if currT > 1:
					Ts.append(currT - 1)
				currT = 0
				currF += 1
		if currT > 1:
			Ts.append(currT - 1)
		elif currF > 1:
			Fs.append(currF - 1)
		print(max(sum(Ts), sum(Fs)))

def C():
	t = int(input())
	for __ in range(t):
		_ = 0

def D():
	t = int(input())
	for __ in range(t):
		_ = 0
B()


import sys

def ceil(a, b):
	return -(-a // b)

def answer(n, s):
	pcnt = 0
	for i in range(1, n):
		if s[i] == s[i - 1]:
			pcnt += 1
	return ceil(pcnt, 2)

def main():
	t = int(input())
	while t:
		n = int(sys.stdin.readline())
		s = sys.stdin.readline().rstrip()
		print(answer(n, s))
		t -= 1
	return
main()


def solve():
	global s
	c = [0, 0]
	s += '_'
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			c[int(s[i])] += 1
	print(max(c))
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	solve()


import sys
for _ in range(int(sys.stdin.readline())):
	a = int(sys.stdin.readline())
	b = sys.stdin.readline()
	n = 0
	for i in range(a - 1):
		if b[i] == b[i + 1]:
			n += 1
	print(n // 2 + n % 2)


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	s = list(stdin.readline()[:-1])
	s = list(map(int, s))
	for i in range(0, n, 2):
		s[i] ^= 1
	zero = 0
	for i in range(n):
		if i == 0 and s[0] == 0:
			zero += 1
		elif i != 0 and s[i] == 0 and (s[i - 1] == 1):
			zero += 1
	one = 0
	for i in range(n):
		if i == 0 and s[0] == 1:
			one += 1
		elif i != 0 and s[i] == 1 and (s[i - 1] == 0):
			one += 1
	print(min(zero, one))


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n,) = _read_ints()
		s = _read_line()
		assert len(s) % 2 == 0
		wrong_n = sum((char == next_char for (char, next_char) in zip(s, s[1:])))
		result = (wrong_n + 1) // 2
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	have = []
	c = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			have.append((s[i - 1], c))
			c = 0
		c += 1
	have.append((s[-1], c))
	ans = {'0': 0, '1': 0}
	for (k, c) in have:
		ans[k] += c - 1
	print(max(ans.values()))


from math import *
from random import *
from bisect import *
from math import *
for t in range(int(input())):
	n = int(input())
	s = input()
	f1 = [0 for i in range(n)]
	f2 = [0 for i in range(n)]
	for i in range(n):
		if s[i] == '1' and i % 2 == 0 or (s[i] == '0' and i % 2 != 0):
			f1[i] = 1
		else:
			f2[i] = 1
	v1 = 0
	v2 = 0
	if f1[0] == 0:
		v1 = 1
	if f2[0] == 0:
		v2 = 1
	for i in range(1, n):
		if f1[i] == 0 and f1[i - 1] != 0:
			v1 += 1
	for i in range(1, n):
		if f2[i] == 0 and f2[i - 1] != 0:
			v2 += 1
	print(min(v1, v2))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	i = 0
	c = 0
	ans1 = 0
	while i < n:
		if a[i] == '1':
			c += 1
		elif c > 0:
			ans1 += c - 1
			c = 0
		i += 1
	c = 0
	i = 0
	ans2 = 0
	while i < n:
		if a[i] == '0':
			c += 1
		elif c > 0:
			ans2 += c - 1
			c = 0
		i += 1
	print(max(ans1, ans2))


from math import *
from collections import deque
from copy import deepcopy
import sys

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

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

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

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

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

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

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

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

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
t = int(input())
for _ in range(t):
	n = int(input())
	s = inp()
	ans1 = 0
	ans2 = 0
	flag = False
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			continue
		elif flag:
			ans1 += 1
			flag = False
		else:
			flag = True
	if flag:
		ans1 += 1
	print(ans1)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	a = [int(x) for x in input()]
	i = 0
	ans1 = 0
	ans2 = 0
	while i < n:
		if a[i] == 1:
			c = 0
			while i < n and a[i] == 1:
				c += 1
				i += 1
			ans1 += c - 1
		c = 0
		while i < n and a[i] == 0:
			c += 1
			i += 1
		if c > 0:
			ans2 += c - 1
	print(max(ans1, ans2))


import sys
from array import array
from itertools import groupby

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def solve(a, x):
	for i in range(len(a)):
		a[i] ^= x
		x ^= 1
	return sum((1 for (k, v) in groupby(a) if k == 1))
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().rstrip()))
	print(min(solve(s[:], 0), solve(s[:], 1)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	ans = []
	count = 1
	for i in range(1, n):
		if a[i] == a[i - 1] and a[i] == '1':
			count += 1
		else:
			ans.append(count)
			count = 1
	if count > 1 and a[i] == '1':
		ans.append(count)
	ans1 = 0
	for i in ans:
		ans1 += i - 1
	ans = []
	count = 1
	for i in range(1, n):
		if a[i] == a[i - 1] and a[i] == '0':
			count += 1
		else:
			ans.append(count)
			count = 1
	if count > 1 and a[i] == '0':
		ans.append(count)
	ans2 = 0
	for i in ans:
		ans2 += i - 1
	print(max(ans1, ans2))


tc = int(input())
for t in range(tc):
	n = int(input())
	s = input()
	cnt = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			cnt += 1
	print((cnt + 1) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	count = 0
	if s[0] == '1' and s[-1] == '1':
		count += 1
	i = 0
	while i < n - 1:
		if s[i] == '1' and s[i + 1] == '1':
			count += 1
		i += 1
	print(count)


import math

def reverse_binary_string(string):
	mismatch_count = 0
	string_list = list(map(int, string))
	for i in range(len(string_list) - 1):
		if string_list[i] + string_list[i + 1] != 1:
			mismatch_count += 1
	var = mismatch_count / 2
	print(math.ceil(var))
testcases = int(input())
while testcases:
	testcases -= 1
	length = int(input())
	string = input()
	reverse_binary_string(string)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	s = input().split()[0]
	cou = 0
	ans = 0
	for i in range(n):
		if s[i] == '1':
			cou += 1
		else:
			if cou:
				ans += cou - 1
			cou = 0
	if cou:
		ans += cou - 1
	cou = 0
	cou = 0
	ans1 = 0
	for i in range(n):
		if s[i] == '0':
			cou += 1
		else:
			if cou:
				ans1 += cou - 1
			cou = 0
	if cou:
		ans1 += cou - 1
	print(max(ans, ans1))
	t -= 1


import math
from collections import Counter, defaultdict, deque

def f(n, s):
	t1 = 0
	t2 = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			t1 += 1
		if s[i] == '0' and s[i + 1] == '0':
			t2 += 1
	return max(t1, t2)
t = int(input())
result = []
for i in range(t):
	n = int(input())
	s = list(input().strip())
	result.append(f(n, s))
for i in range(t):
	print(result[i])


import sys
import time
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial, ceil
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

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

def solve():
	n = iinp()
	s = inp()
	a = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			a += 1
	print(ceil(a / 2))
start_time = time.time()
for _ in range(iinp()):
	solve()


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	q = int(input())
	w = input()
	e = 0
	r = 0
	for i in range(1, q):
		if w[i - 1] == w[i]:
			if w[i] == '0':
				r += 1
			else:
				e += 1
	print(max(e, r))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	curr = s[0]
	p = 1
	k = []
	for j in range(1, n):
		if s[j] == curr:
			p += 1
		else:
			k.append(p)
			p = 1
			curr = s[j]
	k.append(p)
	c1 = 0
	c0 = 0
	for j in range(len(k)):
		if j % 2 == 0:
			c1 = k[j] + c1 - 1
		else:
			c0 = c0 + k[j] - 1
	print(max(c0, c1))


for pratyush in range(int(input())):
	n = int(input())
	s = str(input())
	(a, b, x, y) = ('1' + s + '0', '0' + s + '1', 0, 0)
	for i in range(n + 1):
		if a[i] == a[i + 1]:
			x += 1
		if b[i] == b[i + 1]:
			y += 1
	print(min(x // 2, y // 2))


T = int(input())
while T != 0:
	T -= 1
	n = int(input())
	s = input()
	tot = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			tot += 1
			i += 2
	print((tot + 1) // 2)


for _ in range(int(input())):
	n = int(input())
	a = list(input()) + ['1']
	zero = []
	ans = 0
	if a[0] == '0':
		ans += 1
	for i in range(n):
		if a[i + 1] == '0':
			ans += 1
		elif ans > 0:
			zero.append(ans)
			ans = 0
	a[-1] = '0'
	one = []
	ans = 0
	if a[0] == '1':
		ans += 1
	for i in range(n):
		if a[i + 1] == '1':
			ans += 1
		elif ans > 0:
			one.append(ans)
			ans = 0
	print(max(sum(one) - len(one), sum(zero) - len(zero)))


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	s = input()
	s = list(s)
	i = 0
	ans1 = 0
	ans0 = 0
	while i < n - 1:
		cnt1 = 0
		cnt0 = 0
		while i < n - 1 and s[i] == s[i + 1] == '1':
			cnt1 += 1
			i += 1
		while i < n - 1 and s[i] == s[i + 1] == '0':
			cnt0 += 1
			i += 1
		ans1 += cnt1
		ans0 += cnt0
		i += 1
	print(max(ans1, ans0))


from math import ceil

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input()))
		w = 0
		for i in range(1, n):
			if a[i] == a[i - 1]:
				w += 1
		print(ceil(w / 2))
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	(ans, ans2) = (0, 0)
	for i in range(n - 1):
		if s[i] == s[i + 1] == '1':
			ans += 1
		elif s[i] == s[i + 1] == '0':
			ans2 += 1
	print(max(ans, ans2))


import sys, os
from math import sqrt
from collections import defaultdict
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	(ans1, ans2) = [0] * 2
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '1':
			ans2 += 1
	for i in range(n - 1):
		if s[i] == '0' and s[i + 1] == '0':
			ans1 += 1
	print(max(ans1, ans2))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	o = 0
	z = 0
	for i in range(n - 1):
		if s[i] == s[i + 1] and s[i] == '0':
			z += 1
		elif s[i] == s[i + 1] and s[i] == '1':
			o += 1
	print(max(o, z))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = input()
		last = l[0]
		count = 1
		temp = []
		for x in range(1, n):
			if l[x] != last:
				temp.append([last, count])
				count = 1
				last = l[x]
			else:
				count += 1
		if count:
			temp.append([last, count])
		(A1, A2) = (0, 0)
		for x in temp:
			if x[0] == '1':
				A1 += x[1] - 1
			else:
				A2 += x[1] - 1
		print(max(A1, A2))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys
import math, bisect
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

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

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	s = input()
	res = [len(list(j)) for (_, j) in groupby(list(s))]
	Ans = 0
	for i in res:
		if i > 1:
			Ans += i - 1
	print(Ans // 2 + Ans % 2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	zeroone = s.count('01')
	onezero = s.count('10')
	ans = n // 2 - max(zeroone, onezero)
	print(ans)


tests = int(input())
for test in range(tests):
	n = int(input())
	s = input()
	res = 0
	for i in range(n - 1):
		if s[i] == s[i + 1]:
			res += 1
	print((res + 1) // 2)


def solution():
	n = int(input())
	l = list(input())
	ans0 = 0
	ans1 = 0
	i = 1
	while i < n:
		if l[i] == l[i - 1]:
			if l[i] == '0':
				ans0 += 1
			else:
				ans1 += 1
		i += 1
	print(max(ans0, ans1))
t = int(input())
for _ in range(t):
	solution()


def solve():
	n = int(input().strip())
	s = list(input().strip())

	def count(object_type):
		adjacent_count = 0
		for i in range(n - 1):
			if s[i] != object_type:
				continue
			if s[i] == s[i + 1]:
				adjacent_count += 1
		return adjacent_count
	return max(count('0'), count('1'))
for _ in range(int(input().strip())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = 1
	for i in range(1, n):
		if s[i] == s[i - 1]:
			r += 1
	print(r // 2)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
import operator as op
from functools import reduce
mod = 1000000007

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

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

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

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPrime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def myCode():
	n = I()
	s = input()
	ans = 0
	ans2 = 0
	cnt = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '1':
			cnt += 1
		else:
			ans += cnt
			cnt = 0
	count = 0
	for i in range(len(s) - 1):
		if s[i] == '0' and s[i + 1] == '0':
			count += 1
		else:
			ans2 += count
			count = 0
	print(max(ans, ans2))

def main():
	for t in range(I()):
		myCode()
main()


import math
for _ in range(int(input())):
	n = int(input())
	s = input().rstrip()
	s = [x for x in s]
	zero = [0]
	count = 0
	for x in range(n - 1):
		if s[x + 1] == s[x]:
			count += 1
			if x + 1 == n - 1:
				zero.append(count)
		elif count > 0:
			zero.append(count)
			count = 0
	print(int(math.ceil(sum(zero) / 2)))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	bs = str(input())
	cnt = 0
	ans = 0
	for i in bs:
		if i == '1':
			cnt += 1
		else:
			if cnt > 1:
				ans += cnt - 1
			cnt = 0
	ans1 = ans
	cnt = 0
	ans = 0
	for i in bs:
		if i == '0':
			cnt += 1
		else:
			if cnt > 1:
				ans += cnt - 1
			cnt = 0
	print(max(ans, ans1))


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	temparr = input()
	arr = []
	for i in temparr:
		arr.append(i)
	arr01 = []
	arr10 = []
	for i in range(n):
		if i & 1:
			arr01.append('1')
		else:
			arr01.append('0')
	for i in range(n):
		if i & 1:
			arr10.append('0')
		else:
			arr10.append('1')
	count01 = 0
	count10 = 0
	flag = 0
	for i in range(n):
		if arr01[i] == arr[i] and flag == 1:
			flag = 0
		elif arr01[i] != arr[i] and flag == 0:
			flag = 1
			count01 += 1
		elif arr01[i] != arr[i] and flag == 1:
			continue
	flag = 0
	for i in range(n):
		if arr10[i] == arr[i] and flag == 1:
			flag = 0
		elif arr10[i] != arr[i] and flag == 0:
			flag = 1
			count10 += 1
		elif arr10[i] != arr[i] and flag == 1:
			continue
	print(min(count10, count01))


def solve():
	n = int(input().strip())
	s = input().strip()
	prev = '0'
	ans1 = 0
	for i in s:
		if prev == i == '1':
			ans1 += 1
		prev = i
	prev = '1'
	ans2 = 0
	for i in s:
		if prev == i == '0':
			ans2 += 1
		prev = i
	print(max(ans1, ans2))
t = int(input())
for _ in range(t):
	solve()


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		s = input()
		arr = s.split('0')
		arr2 = s.split('1')
		ans1 = 0
		ans2 = 0
		for x in arr:
			if len(x) > 0 and x[0] == '1':
				ans1 += len(x) - 1
		for x in arr2:
			if len(x) > 0 and x[0] == '0':
				ans2 += len(x) - 1
		print(max(ans1, ans2))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	s = insr() + 'q'
	q = []
	c = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '1':
			c = c + 1
		elif s[i] == '1':
			q.append(c)
			c = 1
	w = []
	c = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] and s[i] == '0':
			c = c + 1
		elif s[i] == '0':
			w.append(c)
			c = 1
	print(max(sum(q) - len(q), sum(w) - len(w)))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

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

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

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

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

def ceil(a, b):
	return -(-a // b)

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	a = s.count('10')
	b = s.count('01')
	h = n // 2
	print(h - max([a, b]))


for _ in range(int(input())):
	waste = int(input())
	s = input()
	(a, b) = (0, 1)
	l = []
	for x in s:
		if s[0] == '1':
			y = int(x)
			l.append(b ^ y)
		else:
			y = int(x)
			l.append(a ^ y)
		b = 1 - b
		a = 1 - a
	cnt = 0
	for i in range(1, waste):
		if l[i] == 1 and l[i - 1] == 0:
			cnt += 1
	if waste >= 4:
		print(cnt)
	else:
		print('0')


t = int(input())
while t:
	t -= 1
	n = int(input())
	str = input()
	count = 0
	count1 = 0
	for i in range(n - 1):
		if str[i] == str[i + 1] and str[i] == '1':
			count += 1
		elif str[i] == str[i + 1] and str[i] == '0':
			count1 += 1
	print(max(count, count1))


for s in [*open(0)][2::2]:
	print(len(s) // 2 - len([*filter(None, s[:-1].split(s[0]))]))


f = int(input())
for i10 in range(f):
	n = int(input())
	s = input()
	if s[0] == '0' and s[-1] == '0':
		k = '1'
	else:
		k = '0'
	c = 0
	for i in range(1, n):
		if s[i] == s[i - 1] and s[i] == k:
			c += 1
	print(c)


from sys import stdin
import math
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr = list(stdin.readline().strip())
	ref_1 = True
	ref_2 = False
	last_i_1 = -1
	changes_1 = 0
	last_i_2 = -1
	changes_2 = 0
	for i in range(n):
		if arr[i] == '1' and (not ref_1) or (arr[i] == '0' and ref_1):
			if last_i_1 != i - 1 or last_i_1 == -1:
				changes_1 += 1
			last_i_1 = i
		ref_1 = not ref_1
		if arr[i] == '1' and (not ref_2) or (arr[i] == '0' and ref_2):
			if last_i_2 != i - 1 or last_i_2 == -1:
				changes_2 += 1
			last_i_2 = i
		ref_2 = not ref_2
	print(min(changes_1, changes_2))


import sys, os, io
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for tc in range(1, 1 + int(I())):
	n = int(I())
	s = I().rstrip()
	c = {ord('0'): 0, ord('1'): 0}
	for i in range(1, n):
		if s[i] == s[i - 1]:
			c[s[i]] += 1
	print(max(c.values()))


import math
import os
import random
import re
import sys

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = str(input())
		xs = [int(x) for x in s]
		one_count = 0
		zero_count = 0
		for i in range(len(xs) - 1):
			if xs[i] == 0 and xs[i + 1] == 0:
				zero_count += 1
			elif xs[i] == 1 and xs[i + 1] == 1:
				one_count += 1
			pass
		print(max(one_count, zero_count))
result = solve()


from collections import deque, defaultdict

def solve():
	n = int(input())
	s = input()
	z = f = ansz = ansf = 0
	for i in range(n):
		if i % 2 != int(s[i]):
			z += 1
			if f != 0:
				ansf += 1
			f = 0
		else:
			f += 1
			if z != 0:
				ansz += 1
			z = 0
	if z != 0:
		ansz += 1
	if f != 0:
		ansf += 1
	print(min(ansz, ansf))

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


for _ in range(int(input())):
	n = int(input())
	s = input()
	d = 0
	e = 0
	for i in range(1, n):
		if s[i - 1] == s[i] == '1':
			d += 1
		if s[i - 1] == s[i] == '0':
			e += 1
	print(max(d, e))


from sys import stdin, stdout
from math import factorial as f
for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 1
	for i in range(n):
		if not i or s[i] == s[i - 1]:
			continue
		cnt += 1
	print((n - cnt + 1) // 2)


import math
t = int(input())
for x in range(t):
	n = int(input())
	a = input()
	subsets = []
	subset = [a[0]]
	if n == 2:
		print(0)
	else:
		for i in range(1, n):
			if a[i] != a[i - 1]:
				subset.append(a[i])
			else:
				subsets.append(subset)
				subset = [a[i]]
			if i == n - 1:
				subsets.append(subset)
		print(int(math.floor(len(subsets) / 2)))


for tt in range(int(input())):
	n = int(input())
	s = input()
	c = s[0]
	ans = 1
	for i in range(1, n):
		if s[i] == c:
			ans += 1
		c = s[i]
	print(ans // 2)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = 0
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			c += 1
	x = n - 1 - c
	ans = math.ceil(x / 2)
	print(ans)


test = int(input())
for _ in range(test):
	n = int(input())
	s = list(input())
	freq1 = [1]
	freq0 = [1]
	for i in range(1, n):
		if s[i] == '1':
			if s[i - 1] == '1':
				freq1[-1] += 1
			else:
				freq1.append(1)
		elif s[i - 1] == '0':
			freq0[-1] += 1
		else:
			freq0.append(1)
	op1 = 0
	for f in freq1:
		if f > 1:
			op1 += f - 1
	op0 = 0
	for f in freq0:
		if f > 1:
			op0 += f - 1
	print(max(op1, op0))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	s = ips()
	s1 = '1' + s + '0'
	(ct1, ct0) = (0, 0)
	for i in range(len(s1) - 1):
		if s1[i] == '1' and s1[i + 1] == '1':
			ct1 += 1
		if s1[i] == '0' and s1[i + 1] == '0':
			ct0 += 1
	ans1 = min(ct1, ct0)
	(ct1, ct0) = (0, 0)
	s2 = '0' + s + '1'
	for i in range(len(s1) - 1):
		if s2[i] == '1' and s2[i + 1] == '1':
			ct1 += 1
		if s2[i] == '0' and s2[i + 1] == '0':
			ct0 += 1
	ans2 = min(ct1, ct0)
	ans = min(ans1, ans2)
	out(ans)


for _ in range(0, int(input())):
	n = int(input())
	a = [int(i) for i in input()]
	count = 0
	mount = 0
	for i in range(0, len(a) - 1):
		if a[i] == 0 and a[i + 1] == 0:
			count += 1
		elif a[i] == 1 and a[i + 1] == 1:
			mount += 1
	print(max(mount, count))


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	a = input()
	a = list(map(int, list(a)))
	b = [a[0]]
	one = 0
	zero = 0
	for i in range(1, n):
		if len(b) >= 1:
			if b[-1] != a[i]:
				b.pop(-1)
				b.append(a[i])
			else:
				b.append(a[i])
		else:
			b.append(a[i])
	for i in b:
		if i == 1:
			one += 1
		else:
			zero += 1
	print(min(one, zero))


for _ in range(int(input())):
	n = int(input())
	a = input()
	count = 0
	flag = 0
	for i in range(n - 1):
		if a[i] == '1' and a[i] == a[i + 1]:
			count += 1
		if a[i] == '0' and a[i] == a[i + 1]:
			flag += 1
	print(max(count, flag))


def solve():
	n = int(input())
	s = str(input())
	s1 = '1' + s + '0'
	s2 = '0' + s + '1'
	(dif1, dif2) = (0, 0)
	for i in range(1, n + 2):
		if s1[i - 1] == s1[i]:
			dif1 += 1
		if s2[i - 1] == s2[i]:
			dif2 += 1
	print(min(dif1 // 2, dif2 // 2))
t = int(input())
for q in range(t):
	solve()


def f(s):
	n = len(s)
	m = 1
	for i in range(n - 1):
		if s[i] + s[i + 1] == '10':
			m += 1
	if s[-1] == '0':
		m -= 1
	return m
for i in range(int(input())):
	n = int(input())
	s = input()
	l = '01' * (n // 2)
	q = ''
	w = ''
	for i in range(n):
		if s[i] == l[i]:
			q += '0'
			w += '1'
		else:
			q += '1'
			w += '0'
	print(min(f(q), f(w)))


from collections import deque
import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		s = Istr()
		(z, o) = (0, 0)
		a = 0
		is_zero = s[0] == '0'
		for si in s[1:]:
			if is_zero and si == '0':
				z += 1
			elif not is_zero and si == '1':
				o += 1
			elif is_zero and si == '1':
				a += z
				z = 0
				is_zero = False
			elif not is_zero and si == '0':
				a += o
				o = 0
				is_zero = True
		a += z + o
		if a % 2 == 0:
			print(a // 2)
		else:
			print((a + 1) // 2)
en = enumerate
FIO = 0

def debug(*args, c=6):
	pass
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=sys.stderr)
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

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')
main()


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	s = input()
	z = 0
	o = 0
	k = 0
	while k < n:
		j = k
		while j < n and s[j] == s[k]:
			j = j + 1
		if s[k] == '1':
			o += j - k - 1
		else:
			z += j - k - 1
		k = j
	print(max(o, z))


a = int(input())
for i in range(a):
	n = int(input())
	s = input()
	arr = [int(i) for i in s]
	count1 = 0
	for i in range(0, len(arr) - 1):
		if arr[i] == arr[i + 1] and arr[i + 1] == 1:
			count1 = count1 + 1
	count2 = 0
	for i in range(0, len(arr) - 1):
		if arr[i] == arr[i + 1] and arr[i + 1] == 0:
			count2 = count2 + 1
	print(max(count1, count2))


for i in range(int(input())):
	n = int(input())
	s = input()
	o_s = 0
	z_s = 0
	for j in range(n - 1):
		if s[j] == '0' and s[j + 1] == '0':
			z_s += 1
		elif s[j] == '1' and s[j + 1] == '1':
			o_s += 1
	print(max(o_s, z_s))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	s = list(data())
	answer = 0
	pos = [0] * n
	for i in range(n):
		if i % 2 != int(s[i]) % 2:
			pos[i] = 1
	answer = int(pos[0] == 1)
	for i in range(1, n):
		if pos[i] == pos[i - 1] == 1:
			continue
		if pos[i] == 1:
			answer += 1
	pos = [0] * n
	temp = 0
	for i in range(n):
		if i % 2 == int(s[i]) % 2:
			pos[i] = 1
	temp = int(pos[0] == 1)
	for i in range(1, n):
		if pos[i] == pos[i - 1] == 1:
			continue
		if pos[i] == 1:
			temp += 1
	out(min(temp, answer))


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = '10' * (n // 2)
	y = '01' * (n // 2)
	a = 0
	b = 0
	cnt = 0
	for i in range(n):
		if s[i] != x[i]:
			cnt += 1
		elif cnt != 0:
			cnt = 0
			a += 1
	if cnt != 0:
		a += 1
	cnt = 0
	for i in range(n):
		if s[i] != y[i]:
			cnt += 1
		elif cnt != 0:
			cnt = 0
			b += 1
	if cnt != 0:
		b += 1
	print(min(a, b))


for c in range(int(input())):
	a = int(input())
	b = input()
	l = []
	for y in b:
		l.append(y)
	i = 0
	j = 1
	if l[0] == '1' and l[-1] == '1':
		i += 1
	for t in range(1, a):
		if l[t - 1] == '0':
			j += 1
			l[t - 1] = j
		if l[t - 1] == l[t]:
			i += 1
	print(i)


def swap_func(s):
	oneCount = 0
	zeroCount = 0
	for i in range(len(s)):
		if i + 1 < len(s):
			if s[i] == '1' and s[i + 1] == '1':
				oneCount += 1
			if s[i] == '0' and s[i + 1] == '0':
				zeroCount += 1
	min_swap = max(oneCount, zeroCount)
	return min_swap
t = int(input())
temp_arr = []
for i in range(t):
	n = int(input())
	s = str(input())
	min_swap = swap_func(s)
	temp_arr.append(min_swap)
for j in temp_arr:
	print(j)


cases = int(input())
for i in range(0, cases):
	num = int(input())
	mylist = [char for char in input()]
	mylist2 = []
	mylist3 = []
	for j in range(0, num):
		if j % 2 == 0:
			if mylist[j] == '0':
				mylist2.append(0)
				mylist3.append(1)
			else:
				mylist2.append(1)
				mylist3.append(0)
		elif mylist[j] == '1':
			mylist2.append(0)
			mylist3.append(1)
		else:
			mylist2.append(1)
			mylist3.append(0)
	count1 = 0
	count2 = 0
	j = 0
	while j < num:
		if mylist2[j] == 0:
			count1 += 1
			while j < num and mylist2[j] == 0:
				j += 1
		else:
			while j < num and mylist2[j] == 1:
				j += 1
	j = 0
	while j < num:
		if mylist3[j] == 0:
			count2 += 1
			while j < num and mylist3[j] == 0:
				j += 1
		else:
			while j < num and mylist3[j] == 1:
				j += 1
	if count2 > count1:
		print(count1)
	else:
		print(count2)


testes = int(input())
while testes:
	testes -= 1
	tamanho = int(input())
	string = input()
	corretos = string.count('01') + string.count('10')
	errados = tamanho - corretos
	print(errados // 2)


n = int(input())
for _ in range(n):
	a = float(input())
	b = str(input())
	print(int((a - b.count('10') - b.count('01')) // 2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	temp = 0
	temp2 = 0
	arr = []
	arr2 = []
	for i in range(n):
		if s[i] == '1':
			temp += 1
		elif temp > 0:
			arr.append(temp)
			temp = 0
		if s[i] == '0':
			temp2 += 1
		elif temp2 > 0:
			arr2.append(temp2)
			temp2 = 0
	print(max(sum(arr) - len(arr), sum(arr2) - len(arr2)))


def counting(s, t):
	n = len(s)
	n1 = len(t)
	count = 0
	for i in range(n - n1 + 1):
		if s[i:i + n1] == t:
			count += 1
	return count
for i in range(int(input())):
	n = int(input())
	s = input()
	c1 = counting(s, '11')
	c2 = counting(s, '00')
	print(max(c1, c2))


import sys
from collections import deque
from copy import *
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

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

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

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

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

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

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	s = si()
	ans = [0, 0]
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			continue
		else:
			ans[int(s[i])] += 1
	print(max(ans))


from sys import stdin
for _ in range(int(stdin.readline())):
	l = int(stdin.readline())
	string = stdin.readline().strip()
	ans = 0
	wrong1 = 0
	wrong0 = 0
	for i in range(1, l):
		if string[i] == string[i - 1] and string[i] == '1':
			wrong1 += 1
		elif string[i] == string[i - 1] and string[i] == '0':
			wrong0 += 1
	ans = max(wrong1, wrong0)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	count = 0
	b = s[0]
	for i in range(1, n):
		if b == s[i]:
			count += 1
		b = s[i]
	if count % 2 != 0:
		count -= 1
		print(count // 2 + 1)
	else:
		print(count // 2)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def isPrime(num):
	if num > 1:
		for i in range(2, num):
			if num % i == 0:
				return False
		return True
	else:
		return False

def calcSumPrime(n):
	s = 1
	for i in range(1, n + 1):
		if isPrime(i) == True:
			s = s * i
	return s

def main():
	t = inp()
	while t > 0:
		t -= 1
		n = inp()
		s = insr()
		(s0, s1) = (0, 0)
		for i in range(0, n):
			if s[i] == '0':
				if i + 1 < n and s[i + 1] == '0':
					s0 += 1
			elif i + 1 < n and s[i + 1] == '1':
				s1 += 1
		ans = 0
		if s0 > 0 or s1 > 0:
			ans = max(s0, s1)
		print(ans)
input = sys.stdin.readline
main()


match = int(input())
for t in range(match):
	n = int(input())
	s = input()
	s1 = '1' + s + '0'
	s2 = '0' + s + '1'
	ans1 = 0
	ans2 = 0
	for i in range(1, n + 2):
		if s1[i - 1] == s1[i]:
			ans1 += 1
	for i in range(1, n + 2):
		if s2[i - 1] == s2[i]:
			ans2 += 1
	ans = min(ans1, ans2)
	print(int(ans / 2))


import sys, os.path
from collections import *
from heapq import *
from copy import *
import math
mod = 10 ** 9 + 7
read = lambda : map(int, input().split())
inf = float('inf')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	s = input()
	res = []
	for i in s:
		res.append(i)
	c = 0
	c1 = 0
	for i in range(n - 1):
		if res[i] == res[i + 1] == '1':
			c += 1
	for i in range(n - 1):
		if res[i] == res[i + 1] == '0':
			c1 += 1
	print(max(c, c1))


def solve():
	n = int(input())
	s = input()
	if n == 2:
		print(0)
		return
	else:
		oneCount = 0
		zeroCount = 0
		i = 0
		if s[0] == '0':
			i += 1
		while s[i] == '0':
			i += 1
			zeroCount += 1
		while i < n:
			while i < n and s[i] == '1':
				i += 1
			if i == n:
				break
			if s[i] == '0':
				i += 1
			while i < n and s[i] == '0':
				i += 1
				zeroCount += 1
		i = 0
		if s[0] == '1':
			i += 1
		while s[i] == '1':
			i += 1
			oneCount += 1
		while i < n:
			while i < n and s[i] == '0':
				i += 1
			if i == n:
				break
			if s[i] == '1':
				i += 1
			while i < n and s[i] == '1':
				i += 1
				oneCount += 1
		print(max(zeroCount, oneCount))
for _ in range(int(input())):
	solve()


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input()))
	cnt = 0
	x = 0
	while x < n - 1:
		if arr[x] == arr[x + 1]:
			cnt += 1
			for z in range(x + 1, n - 1):
				if arr[z] == arr[z + 1]:
					arr[z] ^= 1
					x = z - 1
					break
		x += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(a1, a0, c0, c1) = (0, 0, 0, 0)
	for i in range(n):
		if s[i] == '1':
			c1 += 1
			if c0:
				a0 += c0 - 1
			c0 = 0
		else:
			c0 += 1
			if c1:
				a1 += c1 - 1
			c1 = 0
	print(max(a1, a0))


for _ in range(int(input())):
	n = int(input())
	count = 0
	num = input()
	for i in range(int(n - 1)):
		if num[i] == num[i + 1]:
			count += 1
	if count % 2 == 0:
		print(count // 2)
	else:
		print(count // 2 + 1)


def answer():
	m = int(input())
	a = [int(i) for i in str(input())]
	count = 0
	count1 = 0
	for i in range(m - 1):
		if a[i] == a[i + 1]:
			if a[i]:
				count1 += 1
			else:
				count += 1
	print(max(count, count1))
test = int(input())
while test:
	answer()
	test -= 1


import sys
from math import ceil
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	(c, i) = (0, 0)
	while i < len(s) - 1:
		if s[i] == s[i + 1]:
			c += 1
		i += 1
	print(int(ceil(c / 2)))


n = int(input())
result = []
for i in range(n):
	lenlen = input()
	count0 = 0
	count1 = 0
	str = input()
	prev = str[0]
	cur_len = 0
	len_opr = '0'
	for i in range(1, len(str) - 1):
		ch = str[i]
		if prev == ch:
			len_opr = ch
			cur_len += 1
		else:
			if len_opr == '0':
				count0 += cur_len
			else:
				count1 += cur_len
			cur_len = 0
		prev = ch
	if len_opr == '0':
		count0 += cur_len
	else:
		count1 += cur_len
	result.append(max(count1, count0))
for i in result:
	print(i)


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

def main():
	t = int(input())
	while t:
		x = int(input())
		s = input()
		c = 0
		for i in range(x - 1):
			if s[i] == s[i + 1]:
				c += 1
		print(math.ceil(c / 2))
		t -= 1
main()


number = input()
i = 0
while i < int(number):
	useless = input()
	inputboi = str(input())
	zboi = inputboi.split('1')
	oboy = inputboi.split('0')
	kekw = sum([len(smolboi) - 1 if smolboi else 0 for smolboi in zboi])
	ecksdee = sum([len(smolboi) - 1 if smolboi else 0 for smolboi in oboy])
	print(max(kekw, ecksdee))
	i += 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	y = 0
	for i in range(0, n - 1):
		if s[i] + s[i + 1] == '00':
			y += 1
		elif s[i] + s[i + 1] == '11':
			x += 1
	print(max(x, y))


from math import ceil as c
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	flag = 0
	for i in range(1, len(s)):
		if s[i - 1] == s[i]:
			flag += 1
	print(c(flag / 2))


import math
for _ in range(int(input())):
	n = int(input())
	k = input()
	pair = 0
	for i in range(n - 1):
		if k[i] == '1' and k[i + 1] == '1':
			pair += 1
		if k[i] == '0' and k[i + 1] == '0':
			pair += 1
	print(math.ceil(pair / 2))


import sys
tests = int(sys.stdin.readline())
for _ in range(tests):
	_ = int(sys.stdin.readline())
	n = sys.stdin.readline()
	count = 0
	last_c = 'X'
	for c in n:
		if last_c == c:
			count += 1
		last_c = c
	print(int((count + 1) // 2))


import math
tc = int(input())
while tc:
	length = input()
	string = input()
	chars = [x for x in string]
	count = 0
	for x in range(len(chars) - 1):
		if chars[x] == chars[x + 1]:
			count += 1
	print(math.ceil(count / 2))
	tc -= 1


t = int(input())
len = 0
ans = 0
sameLen = 0
last = ''
bin = ''
for i in range(t):
	len = int(input())
	bin = input()
	ans = 0
	sameLen = 1
	last = bin[0]
	for j in range(1, len):
		if bin[j] == bin[j - 1]:
			ans += 1
	if bin[0] == bin[-1]:
		ans += 1
	ans /= 2
	ans = int(ans)
	print(ans)


t = int(input())
for i in range(t):
	k = int(input())
	s = input()
	last = s[0]
	kol = 1
	k1 = 0
	k2 = 0
	for i in range(1, k):
		if s[i] == last:
			kol += 1
		else:
			if s[i] == '1':
				k1 += kol - 1
			else:
				k2 += kol - 1
			kol = 1
			last = s[i]
	print(max(k1, k2))


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
mod = 10 ** 9 + 7

def main():
	ans = ''
	for _ in range(int(input())):
		n = int(input())
		s = input().strip()
		ans += str(n // 2 - max(s.count('10'), s.count('01'))) + '\n'
	print(ans)
main()


import math
n = int(input())
for w in range(n):
	a = int(input())
	s = input()
	c = 0
	flag = 0
	for i in range(1, a):
		if s[i] == s[i - 1]:
			c += 1
	print(math.ceil(c / 2))


def func_name(temp_input1):
	x = 0
	y = 0
	for i in range(len(temp_input1)):
		if i + 1 < len(temp_input1):
			if temp_input1[i] == '1' and temp_input1[i + 1] == '1':
				x += 1
			if temp_input1[i] == '0' and temp_input1[i + 1] == '0':
				y += 1
	min_value = max(x, y)
	return min_value
t = int(input())
temp_array = []
for i in range(t):
	temp_input = int(input())
	temp_input1 = input()
	min_value = func_name(temp_input1)
	print(min_value)


import math

def solve():
	N = int(input())
	string = str(input())
	Ans = (N - (string.count('10') + string.count('01'))) // 2
	print(Ans)
Testcase = 1
Testcase = int(input())
for _ in range(Testcase):
	solve()


from math import *
a = int(input())
for x in range(a):
	c = int(input())
	b = input()
	d = 0
	for y in range(c - 1):
		if b[y] == b[y + 1]:
			d += 1
	print(ceil(d / 2))


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	(l, r) = (1, n - 2)
	while r > l:
		if s[l] != s[r]:
			if s[l] == s[l - 1] or s[r] == s[r + 1]:
				ans += 1
		else:
			ans += s[l] == s[l - 1] and s[r] == s[r + 1]
		l += 1
		r -= 1
	print(ans + 1 if s[r] == s[l] else ans)


t = int(input())
while t:
	zero = 0
	one = 0
	size = int(input())
	array = list(map(int, input()))
	for i in range(len(array) - 1):
		if array[i] == 1 and array[i + 1] == 1:
			one += 1
		if array[i] == 0 and array[i + 1] == 0:
			zero += 1
	print(max(one, zero))
	t -= 1


import sys
import math
input = sys.stdin.readline

def get_int():
	return int(input().strip())

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

def get_char_list():
	return list(input().strip())
cases = get_int()
for _ in range(cases):
	n = get_int()
	ds = get_char_list()
	one = 0
	zero = 0
	for i in range(1, n):
		if ds[i] == '1' and ds[i - 1] == '1':
			one += 1
		elif ds[i] == '0' and ds[i - 1] == '0':
			zero += 1
	print(max(one, zero))


t = int(input())
answer = []
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	d = 0
	for j in range(len(s) - 1):
		if s[j] == '1' and s[j + 1] == '1':
			c += 1
		elif s[j] == '0' and s[j + 1] == '0':
			d += 1
	maximum = max(c, d)
	answer.append(maximum)
for i in answer:
	print(i)


t = int(input())
while t:
	n = int(input())
	s = list(input())
	x = ans = ans1 = 0
	while x < n - 1:
		if s[x] == s[x + 1] and s[x] == '1':
			ans += 1
		if s[x] == s[x + 1] and s[x] == '0':
			ans1 += 1
		x += 1
	print(max(ans, ans1))
	t -= 1


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = input().strip()
	c = 0
	d = 0
	for i in range(1, n):
		if a[i] == a[i - 1] and a[i] == '1':
			c += 1
		if a[i] == a[i - 1] and a[i] == '0':
			d += 1
	print(max(c, d))
for _ in range(I()):
	solve()


try:
	for _ in range(int(input())):
		n = int(input())
		l = list(input())
		ls1 = []
		ls0 = []
		ans = ans1 = 0
		for i in range(0, n):
			if l[i] == '1':
				ls1.append(i)
			else:
				ls0.append(i)
		for i in range(len(ls1) - 1):
			if ls1[i + 1] - ls1[i] == 1:
				ans += 1
		for i in range(len(ls0) - 1):
			if ls0[i + 1] - ls0[i] == 1:
				ans1 += 1
		print(max(ans, ans1))
except:
	pass


for q in range(int(input())):
	n = int(input())
	s = input()
	ans1 = 0
	ans2 = 0
	for i in range(0, n - 1):
		if s[i:i + 2] == '11':
			ans1 += 1
		elif s[i:i + 2] == '00':
			ans2 += 1
	print(max(ans1, ans2))


for _ in range(int(input())):
	n = int(input())
	arr = input()
	repz = 0
	tempz = int(arr[0])
	for i in range(1, n):
		if int(arr[i]) == 0:
			if int(arr[i]) == tempz:
				repz += 1
			else:
				tempz = int(arr[i])
		else:
			tempz = int(arr[i])
	repo = 0
	tempo = int(arr[0])
	for i in range(1, n):
		if int(arr[i]) == 1:
			if int(arr[i]) == tempo:
				repo += 1
			else:
				tempo = int(arr[i])
		else:
			tempo = int(arr[i])
	if repo > repz:
		print(repo)
	else:
		print(repz)


def solve():
	n = int(input())
	st = input()
	ans = 0
	for i in range(len(st) - 1):
		if st[i] == st[i + 1]:
			ans = ans + 1
	print((ans + 1) // 2)
t = int(input())
while t > 0:
	solve()
	t = t - 1


import sys, math
from heapq import *
from collections import defaultdict as dd
mod = 10 ** 9 + 7
modd = 998244353
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n,) = inp()
	a = str(input())
	ans = 0
	for i in range(n):
		ans += 1 * (a[i] == a[(i + 1) % n])
	print(ans // 2)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = 0
	b = 0
	l = '-1'
	for i in s:
		if i == l == '0':
			a += 1
		elif i == l == '1':
			b += 1
		l = i
	print(max(a, b))


for _ in range(int(input())):
	N = int(input())
	S = input()
	count = 0
	for i in range(1, N):
		if S[i] == S[i - 1]:
			count += 1
	if count % 2 == 0:
		print(count // 2)
	else:
		print(count // 2 + 1)


for _ in range(int(input())):
	z = int(input())
	s = input()
	ans = 0
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			ans += 1
	print(ans // 2 + ans % 2)


n = int(input())

def c1(L, s):
	k = ''
	c = 0
	for i in range(L):
		k += str((i % 2 + int(s[i])) % 2)
	for i in range(L):
		if i > 0 and k[i] != k[i - 1]:
			c += 1
	return c // 2 + c % 2
for i in range(n):
	L = int(input())
	s = input()
	a = 0
	b = 0
	print(c1(L, s))


for t in range(int(input())):
	n = int(input())
	s = input()
	f = ans = 0
	c = 0
	for i in range(n):
		if s[i] == '1':
			c += 1
		if s[i] == '0':
			f = 0
			if c > 0:
				ans += c - 1
			c = 0
	c = 0
	f = ans2 = 0
	for i in range(n):
		if s[i] == '0':
			c += 1
		if s[i] == '1':
			f = 0
			if c > 0:
				ans2 += c - 1
			c = 0
	print(max(ans, ans2))


n = int(input())
for i in range(n):
	m = int(input())
	s = input()
	pr = -1
	(cnt0, cnt1) = (0, 0)
	for i in range(1, m):
		vl = 0 if s[i] == '0' else 1
		pr = 0 if s[i - 1] == '0' else 1
		if vl == pr:
			if vl == 0:
				cnt0 += 1
			else:
				cnt1 += 1
	print(max(cnt0, cnt1))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	co = 0
	cz = 0
	for j in range(n - 1):
		if s[j] == s[j + 1] and s[j] == '1':
			co = co + 1
		if s[j] == s[j + 1] and s[j] == '0':
			cz = cz + 1
	print(max(co, cz))


t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	count0 = 0
	count1 = 0
	flag0 = False
	flag1 = False
	for i in s:
		if i == '0' and flag0 and (not flag1):
			count0 += 1
		elif i == '0' and (not flag0):
			flag0 = True
			flag1 = False
		elif i == '1' and (not flag0) and flag1:
			count1 += 1
		else:
			flag0 = False
			flag1 = True
	print(max(count0, count1))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
t = int(input())
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	(cnt, ans1, ans2) = (0, 0, 0)
	for i in range(n):
		if s[i] == '1':
			cnt += 1
		else:
			ans1 += max(0, cnt - 1)
			cnt = 0
	ans1 += max(0, cnt - 1)
	cnt = 0
	for i in range(n):
		if s[i] == '0':
			cnt += 1
		else:
			ans2 += max(0, cnt - 1)
			cnt = 0
	ans2 += max(0, cnt - 1)
	print(max(ans1, ans2))
for _ in range(t):
	n = int(input())
	s = input()
	solve()


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def main():
	try:
		for _ in range(inp()):
			n = inp()
			s = input()
			count = 0
			if n == 2:
				if s == '01' or s == '10':
					print('0')
				else:
					print('1')
				continue
			for i in range(1, n):
				if s[0] == '1':
					if s[i] == '0' and s[i - 1] == '1':
						count += 1
				elif s[i] == '1' and s[i - 1] == '0':
					count += 1
			print(n // 2 - count)
	except Exception as e:
		print(e)
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()
	co = 0
	mi1 = 0
	mi2 = 0
	for i in range(1, n, 1):
		if s[i] == s[i - 1] and s[i] == '1':
			co += 1
		else:
			mi1 += co
			co = 0
	mi1 += co
	co = 0
	for i in range(1, n, 1):
		if s[i] == s[i - 1] and s[i] == '0':
			co += 1
		else:
			mi2 += co
			co = 0
	mi2 += co
	print(max(mi1, mi2))


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	n = IN()
	s = S()
	a = s.split('0')
	b = s.split('1')
	x = 0
	for i in a:
		if len(i):
			x += len(i) - 1
	for i in b:
		if len(i):
			x += len(i) - 1
	print((x + 1) // 2)
for _ in range(IN()):
	case()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().replace('', ' ').split()))
	count1 = 0
	maxcount1 = 0
	count0 = 0
	maxcount0 = 0
	for i in a:
		if i == 0:
			count0 += 1
			if count1 > 1:
				maxcount1 += count1 - 1
			count1 = 0
		else:
			if count0 > 1:
				maxcount0 += count0 - 1
			count1 += 1
			count0 = 0
	print(max(maxcount1, maxcount0))


from sys import stdin, stdout
n = int(stdin.readline())

def calculate(length, sequence):
	count = 0
	for i in range(length - 1):
		if sequence[i] == sequence[i + 1]:
			count += 1
	return count // 2
for _ in range(n):
	length = int(stdin.readline())
	sequence = stdin.readline().strip()
	stdout.write(str(min(calculate(length + 2, '0' + sequence + '1'), calculate(length + 2, '1' + sequence + '0'))) + '\n')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def give(l):
	l1 = [[l[0], 1]]
	for i in l[1:]:
		if i == l1[-1][0]:
			l1[-1][1] += 1
		else:
			l1.append([i, 1])
	return l1[:]
for _ in range(val()):
	n = val()
	l = give(li3())
	ans = left1 = left2 = 0
	for i in range(1, len(l), 2):
		(a, b) = (l[i - 1][1] + left1, l[i][1] + left2)
		ans += min(a, b) - 1
		(left1, left2) = (a - min(a, b), b - min(b, a))
	print(ans + max(left1, left2))


for w in [*open(0)][2::2]:
	c = 1
	for i in range(len(w) - 1):
		if w[i] == w[i + 1]:
			c += 1
	print(c // 2)


for testCase in range(int(input())):
	n = int(input())
	s = input()
	if n == 2:
		print(0)
		continue
	print((n - s.count('01') - s.count('10')) // 2)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	S = input().strip()
	bef = S[0]
	cnt = 0
	for s in S[1:]:
		if bef == s:
			cnt += 1
		bef = s
	print((cnt + 1) // 2)
for _ in range(int(input())):
	main()