package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	io := bufio.NewReader(os.Stdin)
	var t, n int
	var str string
	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n)
		res := 0
		fmt.Fscan(io, &str)
		prev := 'a'
		for _, r := range str {
			if r == prev {
				res++
			}
			prev = r
		}
		fmt.Println((res + res%2) / 2)
	}
}

package main

import (
  . "fmt"
  //"os"
  //"bufio"
)

func main() {
  var t int
  Scan(&t)

  for i := 0; i < t; i++ {
    var n int
    Scan(&n)
    var s string
    Scan(&s)
    s = " " + s

    var c0, c1 int

    for i := 1; i < n; i++ {
      if s[i] == '0' && s[i] == s[i - 1] {
        c0++
      } else if s[i] == '1' && s[i] == s[i - 1] {
        c1++
      }
    }

    Max := func(a, b int) int {
      if a > b {return a}
      return b
    }

    Println(Max(c0, c1))
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var Writer = bufio.NewWriter(os.Stdout)
var Reader = bufio.NewReader(os.Stdin)

func Print(args ...interface{}) {
	fmt.Fprint(Writer, args...)
}

func Scan(args ...interface{}) {
	fmt.Fscan(Reader, args...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func countDoubles(a string, val byte) (cnt int) {
	for i := 1; i < len(a); i++ {
		if a[i] == val && a[i] == a[i-1] {
			cnt++
		}
	}
	return
}

func main() {
	defer Writer.Flush()

	var t int
	Scan(&t)
	for t != 0 {
		var n int
		Scan(&n)
		var s string
		Scan(&s)
		Print(max(countDoubles(s, '0'), countDoubles(s, '1')), "\n")
		t--
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := make([]int, 2)
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if mainCondition && string(stringBinary[index][i]) == "0" {
			operations[0]++
		}
		if mainCondition && string(stringBinary[index][i]) == "1" {
			operations[1]++
		}
	}
	return max(operations)
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func max(list []int) int {
	max := list[0]
	for _, elem := range list[1:] {
		if elem > max {
			max = elem
		}
	}
	return max
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuousA, continuous_maxA int
		var continuousB, continuous_maxB int
		var last byte

		last = tmp[0]
		for i := 1; i < len(tmp); i++ {
			if tmp[i] == last {
				if tmp[i] == '1' {
					continuousA++
				} else {
					continuousB++
				}
			} else {

				continuous_maxA += continuousA
				continuousA = 0
				continuous_maxB += continuousB
				continuousB = 0
				last = tmp[i]
			}
		}

		continuous_maxA += continuousA
		continuous_maxB += continuousB

		Fprintln(out, max(continuous_maxA, continuous_maxB))

	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func ReverseString1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func solve() {
	var n int
	scanf("%d\n", &n)
	var s string
	scanf("%s\n", &s)
	cnt0 := 0
	cnt1 := 0
	for i := 0; i + 1 < len(s); i++ {
		if s[i] == s[i + 1] {
			if s[i] == '0' {
				cnt0++
			} else {
				cnt1++
			}
		}
	}
	ans := cnt0
	if cnt1 > ans {
		ans = cnt1
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func min_int(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func min_int64(a int64, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func max_int(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func max_int64(a int64, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n int = 0
		scanf("%d\n", &n)

		var s string
		scanf("%s\n", &s)

		s = strings.TrimRight(s, "\n")

		var n_one_blocks int = 0
		var n_zero_blocks int = 0

		for i := 1; i < len(s); i++ {

			if s[i-1] == s[i] {
				if string(s[i]) == "0" {
					n_zero_blocks++
				} else {
					n_one_blocks++
				}
			}

		}

		// printf("%d %d\n", n_one_blocks, n_zero_blocks)
		var res int = max_int(n_one_blocks, n_zero_blocks)
		printf("%d\n", res)

	}

}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
	"fmt"
)

func main() {
	// Write your solution here
	var t int
	fmt.Scanf("%d\n", &t)

	for ;t>0; t--{
		var n int
		fmt.Scanf("%d\n", &n)
		var s string
		fmt.Scanf("%s\n", &s)

		plain := 0
		for i:=1; i<len(s); i++ {
			if s[i] == s[i-1] {
				plain += 1
			}
		}
		ans := (plain+1)/2
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func main() { CF1437B(os.Stdin, os.Stdout) }
func CF1437B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		c, c2 := 0, 0
		for _, s := range strings.FieldsFunc(s, func(r rune) bool { return r == '0' }) {
			c += len(s) - 1
		}
		for _, s := range strings.FieldsFunc(s, func(r rune) bool { return r == '1' }) {
			c2 += len(s) - 1
		}
		if c2 > c {
			c = c2
		}
		Fprintln(out, c)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var t int

func getMax(q1, q2 int) (ans int) {
	if q1 > q2 {
		ans = q1
	} else {
		ans = q2
	}

	return
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		arr := make([]byte, n)
		fmt.Fscan(input, &arr)

		var ans1, ans2 int
		for i := 1; i < n; i++ {
			if arr[i] == arr[i-1] {
				if arr[i] == '0' {
					ans1++
				} else {
					ans2++
				}
			}
		}

		fmt.Println(getMax(ans1, ans2))
	}
}

package main

import (
	"fmt"
)
func max(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		n, s, a, b := 0, "", 0, 0
		fmt.Scan(&n, &s)
		for i := 1; i < n; i++ {
			if s[i - 1] == '0' && s[i] == '0' {
				a++
			} else if s[i - 1] == '1' && s[i] == '1' {
				b++
			}
		}
		fmt.Println(max(a, b))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	io := bufio.NewReader(os.Stdin)
	var t, n int
	var str string
	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n)
		res := 0
		fmt.Fscan(io, &str)
		for i, r := range str {
			if i > 0 && r == '1' && str[i-1] == '1' {
				res++
			}
		}
		fmt.Println(res)
	}
}

package main

import (
  "fmt"
)

func main() {
  var t int
  fmt.Scanf("%v", &t)

  for i := 0; i < t; i++ {
    var n int
    fmt.Scanf("%v", &n)
    var s string
    fmt.Scanf("%v", &s)
    s = " " + s
    //fmt.Println(s)

    var ans int

    for i := 1; i < n; i++ {
      if s[i] == s[i - 1] {
        for i < n && s[i] == s[i - 1] {
          i++
        }
        ans++
      }
    }
    fmt.Println(ans)
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var Writer = bufio.NewWriter(os.Stdout)
var Reader = bufio.NewReader(os.Stdin)

func Print(args ...interface{}) {
	fmt.Fprint(Writer, args...)
}

func Scan(args ...interface{}) {
	fmt.Fscan(Reader, args...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	defer Writer.Flush()

	var t int
	Scan(&t)
	for t != 0 {
		var n int
		Scan(&n)
		var s string
		Scan(&s)
		bits := make([]int, len(s))
		for i := range s {
			bits[i] = int(s[i] - 48)
		}
		res := n * 2
		for d := 0; d < 2; d++ {
			sres := 0
			i, j := 0, 0
			for {
				for i < n && !((i+d)%2 == 0 && bits[i] == 1) {
					i++
				}
				if i >= n {
					break
				}
				for j < n && !((j+d)%2 == 1 && bits[j] == 0) {
					j++
				}
				if j >= n {
					break
				}
				sres++
				if abs(i-j) > 2{
					sres++
				}
				i++
				j++
			}
			if sres < res {
				res = sres
			}
		}

		Print(res, "\n")
		t--
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	bitType := "0"
	operations := 0
	for i := 0; i < stringLength[index]-1; i++ {
		mainCondition := (stringBinary[index][i] == stringBinary[index][i+1])
		if operations == 0 {
			bitType = string(stringBinary[index][i])
		}
		if mainCondition && string(stringBinary[index][i]) == bitType {
			operations++
		}
	}
	return operations
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"strings"
)

var (
	stringLength []int
	stringBinary []string
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 10*8*4096)
	scanner.Buffer(bf, 10*8*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
		fmt.Println("length", len(stringBinary[0]))
	}
}

func processTestCase(index int) int {
	operations := 0
	for {
		check := checkForOperation(index)
		if check == -1 {
			break
		}
		subString := getSubString(index, check)
		reversedString := reverseString(subString)
		replaceSubString(index, check, check+len(subString)-1, reversedString)
		operations++
	}
	return operations
}

func replaceSubString(index int, start int, stop int, replacement string) {
	stringBinary[index] = stringBinary[index][:start] + replacement + stringBinary[index][stop+1:]
}

func checkForOperation(index int) int {
	for i := 0; i < stringLength[index]-1; i++ {
		if stringBinary[index][i] == stringBinary[index][i+1] {
			return i + 1
		}
	}
	return -1
}

func getSubString(index int, startIndex int) string {
	var subString string
	for i := startIndex; i < stringLength[index]; i++ {
		subString += string(stringBinary[index][i])
		if getSubStringTriggerCondition(index, i, startIndex) {
			break
		}
	}
	return subString
}

func getSubStringTriggerCondition(index int, stringIndex int, startIndex int) bool {
	if stringIndex == stringLength[index]-1 {
		return true
	}
	firstCondition := stringBinary[index][stringIndex] != stringBinary[index][startIndex]
	secondCondition := stringBinary[index][stringIndex+1] != stringBinary[index][startIndex]

	if firstCondition && secondCondition {
		return true
	}
	return false

}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func reverseSlice(data interface{}) {
	value := reflect.ValueOf(data)
	if value.Kind() != reflect.Slice {
		panic(errors.New("data must be a slice type"))
	}
	valueLen := value.Len()
	for i := 0; i <= int((valueLen-1)/2); i++ {
		reverseIndex := valueLen - 1 - i
		tmp := value.Index(reverseIndex).Interface()
		value.Index(reverseIndex).Set(value.Index(i))
		value.Index(i).Set(reflect.ValueOf(tmp))
	}
}

func reverseString(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"strings"
)

var (
	scanner      = bufio.NewScanner(os.Stdin)
	stringLength []int
	stringBinary []string
)

func main() {
	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(testCases)
	for index := range stringLength {
		fmt.Println(processTestCase(index))
	}

}

func collectTestCases(testCases int) {
	for i := 0; i < testCases; i++ {
		stringLength = append(stringLength, convertInputToInt(stdInput(scanner, 1))[0])
		stringBinary = append(stringBinary, stdInput(scanner, 1)[0])
	}
}

func processTestCase(index int) int {
	operations := 0
	for {
		check := checkForOperation(index)
		if check == -1 {
			break
		}
		subString := getSubString(index, check)
		reversedString := reverseString(subString)
		stringBinary[index] = strings.Replace(stringBinary[index], subString, reversedString, 1)
		operations++
	}
	return operations
}

func checkForOperation(index int) int {
	for i := 0; i < stringLength[index]-1; i++ {
		if string(stringBinary[index][i]) == string(stringBinary[index][i+1]) {
			return i + 1
		}
	}
	return -1
}

func getSubString(index int, startIndex int) string {
	var subString string
	for i := startIndex; i < stringLength[index]; i++ {
		subString += string(stringBinary[index][i])
		if getSubStringTriggerCondition(index, i, startIndex) {
			break
		}
	}
	return subString
}

func getSubStringTriggerCondition(index int, stringIndex int, startIndex int) bool {
	if stringIndex == stringLength[index]-1 {
		return true
	}
	firstCondition := string(stringBinary[index][stringIndex]) != string(stringBinary[index][startIndex])
	secondCondition := string(stringBinary[index][stringIndex+1]) != string(stringBinary[index][startIndex])

	if firstCondition && secondCondition {
		return true
	}
	return false

}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func reverseSlice(data interface{}) {
	value := reflect.ValueOf(data)
	if value.Kind() != reflect.Slice {
		panic(errors.New("data must be a slice type"))
	}
	valueLen := value.Len()
	for i := 0; i <= int((valueLen-1)/2); i++ {
		reverseIndex := valueLen - 1 - i
		tmp := value.Index(reverseIndex).Interface()
		value.Index(reverseIndex).Set(value.Index(i))
		value.Index(i).Set(reflect.ValueOf(tmp))
	}
}

func reverseString(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte = '1'

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				if continuous > 1 {
					continuous_max += continuous - 1
				}
				continuous = 0
			}
		}
		if continuous > 1 {
			continuous_max += continuous - 1
		}

		Fprintln(out, continuous_max)

	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func ReverseString1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				add := reverse(tmp[begin:end])
				sum++
				if add  == len(tmp[begin:end]) {
					break
				}

				begin += add
				cur = begin

			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				continuous_max = max(continuous_max, continuous)
				continuous = 0
				last = data
			}
		}
		continuous_max = max(continuous_max, continuous)
		Fprintln(out, continuous_max)

	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func ReverseString1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				flag = true
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				continuous_max = max(continuous_max, continuous)
				continuous = 0
				last = data
			}
		}

		Fprintln(out, continuous_max)

	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func ReverseString1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				//Println("what",string(tmp[begin:end]),begin,end,cur,string(tmp))
				add := reverse(tmp[begin:end])

				//Println("waht end",add+begin,string(tmp))
				begin += add
				cur = begin
				sum++
			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				flag = true
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return len(sub) - 1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				end := findDiffIdx(tmp[cur:]) + 1 + cur
				add := reverse(tmp[begin:end])
				sum++
				if add  == len(tmp) {
					break
				}

				begin += add
				cur = begin

			}else {
				cur ++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

11110000
8
11101000
8

11001100

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		var continuous, continuous_max int
		var last byte = '1'

		for _, data := range tmp {
			if data == last {
				continuous++
			} else {
				if continuous > 1 {
					continuous_max += continuous - 1
					continuous = 0
				}
			}
		}
		if continuous > 1 {
			continuous_max += continuous - 1
		}

		Fprintln(out, continuous_max)

	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func ReverseString1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin := tt + 1

		//Println("test", begin)

		sum := 0
		var end int
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					end = len(tmp)
				} else {
					end = tmpd + 1 + cur
				}

				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				tt := findDiffIdx(tmp[add:])
				if tt == -1 {
					break
				}

				begin = add + tt + 1
				cur = begin
				//Println("waht end", add, begin, string(tmp))

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4

8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		flag := false

		tt := findDiffIdx(tmp)
		if tt == -1 {
			Fprintln(out, 0)
			continue
		}
		begin :=  tt+ 1

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 && flag {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++

				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin
			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
1
8
11101000
3
2
10
4
0110
8
11101000

11101000 → 10101100;
10101100 → 10101010.
*/

func findDiffIdx(sub []byte) int {
	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return begin
		}

		begin = end
	}
	return -1
}

func ReverseString(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, M int
	var Str string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &M)
		Fscan(in, &Str)
		tmp := []byte(Str)

		begin := findDiffIdx(tmp) + 1
		if begin == len(tmp) {
			Fprintln(out, 0)
			continue
		}

		//Println("test", begin)

		sum := 0
		for cur := begin; cur < len(tmp); {
			if tmp[begin] != tmp[cur] {
				tmpd := findDiffIdx(tmp[cur:])
				if tmpd == -1 {
					break
				}
				end := tmpd + 1 + cur
				//Println("what", string(tmp[begin:end]), begin, end, cur, string(tmp))
				add := reverse(tmp[begin:end])
				sum++
				//Println("waht end", add, begin, string(tmp))

				begin += add
				cur = begin

			} else {
				cur++
			}
		}

		Fprintln(out, sum)

	}

}

func reverse(sub []byte) int {
	i := 0
	j := len(sub) - 1
	for i < j {
		sub[i], sub[j] = sub[j], sub[i]
		i++
		j--
	}

	begin := 0
	for end := begin + 1; end < len(sub); end++ {
		if sub[end] == sub[begin] {
			return end
		}

		begin = end
	}

	return len(sub)
}

func main() {
	ReverseString(os.Stdin, os.Stdout)
}


package main

import "fmt"

func main() {
    var n,m,min int
    fmt.Scan(&n,&m)
    if n < m { min = n } else { min = m }
    fmt.Println(min+1)
    for i := 0; i <= min; i++ {
        fmt.Println(i,min-i)
    }
}

package main
import (
	"fmt"
)
func main() {
	var n,m int
	fmt.Scan(&n,&m)
	if m<n {
		n=m
	}
	fmt.Println(n+1)
	for i:=0;i<=n;i++ {
		fmt.Println(i,n-i)
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
)

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

var n, m int

func main() {

	defer out.Flush()
	in.Split(bufio.ScanWords)

	read(&n, &m)

	if n > m {
		n = m
	}

	writeln(n + 1)
	for i := 0; i <= n; i++ {
		writeln(n-i, i)
	}
}

func writeln(num ...int) {
	for _, value := range num {
		str := strconv.Itoa(value)
		out.WriteString(str + " ")
	}
	out.WriteString("\n")
}

func read(num ...*int) {
	for _, value := range num {
		in.Scan()
		*value, _ = strconv.Atoi(in.Text())
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m float64
	_, _ = fmt.Scan(&n, &m)
	sz := int(math.Min(n,m))
	fmt.Println(sz + 1)
	for i := 0; i <= int(math.Min(n, m)); i++ {
		fmt.Println(i, sz-i)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m float64
	_, _ = fmt.Scan(&n, &m)
	fmt.Println(math.Min(n,m)+1)
	for i := 0; i <= int(math.Min(n, m)); i++ {
		fmt.Println(i, i)
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"time"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		type X struct {
			topic    int
			dificult int
		}

		ARR := make([]X, n)
		N := make([]int64, n+1)
		M := make([]int64, n+1)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARR[i].topic, &ARR[i].dificult)
			N[ARR[i].dificult]++
			M[ARR[i].topic]++
		}

		sort.Slice(ARR, func(i, j int) bool {
			return ARR[i].topic > ARR[j].topic
		})

		// Another := make([]int, 0)
		// begin := ARR[0].topic
		// count := 1
		// for i := 1; i < n; i++ {
		// 	if ARR[i].topic == begin {
		// 		count++
		// 	} else {
		// 		Another = append(Another, count)
		// 		count = 1
		// 		begin = ARR[i].topic
		// 	}
		// }
		var sum int64
		// if ARR[0].topic != ARR[n-1].topic {
		// 	for i := 0; i < n-1; i++ {
		// 		for j := i + 1; j < n; j++ {
		// 			if ARR[i].topic == ARR[j].topic {
		// 				sum += N[ARR[i].dificult] + N[ARR[j].dificult] - 2
		// 			} else {
		// 				break
		// 			}
		// 		}
		// 	}
		// }

		for i := 0; i < n; i++ {
			q := ARR[i].topic
			numberOfThatTopic := M[q]
			sum += (numberOfThatTopic - 1) * (N[ARR[i].dificult] - 1)
		}
		var anss int64

		anss = int64(n) * int64(n-1) * int64(n-2) / 6
		anss = anss - sum
		fmt.Println(anss)

	}

}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"time"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		type X struct {
			topic    int
			dificult int
		}

		ARR := make([]X, n)
		N := make([]int64, n+1)
		M := make([]int64, n+1)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARR[i].topic, &ARR[i].dificult)
			N[ARR[i].dificult]++
			M[ARR[i].topic]++
		}

		sort.Slice(ARR, func(i, j int) bool {
			return ARR[i].topic > ARR[j].topic
		})

		// Another := make([]int, 0)
		// begin := ARR[0].topic
		// count := 1
		// for i := 1; i < n; i++ {
		// 	if ARR[i].topic == begin {
		// 		count++
		// 	} else {
		// 		Another = append(Another, count)
		// 		count = 1
		// 		begin = ARR[i].topic
		// 	}
		// }
		var sum int64
		// if ARR[0].topic != ARR[n-1].topic {
		// 	for i := 0; i < n-1; i++ {
		// 		for j := i + 1; j < n; j++ {
		// 			if ARR[i].topic == ARR[j].topic {
		// 				sum += N[ARR[i].dificult] + N[ARR[j].dificult] - 2
		// 			} else {
		// 				break
		// 			}
		// 		}
		// 	}
		// }

		for i := 0; i < n; i++ {
			q := ARR[i].topic
			numberOfThatTopic := M[q]
			sum += (numberOfThatTopic - 1) * (N[ARR[i].dificult] - 1)
		}
		var ans int64

		ans = int64(n) * int64(n-1) * int64(n-2) / 6
		ans = ans - sum
		fmt.Println(ans)

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		b := make([]int,n+5)
		mpt := map[int]int{}
		mpd := map[int]int{}
		sum := n*(n-1)*(n-2)/6
		var i int64
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i],&b[i])
			mpt[a[i]]++
			mpd[b[i]]++
		}
		for i=1;i<=n;i++{
			sum -= int64(int64(mpt[a[i]]-1)*int64(mpd[b[i]]-1))
		}
		fmt.Fprintln(out,sum)
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
)

