def count_swaps(s):
# initialize the counts of zeros and ones
zeros = 0
ones = 0
# loop through the string from left to right
for c in s:
# if the character is zero, increment the zeros count
if c == '0':
zeros += 1
# if the character is one, increment the ones count
else:
ones += 1
# the minimum number of swaps is the minimum of zeros and ones
return min(zeros, ones)
# read the number of test cases
t = int(input())
# loop through the test cases
for _ in range(t):
# read the size of the string
n = int(input())
# read the string
s = input()
# print the minimum number of swaps
print(count_swaps(s))