var n int

var pr [][2]int

var topic [][][2]int
var diff [][][2]int

var bit []map[int]int

const LOCAL = false

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	if LOCAL {
		rand.Seed(time.Now().UnixNano())

		for tt := 0 ; tt < t; tt++ {
			n = 10
			pr = make([][2]int, n)

			mm := make([][]bool, n + 1)

			for j := 0; j < n + 1; j++ {
				mm[j] = make([]bool, n + 1)
			}

			for i := 0; i < n; i++ {

				var top int
				var diff int

				for ;; {
					top = 1 + rand.Intn(n)
					diff = 1 + rand.Intn(n)

					if !mm[top][diff] {
						mm[top][diff] = true
						break
					}
				}

				pr[i][0] = top
				pr[i][1] = diff
			}

			a1 := solve(n)
			a2 := solve_stupid(n)

			if a1 != a2 {
				fmt.Println("ERROR")
				fmt.Println(a1)
				fmt.Println(a2)
				fmt.Println(pr)
				break
			}
		}

		return
	}

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		pr = make([][2]int, n)

		for  j := 0; j < n; j++ {
			fmt.Fscan(r, &pr[j][0], &pr[j][1])
		}

		ans := solve(n)

		fmt.Println(ans)
	}
}

func solve_stupid(n int) int64 {
	var ans int64

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				p1 := pr[i]
				p2 := pr[j]
				p3 := pr[k]

				if p1[0] == p2[0] || p1[0] == p3[0] || p2[0] == p3[0] {

					if p1[1] == p2[1] || p1[1] == p3[1] || p2[1] == p3[1] {
						continue

					} else {
						ans++
					}

				} else {
					ans++
				}
			}
		}
	}

	return ans
}

func solve(n int) int64 {
	var ans int64

	topic = make([][][2]int, n + 1)
	diff = make([][][2]int, n + 1)

	for i := 0; i < n; i++ {
		p := pr[i]

		topic[p[0]] = append(topic[p[0]], p)
		diff[p[1]] = append(diff[p[1]], p)
	}

	topicSum := make([]int64, n + 1)
	diffSum := make([]int64, n + 1)

	for i := 1; i <= n; i++ {
		t := topic[i]

		for j := 0; j < len(t); j++ {
			p := t[j]

			d := p[1]

			dd := diff[d]

			diffs := len(dd) - 1

			topicSum[i] += int64(diffs)
		}

	}

	for i := 1; i <= n; i++ {
		d := diff[i]

		for j := 0; j < len(d); j++ {
			p := d[j]

			top := p[0]

			tt := topic[top]

			tops := len(tt) - 1

			diffSum[i] += int64(tops)

		}
	}

	var all = (int64(n) - 1) * (int64(n) - 2)/2

	for i := 0; i < n; i++ {
		p := pr[i]

		top := p[0]
		di := p[1]

		sum1 := topicSum[top]

		sum1 = sum1 - int64(len(diff[di])) + 1

		sum2 := diffSum[di]

		sum2 = sum2 - int64(len(topic[top])) + 1

		ans += all - sum1 - sum2 - (int64(len(diff[di])) - 1) * (int64(len(topic[top])) - 1)
	}

	return ans/3
}

func update(n int, bit *[]map[int]int, x, y int, delta int) {
	for ;x <= n; x += x & -x {
		y1 := y
		for ; y1 <= n; y1 += y1 & -y1 {
			(*bit)[x][y1] += delta
		}
	}
}

func get(x, y int, bit *[]map[int]int) int64 {
	var ret int64 = 0

	for ; x > 0; x -= x & -x {
		y1 := y
		for ; y1 > 0; y1 -= y1 & -y1 {

			ret += int64((*bit)[x][y1])
		}
	}
	return ret
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		b := make([]int,n+5)
		mpt := map[int]int{}
		mpd := map[int]int{}
		sum := n*(n-1)*(n-2)/6
		var i int64
		for i=1;i<=n;i++{
			fmt.Fscan(in,&a[i],&b[i])
			mpt[a[i]]++
			mpd[b[i]]++
		}
		for i=1;i<=n;i++{
			sum -= int64((mpt[a[i]]-1)*(mpd[b[i]]-1))
		}
		fmt.Fprintln(out,sum)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		b := make([]int,n+5)
		mpt := map[int]int{}
		mpd := map[int]int{}
		sum := n*(n-1)*(n-2)/6
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i],&b[i])
			mpt[a[i]]++
			mpd[b[i]]++
		}
		for i:=1;i<=n;i++{
			sum -= (mpt[a[i]]-1)*(mpd[b[i]]-1)
		}
		fmt.Fprintln(out,sum)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	const mod = 1000000007
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n, k int
		fmt.Fscan(in,&n,&k)
		a := make([]int,n+5)
		cnt:=0
		ans:=0
		for i:=k;i>=1;i--{
			cnt++
			if i==k{
				ans += 1
				for j:=1;j<=n;j++{
					a[j]=1
				}
				continue
			}
			if cnt%2==0{
				pre := 0
				for j:=n;j>=1;j--{
					ans = (ans%(mod) + a[j]%(mod))%(mod)
					temp := a[j]
					a[j] = pre
					pre = (pre%(mod) + temp%(mod))%(mod)
				}
			}else{
				pre := 0
				for j:=1;j<=n;j++{
					ans = (ans%(mod) + a[j]%(mod))%(mod)
					temp := a[j]
					a[j] = pre
					pre = (pre%(mod) + temp%(mod))%(mod)
				}
			}
		}
		fmt.Fprintln(out,ans%mod)
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"
)

var n int

var pr [][2]int

var topic [][][2]int
var diff [][][2]int

var bit []map[int]int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		pr = make([][2]int, n)

		for  j := 0; j < n; j++ {
			fmt.Fscan(r, &pr[j][0], &pr[j][1])
		}

		ans := solve(n)

		fmt.Println(ans)
	}
}

func solve(n int) int64 {
	var ans int64

	topic = make([][][2]int, n + 1)
	diff = make([][][2]int, n + 1)

	for i := 0; i < n; i++ {
		p := pr[i]

		topic[p[0]] = append(topic[p[0]], p)
		diff[p[1]] = append(diff[p[1]], p)
	}

	topicSum := make([]int64, n + 1)
	diffSum := make([]int64, n + 1)

	for i := 1; i <= n; i++ {
		t := topic[i]

		for j := 0; j < len(t); j++ {
			p := t[j]

			d := p[1]

			dd := diff[d]

			diffs := len(dd) - 1

			topicSum[i] += int64(diffs)
		}

	}

	for i := 1; i <= n; i++ {
		d := diff[i]

		for j := 0; j < len(d); j++ {
			p := d[j]

			top := p[0]

			tt := topic[top]

			tops := len(tt) - 1

			diffSum[i] += int64(tops)

		}
	}

	var all = (int64(n) - 1) * (int64(n) - 2)/2

	for i := 0; i < n; i++ {
		p := pr[i]

		top := p[0]
		di := p[1]

		sum1 := topicSum[top]

		sum1 = sum1 - int64(len(diff[di])) + 1

		sum2 := diffSum[di]

		sum2 = sum2 - int64(len(topic[top])) + 1

		ans += all - sum1 - sum2
	}

	return ans/3
}

func update(n int, bit *[]map[int]int, x, y int, delta int) {
	for ;x <= n; x += x & -x {
		y1 := y
		for ; y1 <= n; y1 += y1 & -y1 {
			(*bit)[x][y1] += delta
		}
	}
}

func get(x, y int, bit *[]map[int]int) int64 {
	var ret int64 = 0

	for ; x > 0; x -= x & -x {
		y1 := y
		for ; y1 > 0; y1 -= y1 & -y1 {

			ret += int64((*bit)[x][y1])
		}
	}
	return ret
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func Min[T int | int64 | float64](x, y T) T {
	if x < y {
		return x

	}
	return y

}

func Max[T int | int64 | float64](x, y T) T {
	if x > y {
		return x

	}
	return y

}

func main() {
	var t int
	read := bufio.NewReader(os.Stdin)
	fmt.Fscan(read, &t)
	for ; t > 0; t-- {
		var (
			n, m, min int
		)
		fmt.Fscan(read, &n, &m)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(read, &a[i])
		}
		b := make([]bool, m)
		for _, val := range a {
			min = Min(m-val, val-1)
			val = Max(m-val, val-1)
			if b[min] {
				b[val] = true
				continue
			}
			b[min] = true
		}
		for _, val := range b {
			if val {
				fmt.Print("A")
			} else {
				fmt.Print("B")
			}
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1706A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1706A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1706A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1706A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1706A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1706A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1706A
Date: 22/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1706/A
Problem: CF1706A
**/
func (in *CF1706A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		mapa := make(map[int]bool)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		for i := 0; i < n; i++ {
			a := arr[i]
			b := m + 1 - arr[i]
			_, eA := mapa[a]
			_, eB := mapa[b]

			if a < b && !eA {
				mapa[a] = true
			} else if b < a && !eB {
				mapa[b] = true
			} else if !eA {
				mapa[a] = true
			} else {
				mapa[b] = true
			}
		}

		var ans strings.Builder
		for i := 0; i < m; i++ {
			if _, e := mapa[i+1]; e {
				ans.WriteString("A")
			} else {
				ans.WriteString("B")
			}
		}

		fmt.Println(ans.String())
	}
}

func NewCF1706A(r *bufio.Reader) *CF1706A {
	return &CF1706A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1706A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	tests := sc.Text()
	cnt, _ := strconv.Atoi(tests)
	for cnt > 0 {
		sc.Scan()
		one := sc.Text()
		cur := strings.Split(one, " ")
		m, _ := strconv.Atoi(cur[0])
		n, _ := strconv.Atoi(cur[1])
		sc.Scan()
		arr := strings.Split(sc.Text(), " ")
		source := make([]byte, n)
		for i := 0; i < n; i++ {
			source[i] = 'B'
		}
		for i := 0; i < m; i++ {
			index, _ := strconv.Atoi(arr[i])
			index1, index2 := index-1, n-index
			if index1 > index2 {
				index1, index2 = index2, index1
			}
			if index1 < index2 && source[index1] == 'B' {
				source[index1] = 'A'
			} else {
				source[index2] = 'A'
			}
		}
		fmt.Printf("%s\n", string(source))
		cnt--
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		b := make([]int, n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(n, m, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, b []int) string {
	c := make([]byte, m)
	for i := range c {
		c[i] = 'B'
	}
	for _, v := range b {
		if v > m-v+1 {
			v = m - v + 1
		}
		if c[v-1] == 'B' {
			c[v-1] = 'A'
		} else {
			c[m-v] = 'A'
		}
	}
	return string(c)
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	n := readInt(in)
	for i := 0; i < n; i++ {
		solution(in, out)
	}
}

func solution(in *bufio.Reader, out *bufio.Writer) {
	v := readArrInt(in)
	k := v[1]
	arr := readArrInt(in)
	bools := make([]bool, k)

	for _, v := range arr {
		idx1 := v - 1
		idx2 := k - v
		firstIdx := Min(idx1, idx2)
		secondIdx := Max(idx1, idx2)
		if bools[firstIdx] {
			bools[secondIdx] = true
		} else {
			bools[firstIdx] = true
		}
	}

	for _, v := range bools {
		if v {
			out.WriteString("A")
		} else {
			out.WriteString("B")
		}
	}

	out.WriteString("\n")

}

func Max(sum int, sum2 int) int {
	if sum > sum2 {
		return sum
	}
	return sum2

}

func Min(sum int, sum2 int) int {
	if sum < sum2 {
		return sum
	}
	return sum2
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

import (
	"bufio"
	"os"
	"fmt"
)

const MOD int64 = 1000000007

var n, m int

var a[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &m)

		a = make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() string {
	bts := make([]byte, m)

	seen := make([]bool, m)

	for i := 0; i < n; i++ {
		aa := a[i] - 1
		bb := m - a[i]

		if aa <= bb {
			if seen[aa] {
				bts[bb] = 'A'
				seen[bb] = true
			} else {
				bts[aa] = 'A'
				seen[aa] = true
			}

		} else {
			if seen[bb] {
				bts[aa] = 'A'
				seen[aa] = true
			} else {
				bts[bb] = 'A'
				seen[bb] = true
			}
		}
	}

	for i := 0; i < m; i++ {
		if bts[i] == 0 {
			bts[i] = 'B'
		}
	}

	return string(bts)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var cf = true

func solve() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	ans := make([]byte, m)
	for i := range ans {
		ans[i] = 'B'
	}
	var ind int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &ind)
		ind1 := ind - 1
		ind2 := m - ind
		if ind1 > ind2 {
			ind1, ind2 = ind2, ind1
		}
		if ans[ind1] == 'B' {
			ans[ind1] = 'A'
		} else {
			ans[ind2] = 'A'
		}
	}
	fmt.Fprintf(out, "%s\n", string(ans))
}

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T comparable] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

import (
	"fmt"
)

func main() {
	times := 0
	fmt.Scan(&times)
	for i := 0; i < times; i++ {
		n, m, poss := 0, 0, []int{}
		fmt.Scan(&n, &m)
		for j := 0; j < n; j++ {
			tmpNum := 0
			fmt.Scan(&tmpNum)
			poss = append(poss, tmpNum)
		}
		ans := solve(m ,poss)
		fmt.Println(ans)
	}
}

func solve(l int, poss []int) string {
	m := make(map[int]bool)
	for _, pos := range poss {
		if pos > (l + 1) / 2 {
			pos = l + 1 - pos
		}
		if _, ok := m[pos]; !ok {
			m[pos] = false
		} else {
			m[pos] = true
		}
	}
	//fmt.Println(m)
	ans := []byte{}
	for i := 0; i < l; i++ {
		ans = append(ans, 'B')
	}
	for pos, flag := range m {
		if !flag {
			ans[pos - 1] = 'A'
		} else {
			ans[pos - 1] = 'A'
			ans[l - pos] = 'A'
		}
	}
	return string(ans)
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    tc := readInt(in)
    for tc > 0 {
        f := readArrInt(in)
        n := f[0]
        m := f[1]
        ops := readArrInt(in)
        var res []rune
        for i:=0; i<m; i++ {
            res = append(res, 'B')
        }

        for i:=0; i<n; i++ {
            curId := ops[i]
            nextId := m+1-curId

            if nextId < curId {
                curId, nextId = nextId, curId
            }

            if curId-1 >= 0 && curId-1 < m && res[curId-1] == 'B' {
                res[curId-1] = 'A'
            } else if nextId-1 >= 0 && nextId-1 < m {
                res[nextId-1] = 'A'
            }
        }
        fmt.Println(string(res))
        tc--
    }
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
)

func solve() {
	n := get()
	m := get()
	a := geta(n)
	for i := range a {
		a[i]--
	}

	s := []rune(strings.Repeat("B", m))

	for _, i := range a {
		if m-i-1 < i {
			i = m - i - 1
		}
		if s[i] == 'B' {
			s[i] = 'A'
			continue
		}
		s[m-i-1] = 'A'
	}

	putsln(string(s))
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		s := bytes.Repeat([]byte{'B'}, m)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			d := min(v-1, m-v)
			if s[d] == 'B' {
				s[d] = byte('A')
			} else {
				s[max(v-1, m-v)] = byte('A')
			}
		}
		fmt.Fprintln(out, string(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewReader(os.Stdin)
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n, m int
		fmt.Fscan(scanner, &n, &m)
		slice := make([]rune, m)
		for i := 0; i < m; i++ {
			slice[i] = 'B'
		}
		for i := 0; i < n; i++ {
			var num int
			fmt.Fscan(scanner, &num)
			num = num - 1
			if m-num-1 < num {
				num = m - num - 1
			}
			if slice[num] != 'A' {
				slice[num] = 'A'
			} else {
				slice[m-num-1] = 'A'
			}
		}
		for i := 0; i < m; i++ {
			fmt.Printf("%c", slice[i])
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func main() {
	a1706(os.Stdin, os.Stdout)
}

func a1706(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var m int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &m)
		r := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r[i] = x
		}
		ans := make([]byte, m)
		for i := 0; i < m; i++ {
			ans[i] = 'B'
		}
		for _, v := range r {
			a, b := v-1, m-v
			if a > b {
				a, b = b, a
			}
			if ans[a] == 'A' {
				ans[b] = 'A'
			} else {
				ans[a] = 'A'
			}
		}

		Fprintln(out, string(ans))
	}
}

// 00
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, m, curr int
		fmt.Fscan(reader, &n, &m)
		bs := make([]byte, m)
		for i := 0; i < m; i++ {
			bs[i] = 'B'
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			first := curr - 1
			other := m - curr
			if first > other {
				first, other = other, first
			}
			if bs[first] == 'B' {
				bs[first] = 'A'
			} else {
				bs[other] = 'A'
			}
		}
		fmt.Println(string(bs))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(n int, m int, a []int) string {
	res := make([]int, m)
	for i := 0; i < m; i++ {
		res[i] = 1
	}

	for i := 0; i < n; i++ {
		u := a[i] - 1
		v := m - a[i]
		if u > v {
			u, v = v, u
		}
		if res[u] == 1 {
			res[u] = 0
		} else {
			res[v] = 0
		}
	}

	s := ""
	for i := 0; i < m; i++ {
		if res[i] == 0 {
			s += "A"
		} else {
			s += "B"
		}
	}

	return s
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Fscanln(inp, &a[i])
			} else {
				fmt.Fscan(inp, &a[i])
			}
		}

		fmt.Fprintln(out, solve(n, m, a))
	}

	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	nums := make([]int, n)
	ans := make([]byte, m)
	for i := range ans {
		ans[i] = 'B'
	}
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
		if ans[min(m-nums[i], nums[i]-1)] == 'B' {
			ans[min(m-nums[i], nums[i]-1)] = 'A'
		} else {
			ans[max(m-nums[i], nums[i]-1)] = 'A'
		}
	}
	fmt.Fprintln(ww, string(ans))
}

func min(a, b int) int {if a < b {return a} else {return b}}
func max(a, b int) int {if a > b {return a} else {return b}}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Min[T int | int64 | float64](x, y T) T {
	if x < y {
		return x

	}
	return y

}

func Max[T int | int64 | float64](x, y T) T {
	if x > y {
		return x

	}
	return y

}

func main() {
	var t int
	read := bufio.NewReader(os.Stdin)
	fmt.Fscan(read, &t)
	for ; t > 0; t-- {
		var (
			n, m, min int
		)
		fmt.Fscan(read, &n, &m)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(read, &a[i])
		}
		b := make([]bool, m)
		for _, val := range a {
			min = Min(m-val, val-1)
			val = Max(m-val, val-1)
			if b[min] {
				b[val] = true
				continue
			}
			b[min] = true
		}
		s := make([]byte, m)
		for index, val := range b {
			if val {
				s[index] = 'A'
			} else {
				s[index] = 'B'
			}
		}
		fmt.Println(string(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func packAddrs(n []int) []interface{} {
	p := make([]interface{}, len(n))
	for i := range n {
		p[i] = &n[i]

	}
	return p

}

func Min[T int | int64 | float64](x, y T) T {
	if x < y {
		return x

	}
	return y

}

func Max[T int | int64 | float64](x, y T) T {
	if x > y {
		return x

	}
	return y

}

func main() {
	var t int
	read := bufio.NewReader(os.Stdin)
	fmt.Fscanln(read, &t)
	for ; t > 0; t-- {
		var (
			n, m, min int
		)
		fmt.Fscanln(read, &n, &m)
		a := make([]int, n)
		fmt.Fscanln(read, packAddrs(a)...)
		b := make([]bool, m)
		for _, val := range a {
			min = Min(m-val, val-1)
			val = Max(m-val, val-1)
			if b[min] {
				b[val] = true
				continue
			}
			b[min] = true
		}
		for _, val := range b {
			if val {
				fmt.Print("A")
			} else {
				fmt.Print("B")
			}
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var symbols = map[bool]string{
	true:  "A",
	false: "B",
}

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt()

	for i := 0; i < t; i++ {
		_, strLen := readTwoInts()
		a := readArrInt()

		str := make([]bool, strLen)
		for _, ai := range a {
			ai -= 1
			smaller, greater := ai, strLen-1-ai
			if smaller > greater {
				smaller, greater = greater, smaller
			}

			if str[smaller] == false {
				str[smaller] = true
				continue
			}

			if str[greater] == false {
				str[greater] = true
				continue
			}
		}

		for _, b := range str {
			fmt.Print(symbols[b])
		}
		fmt.Println()
	}
}

func readInt() int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readTwoInts() (int, int) {
	r := readArrInt()
	return r[0], r[1]
}

func readArrString() []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt() []int {
	numbs := readArrString()
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1706A(os.Stdin, os.Stdout)
}
func CF1706A(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n, m int
		fmt.Fscan(r, &n, &m)
		s := bytes.Repeat([]byte("B"), m)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}
		for _, v := range arr {
			left, right := v-1, m-v
			if left > right {
				left, right = right, left
			}

			if s[left] == 'A' {
				s[right] = 'A'
			} else {
				s[left] = 'A'
			}

		}
		fmt.Fprintln(w, string(s))
	}
}

package main

import (
	"fmt"
)
func main() {
	time := 0
	fmt.Scanf("%d\n", &time)
	for time > 0 {
		time--
		ls, le := 0, 0
		fmt.Scanf("%d %d\n", &ls, &le)
		str := make([]byte, le)
		for i := range str {
			str[i] = byte('B')
		}
		squ := make([]int, ls)
		for i := range squ {
			fmt.Scan(&squ[i])
			squ[i]--
		}
		fmt.Scanf("\n")
		for _, v := range squ {
			vi := le - v - 1
			if v < vi {
				if str[v] != byte('A') {
					str[v] = byte('A')
				} else {
					str[vi] = byte('A')
				}
			} else {
				if str[vi] != byte('A') {
					str[vi] = byte('A')
				} else {
					str[v] = byte('A')
				}
			}
		}
		fmt.Println(string(str))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader

func main() {
	var (
		t int
		n int
		m int
	)

	reader = bufio.NewReader(os.Stdin)

	_, _ = fmt.Fscanln(reader, &t)

	for i := 0; i < t; i++ {
		_, _ = fmt.Fscanln(reader, &n, &m)

		solve(n, m)
	}
}

func solve(n, m int) {
	count := make(map[int]int)

	for n > 0 {
		n--

		var v int
		_, _ = fmt.Fscan(reader, &v)

		count[v-1]++
	}
	_, _ = fmt.Fscanln(reader)

	// true if A placed in ind position
	var answer = make([]bool, m)
	for k, counted := range count {
		if counted >= 2 {
			answer[k] = true
			answer[m-k-1] = true
		} else {
			var (
				a int
				b int
			)
			if k < m-k-1 {
				a = k
				b = m - k - 1
			} else {
				b = k
				a = m - k - 1
			}

			if answer[a] {
				answer[b] = true
			} else {
				answer[a] = true
			}
		}
	}

	var result strings.Builder
	for _, a := range answer {
		if a {
			result.WriteString("A")
		} else {
			result.WriteString("B")
		}
	}

	fmt.Println(result.String())
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,m int
		fmt.Fscan(in,&n,&m)
		row1:= make([]int,n)
		row2:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&row1[j])
			row2[j]=(m+1-row1[j])
		}
		word:= make([]string,m)
		for j:=0;j<m;j++{
			word[j]="B"
		}
		for j:=0;j<n;j++{
			if row1[j] <= row2[j] {
				if string(word[row1[j]-1]) == "B" {
					word[row1[j]-1] = "A"
					continue
				}
			}
			if string(word[row2[j]-1]) == "B" {
				word[row2[j]-1] = "A"
			} else {
				word[row1[j]-1] = "A"
			}
		}
		for j:=0;j<len(word);j++{
			fmt.Fprintf(out,"%v",string(word[j]))
		}
		fmt.Fprintln(out,)
	}
}

// https://codeforces.com/problemset/problem/1706/A

// 1706A - Another String Minimization Problem

// You have a sequence a1,a2,…,an of length n, consisting of integers between 1 and m. You also have a string s, consisting of m characters B.
// You are going to perform the following n operations.
//  • At the i-th (1≤i≤n) operation, you replace either the ai-th or the (m+1−ai)-th character of s with A. You can replace the character at any position multiple times through the operations.
// Find the lexicographically smallest string you can get after these operations.
// A string x is lexicographically smaller than a string y of the same length if and only if in the first position where x and y differ, the string x has a letter that appears earlier in the alphabet than the corresponding letter in y.

// Input
// The first line contains the number of test cases t (1≤t≤2000).
// The first line of each test case contains two integers n and m (1≤n,m≤50) — the length of the sequence a and the length of the string s respectively.
// The second line contains n integers a1,a2,…,an (1≤ai≤m) — the sequence a.

// Output
// For each test case, print a string of length m — the lexicographically smallest string you can get. Each character of the string should be either capital English letter A or capital English letter B.

// Example
// input
// 6
// 4 5
// 1 1 3 1
// 1 5
// 2
// 4 1
// 1 1 1 1
// 2 4
// 1 3
// 2 7
// 7 5
// 4 5
// 5 5 3 5
// output
// ABABA
// BABBB
// A
// AABB
// ABABBBB
// ABABA

// Note

// In the first test case, the sequence a=[1,1,3,1]. One of the possible solutions is the following.
//  • At the 1-st operation, you can replace the 1-st character of s with A. After it, s becomes ABBBB.
//  • At the 2-nd operation, you can replace the 5-th character of s with A (since m+1−a2=5). After it, s becomes ABBBA.
//  • At the 3-rd operation, you can replace the 3-rd character of s with A. After it, s becomes ABABA.
//  • At the 4-th operation, you can replace the 1-st character of s with A. After it, s remains equal to ABABA.
// The resulting string is ABABA. It is impossible to produce a lexicographically smaller string.
// In the second test case, you are going to perform only one operation. You can replace either the 2-nd character or 4-th character of s with A. You can get strings BABBB and BBBAB after the operation. The string BABBB is the lexicographically smallest among these strings.
// In the third test case, the only string you can get is A.
// In the fourth test case, you can replace the 1-st and 2-nd characters of s with A to get AABB.
// In the fifth test case, you can replace the 1-st and 3-rd characters of s with A to get ABABBBB.

// Tutorial

// Let's iterate through the elements of a. For convenience, we'll make ai=min(ai,m+1−ai). If the ai-th character of s is not currently A, then we should replace it. Otherwise, we replace the (m+1−ai)-th character. This is because if we have the choice between replacing two characters, replacing the one with the smaller index will result in a lexicographically smaller string.
// Alternatively, we can keep track of how many times either x or m+1−x appears in a for each 1≤x≤⌈m/2⌉.
//  • If they appear 0 times, neither of these indices in s can become A.
//  • If they appear 1 time, it is optimal to set the x-th character to A, since this will produce a lexicographically smaller string.
//  • Otherwise, they appear at least 2 times, and it is possible to set both the x-th and (m+1−x)-th character to A.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, m, a, i uint
	var s []byte
	var cnt []uint

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &m)
			cnt = make([]uint, m)
			s = make([]byte, m)

			for i = 0; i < n; i++ {
				fmt.Fscan(reader, &a)
				a--

				if a > m-1-a {
					a = m - 1 - a
				}

				cnt[a]++
			}

			for i = 0; i < m; i++ {
				s[i] = 'B'
			}

			for i = 0; i < m; i++ {
				if cnt[i] > 0 {
					s[i] = 'A'

					if cnt[i] > 1 {
						s[m-i-1] = 'A'
					}
				}
			}

			fmt.Fprintln(writer, string(s))
		}
	}

	writer.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		A := readNNums(reader, n)
		res := solve(A, m)
		buf.WriteString(res)
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(A []int, m int) string {
	res := make([]byte, m)
	for i := 0; i < m; i++ {
		res[i] = 'B'
	}

	for _, i := range A {
		j := m + 1 - i
		x := i - 1
		y := j - 1
		if x > y {
			x, y = y, x
		}
		if res[x] == 'B' {
			res[x] = 'A'
		} else {
			res[y] = 'A'
		}
	}

	return string(res)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	var t, n, m int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		var s string
		for i := 0; i < m; i++ {
			s += "B"
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		c := []byte(s)
		for i := 0; i < n; i++ {
			p := a[i] - 1
			q := m - 1 - p
			if p > q {
				p, q = q, p
			}
			// fmt.Fprintln(out, "test:", p, q)
			if c[p] == 'B' {
				c[p] = 'A'
			} else {
				c[q] = 'A'
			}
		}
		fmt.Fprintln(out, string(c))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}
}

func solve() {
	var n, m, x int
	fmt.Fscan(in, &n, &m)
	s := []byte{}
	for i := 0; i < m; i++ {
		s = append(s, 'B')
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		x--
		y := m - 1 - x
		if x > y {
			x, y = y, x
		}

		if s[x] == 'B' {
			s[x] = 'A'
		} else {
			s[y] = 'A'
		}
	}
	fmt.Fprintln(out, string(s))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, m int
	a       []int
)

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func solve(n, m int, a []int) string {
	b := strings.Repeat("B", m)
	for _, p := range a {
		k := min(p, m+1-p)
		if b[k-1] == 'B' {
			b = b[:k-1] + "A" + b[k:]
		} else {
			b = b[:m-k] + "A" + b[m-k+1:]
		}
	}
	return b
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)
		a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, m, a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var bufferedStdin = bufio.NewReader(os.Stdin)
var bufferedStdout = bufio.NewWriter(os.Stdout)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func solve() {
	var n, m int
	_, _ = fmt.Fscan(bufferedStdin, &n, &m)
	answer := make([]rune, m)
	for i := 0; i < m; i++ {
		answer[i] = 'B'
	}
	for i := 0; i < n; i++ {
		var a int
		_, _ = fmt.Fscan(bufferedStdin, &a)
		ind := min(a-1, m-a)
		if answer[ind] == 'A' {
			answer[m-1-ind] = 'A'
		} else {
			answer[ind] = 'A'
		}
	}
	for _, value := range answer {
		_, _ = fmt.Fprintf(bufferedStdout, "%c", value)
	}
	_, _ = fmt.Fprint(bufferedStdout, "\n")
}

func main() {
	var t int
	_, _ = fmt.Fscan(bufferedStdin, &t)
	for i := 0; i < t; i++ {
		solve()
	}
	_ = bufferedStdout.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1706A(os.Stdin, os.Stdout)
}
func CF1706A(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n, m int
		fmt.Fscan(r, &n, &m)
		s := bytes.Repeat([]byte("B"), m)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}
		for _, v := range arr {
			left, right := v-1, m-v
			if s[left] == 'A' {
				s[right] = 'A'
			} else {
				s[left] = 'A'
			}
		}
		fmt.Fprintln(w, string(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader

func main() {
	var (
		t int
		n int
		m int
	)

	reader = bufio.NewReader(os.Stdin)

	_, _ = fmt.Fscanln(reader, &t)

	for i := 0; i < t; i++ {
		_, _ = fmt.Fscanln(reader, &n, &m)

		solve(n, m)
	}
}

func solve(n, m int) {
	count := make(map[int]int)

	for n > 0 {
		n--

		var v int
		_, _ = fmt.Fscan(reader, &v)

		count[v-1]++
	}
	_, _ = fmt.Fscanln(reader)

	// true if A placed in ind position
	var answer = make([]bool, m)
	for k, counted := range count {
		if counted >= 2 {
			answer[k] = true
			answer[m-k-1] = true
		} else {
			if k < m-k-1 {
				answer[k] = true
			} else {
				answer[m-k-1] = true
			}
		}
	}

	var result strings.Builder
	for _, a := range answer {
		if a {
			result.WriteString("A")
		} else {
			result.WriteString("B")
		}
	}

	fmt.Println(result.String())
}