T is playing a game with his friend, HL.There are $$$n$$$ piles of stones, the $$$i$$$-th pile initially has $$$a_i$$$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.Assuming both players play optimally, given the starting configuration of $$$t$$$ games, determine the winner of each game.

The first line of the input contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of games. The description of the games follows. Each description contains two lines: The first line contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$ — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 100)$$$.

For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)

NoteIn the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains $$$1$$$ stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, n)

		for i := range a {
			a[i] = in()
		}

		s := 0

		for i := range a {
			s += a[i]
		}

		okay := false

		for i := range a {
			if a[i] > s/2 {
				okay = true
				break
			}
		}

		if okay {
			fmt.Println("T")
			continue
		}

		if s%2 == 0 {
			fmt.Println("HL")
		} else {
			fmt.Println("T")
		}
	}
}

/*
URL:
https://codeforces.com/contest/1397/problem/D
*/

package main

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

var (
	t int
	n int
	A []int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	if n == 1 {
		fmt.Println("T")
		return
	}

	f := func(lv, rv T) T {
		// return T(math.Min(float64(lv), float64(rv)))
		if lv.val > rv.val {
			return lv
		}
		return rv
	}
	// ti := T(1<<31 - 1)
	ti := T{-INF_BIT30, -1}
	st := NewSegmentTree(n, f, ti)

	for i := 0; i < n; i++ {
		st.Set(i, T{A[i], i})
	}
	st.Build()

	turn := 0
	befIdx := -1
	for {
		var t T
		if befIdx == -1 {
			t = st.Query(0, n)
		} else {
			if befIdx == 0 {
				t = st.Query(1, n)
			} else if befIdx == n-1 {
				t = st.Query(0, n-1)
			} else {
				u := st.Query(0, befIdx)
				v := st.Query(befIdx+1, n)
				if u.val > v.val {
					t = u
				} else {
					t = v
				}
			}
		}

		if t.val == 0 || t.idx == befIdx {
			// for i := 0; i < n; i++ {
			// 	PrintfDebug("%v ", st.Get(i))
			// }
			// PrintfDebug("\n")

			if turn%2 == 0 {
				fmt.Println("HL")
			} else {
				fmt.Println("T")
			}
			return
		}

		befIdx = t.idx
		st.Update(t.idx, T{t.val - 1, t.idx})

		turn++
	}
}

// type T int // (T, f): Monoid
type T struct {
	val int
	idx int
}

type SegmentTree struct {
	sz   int              // minimum power of 2
	data []T              // elements in T
	f    func(lv, rv T) T // T <> T -> T
	ti   T                // identity element of Monoid
}

func NewSegmentTree(
	n int, f func(lv, rv T) T, ti T,
) *SegmentTree {
	st := new(SegmentTree)
	st.ti = ti
	st.f = f

	st.sz = 1
	for st.sz < n {
		st.sz *= 2
	}

	st.data = make([]T, 2*st.sz-1)
	for i := 0; i < 2*st.sz-1; i++ {
		st.data[i] = st.ti
	}

	return st
}

func (st *SegmentTree) Set(k int, x T) {
	st.data[k+(st.sz-1)] = x
}

func (st *SegmentTree) Build() {
	for i := st.sz - 2; i >= 0; i-- {
		st.data[i] = st.f(st.data[2*i+1], st.data[2*i+2])
	}
}

func (st *SegmentTree) Update(k int, x T) {
	k += st.sz - 1
	st.data[k] = x

	for k > 0 {
		k = (k - 1) / 2
		st.data[k] = st.f(st.data[2*k+1], st.data[2*k+2])
	}
}

func (st *SegmentTree) Query(a, b int) T {
	return st.query(a, b, 0, 0, st.sz)
}

func (st *SegmentTree) query(a, b, k, l, r int) T {
	if r <= a || b <= l {
		return st.ti
	}

	if a <= l && r <= b {
		return st.data[k]
	}

	lv := st.query(a, b, 2*k+1, l, (l+r)/2)
	rv := st.query(a, b, 2*k+2, (l+r)/2, r)
	return st.f(lv, rv)
}

func (st *SegmentTree) Get(k int) T {
	return st.data[k+(st.sz-1)]
}

// func solve() {
// 	if n == 1 {
// 		fmt.Println("T")
// 		return
// 	}

// 	if isAllEqual() && n%2 == 0 {
// 		fmt.Println("HL")
// 	} else {
// 		fmt.Println("T")
// 	}
// }

func isAllEqual() bool {
	memo := make(map[int]int)
	for _, a := range A {
		memo[a]++
	}

	if len(memo) == 1 {
		return true
	}
	return false
}

/*******************************************************************/

/********** common constants **********/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

// modint can calculate a right residual whether value is positive or negative.
func modint(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

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

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

func solve() {
	var n int
	scanf("%d\n", &n)
	var a []int = make([]int, n)
	var cnt int = 0
	for i := 0; i < n-1; i++ {
		scanf("%d ", &a[i])
	}
	scanf("%d\n", &a[n-1])
	var sum int = 0
	for _, v := range a {
		sum += v
	}

	for _, v := range a {
		if v > sum / 2 {
			printf("T\n")
			return
		}
		if v > (sum - 1) / 2 {
			cnt++
		}
	}

	if sum&1 == 0 {
		printf("HL\n")
		return
	}

	if cnt > 1 {
		printf("HL\n")
	} else {
		printf("T\n")
	}

}

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

/*
URL:
https://codeforces.com/contest/1396/problem/B
*/

package main

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

var (
	t int

	n int
	A []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

const (
	FIRST, SECOND = "T", "HL"
)

func solve() {
	S := sum(A...)
	maxi := max(A...)

	if maxi > S/2 {
		printf("%s\n", FIRST)
		return
	}

	if S%2 == 0 {
		printf("%s\n", SECOND)
	} else {
		printf("%s\n", FIRST)
	}
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		sum, max := 0, 0
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			sum += v
			if v > max {
				max = v
			}
		}
		if max > sum-max || sum&1 > 0 {
			Println("T")
		} else {
			Println("HL")
		}
	}
}

/*
URL:
https://codeforces.com/contest/1397/problem/D
*/

package main

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

var (
	t int
	n int
	A []int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	if n == 1 {
		fmt.Println("T")
		return
	}

	if isAllEqual() && n%2 == 0 {
		fmt.Println("HL")
	} else {
		fmt.Println("T")
	}
}

func isAllEqual() bool {
	memo := make(map[int]int)
	for _, a := range A {
		memo[a]++
	}

	if len(memo) == 1 {
		return true
	}
	return false
}

/*******************************************************************/

/********** common constants **********/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

// modint can calculate a right residual whether value is positive or negative.
func modint(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*
URL:
https://codeforces.com/contest/1397/problem/D
*/

package main

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

var (
	t int
	n int
	A []int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	if n == 1 {
		fmt.Println("T")
		return
	}

	if isAllEqual() {
		fmt.Println("HL")
	} else {
		fmt.Println("T")
	}
}

func isAllEqual() bool {
	memo := make(map[int]int)
	for _, a := range A {
		memo[a]++
	}

	if len(memo) == 1 {
		return true
	}
	return false
}

/*******************************************************************/

/********** common constants **********/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

// modint can calculate a right residual whether value is positive or negative.
func modint(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*
URL:
https://codeforces.com/contest/1397/problem/D
*/

package main

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

var (
	t int
	n int
	A []int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	f := func(lv, rv T) T {
		// return T(math.Min(float64(lv), float64(rv)))
		if lv.val > rv.val {
			return lv
		}
		return rv
	}
	// ti := T(1<<31 - 1)
	ti := T{-INF_BIT30, -1}
	st := NewSegmentTree(n, f, ti)

	for i := 0; i < n; i++ {
		st.Set(i, T{A[i], i})
	}
	st.Build()

	turn := 0
	befIdx := -1
	for {
		t := st.Query(0, n)
		if t.val == 0 || t.idx == befIdx {
			if turn%2 == 0 {
				fmt.Println("HL")
			} else {
				fmt.Println("T")
			}
			return
		}

		befIdx = t.idx
		st.Update(t.idx, T{t.val - 1, t.idx})

		turn++
	}
}

// type T int // (T, f): Monoid
type T struct {
	val int
	idx int
}

type SegmentTree struct {
	sz   int              // minimum power of 2
	data []T              // elements in T
	f    func(lv, rv T) T // T <> T -> T
	ti   T                // identity element of Monoid
}

func NewSegmentTree(
	n int, f func(lv, rv T) T, ti T,
) *SegmentTree {
	st := new(SegmentTree)
	st.ti = ti
	st.f = f

	st.sz = 1
	for st.sz < n {
		st.sz *= 2
	}

	st.data = make([]T, 2*st.sz-1)
	for i := 0; i < 2*st.sz-1; i++ {
		st.data[i] = st.ti
	}

	return st
}

func (st *SegmentTree) Set(k int, x T) {
	st.data[k+(st.sz-1)] = x
}

func (st *SegmentTree) Build() {
	for i := st.sz - 2; i >= 0; i-- {
		st.data[i] = st.f(st.data[2*i+1], st.data[2*i+2])
	}
}

func (st *SegmentTree) Update(k int, x T) {
	k += st.sz - 1
	st.data[k] = x

	for k > 0 {
		k = (k - 1) / 2
		st.data[k] = st.f(st.data[2*k+1], st.data[2*k+2])
	}
}

func (st *SegmentTree) Query(a, b int) T {
	return st.query(a, b, 0, 0, st.sz)
}

func (st *SegmentTree) query(a, b, k, l, r int) T {
	if r <= a || b <= l {
		return st.ti
	}

	if a <= l && r <= b {
		return st.data[k]
	}

	lv := st.query(a, b, 2*k+1, l, (l+r)/2)
	rv := st.query(a, b, 2*k+2, (l+r)/2, r)
	return st.f(lv, rv)
}

func (st *SegmentTree) Get(k int) T {
	return st.data[k+(st.sz-1)]
}

// func solve() {
// 	if n == 1 {
// 		fmt.Println("T")
// 		return
// 	}

// 	if isAllEqual() && n%2 == 0 {
// 		fmt.Println("HL")
// 	} else {
// 		fmt.Println("T")
// 	}
// }

func isAllEqual() bool {
	memo := make(map[int]int)
	for _, a := range A {
		memo[a]++
	}

	if len(memo) == 1 {
		return true
	}
	return false
}

/*******************************************************************/

/********** common constants **********/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

// modint can calculate a right residual whether value is positive or negative.
func modint(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

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

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

func solve() {
	var n int
	scanf("%d\n", &n)
	var a []int = make([]int, n)
	var cnt int = 0
	for i := 0; i < n-1; i++ {
		scanf("%d ", &a[i])
		if a[i] > n/2 {
			printf("T\n")
			return
		}
		if a[i] > (n-1)/2 {
			cnt++
		}
	}
	scanf("%d\n", &a[n-1])
	if a[n-1] > n/2 {
		printf("T\n")
		return
	}

	if n&1 == 0 {
		printf("HL\n")
		return
	}

	if cnt > 1 {
		printf("HL\n")
	} else {
		printf("T\n")
	}

}

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


You are given a string $$$s$$$ consisting only of lowercase Latin letters.You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — number of queries. Each of the next $$$t$$$ lines contains one string. The $$$i$$$-th line contains a string $$$s_i$$$ consisting only of lowercase Latin letter. It is guaranteed that the length of $$$s_i$$$ is from $$$1$$$ to $$$1000$$$ (inclusive).

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: -1 if it is impossible to obtain a good string by rearranging the letters of $$$s_i$$$ and any good string which can be obtained from the given one (by rearranging the letters) otherwise.

NoteIn the first query we cannot rearrange letters to obtain a good string.Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".In the third query we can do nothing to obtain a good string.

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(buf, "%d\n", &t)
	for i := 1; i <= t; i++ {
		var str string
		fmt.Fscanf(buf, "%s\n", &str)
		strb := []byte(str)
		l := len(strb)
		if l <= 1 {
			fmt.Printf("-1\n")
			continue
		}
		var flag bool = false

		for i := 1; i < l; i++ {
			if strb[i] != strb[0] {
				tmp := strb[i]
				strb[i] = strb[l-1]
				strb[l-1] = tmp
				flag = true
				break
			}
		}
		if flag{
			fmt.Printf("%s\n",string(strb))
		}else{
			fmt.Printf("-1\n")
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	var s string

	fmt.Scanf("%d\n", &n)
	for n > 0 {
		n--

    var mark []int = make([]int, 26)
		fmt.Scanf("%s\n", &s)
		for i := 0; i < len(s); i++ {
      mark[s[i] - 97]++
    }

    var cnt int = 0
    for _, num := range(mark) {
      if num > 0 {
        cnt++
      }
    }

    if cnt == 1 {
      fmt.Println(-1)
    } else {
      var s string = ""
      for i, num := range(mark) {
        for j := 0; j < num; j++ {
          s += string(i + 97)
        }
      }
      fmt.Println(s)
    }
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

func SortString(w string) string {
	s := strings.Split(w, "")
	sort.Strings(s)
	return strings.Join(s, "")
}

func isPalindrome(s string) bool {
	for i, j := 0, len(s) - 1; i < j; i, j = i + 1, j - 1 {
		if s[i] != s[j] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Scan(&s)
		s = SortString(s)
		if isPalindrome(s) {
			fmt.Println("-1")
		} else {
			fmt.Println(s)
		}
	}
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		s := reads()
		ss, ok := solve(s)
		if !ok {
			println(-1)
		} else {
			println(ss)
		}
	}
}

func solve(s string) (string, bool) {
	b := []byte(s)
	if !check(b) {
		return s, true
	}
	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
		if b[i] != b[i+1] {
			b[i], b[i+1] = b[i+1], b[i]
			return string(b), true
		}
	}
	return "", false
}

func check(b []byte) bool {
	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
		if b[i] != b[j] {
			return false
		}
	}
	return true
}

package main
import (
	"fmt"
	"sort"
	"strings"
)

func isPolyndrom(cipher string) bool{
	length := len(cipher)
	for i := 0; i < length / 2; i++ {
		if cipher[i] != cipher[length - i - 1] {
			return false
		}
	}

	return true
}

func main() {
	var request int

	fmt.Scan(&request)

	for i := 0; i < request; i++ {
		var cipher string
		fmt.Scan(&cipher)

		if isPolyndrom(cipher) == false {
			fmt.Printf("%s\n", cipher)
			continue
		}

		split := strings.Split(cipher, "")
		sort.Strings(split)
		newCipher := strings.Join(split, "")

		if newCipher != cipher {
			fmt.Printf("%s\n", newCipher)
		} else {
			fmt.Printf("-1\n")
		}

	}

}


A flowerbed has many flowers and two fountains.You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower. It is guaranteed that all n + 2 points in the input are distinct.

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

NoteThe first sample is (r12 = 5, r22 = 1):  The second sample is (r12 = 1, r22 = 32):

package main

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

type i64pair struct {
    first int64
    second int64
}

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

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

type i64pairArray []i64pair

func (q i64pairArray) Len() int {
    return len(q)
}

func (q i64pairArray) Swap(i, j int) {
    q[i], q[j] = q[j], q[i]
}

func (q i64pairArray) Less(i, j int) bool {
    if q[i].first < q[j].first {
        return true
    } else if q[i].first > q[j].first {
        return false
    } else {
        if q[i].second < q[j].second {
            return true
        } else {
            return false
        }
    }
}

func main() {
    stin := bufio.NewScanner(os.Stdin)
    stin.Scan()
    ss := strings.Fields(stin.Text())
    n,_ := strconv.Atoi(ss[0])
    x1,_ := strconv.ParseInt(ss[1], 10, 64)
    y1,_ := strconv.ParseInt(ss[2], 10, 64)
    x2,_ := strconv.ParseInt(ss[3], 10, 64)
    y2,_ := strconv.ParseInt(ss[4], 10, 64)
    var dist i64pairArray
    for i := 0; i < n; i++ {
        stin.Scan()
        si := strings.Fields(stin.Text())
        x,_ := strconv.ParseInt(si[0], 10, 64)
        y,_ := strconv.ParseInt(si[1], 10, 64)
        q := i64pair{first: (x-x1)*(x-x1) + (y-y1)*(y-y1), second: (x-x2)*(x-x2) + (y-y2)*(y-y2)}
        dist = append(dist, q)
    }
    sort.Sort(dist)
    var maxsuf []int64 = make([]int64, n+1)

    for i := n-1; i >= 0; i-- {
        maxsuf[i] = max(maxsuf[i + 1], dist[i].second)
    }

    var result int64 = min(dist[n - 1].first, maxsuf[0])
    for i := 0; i < n; i++ {
        r1 := dist[i].first
        r2 := maxsuf[i + 1]
        result = min(result, r1 + r2)
    }
    fmt.Printf("%d", result)
}

package main

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

const (
	maxN = 2010
)

var N int
var x1, y1, x2, y2 int64
var X [maxN]int
var Y [maxN]int
var D1 [maxN]int64
var D2 [maxN]int64

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	x1, y1, x2, y2 := fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64()
	for i := 0; i < N; i++ {
		X[i] = fsc.NextInt()
		Y[i] = fsc.NextInt()
	}

	for i := 0; i < N; i++ {
		var dist1, dist2 int64
		var x, y int64
		x = int64(X[i])
		y = int64(Y[i])
		dist1 = (x-x1)*(x-x1) + (y-y1)*(y-y1)
		dist2 = (x-x2)*(x-x2) + (y-y2)*(y-y2)
		D1[i] = dist1
		D2[i] = dist2
		// fmt.Println(dist1, dist2)
	}
	var result int64
	result = (1 << 62)
	for i := 0; i < N; i++ {
		r1 := D1[i]
		r2 := int64(0)
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r1 < d1 {
				if r2 < d2 {
					r2 = d2
				}
			} else if r1 >= d1 {
				continue
			}
		}
		if result > r1+r2 {
			result = r1 + r2
		}
	}
	for i := 0; i < N; i++ {
		r1 := int64(0)
		r2 := D2[i]
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r2 < d2 {
				if r1 < d1 {
					r1 = d1
				}
			} else if r2 >= d2 {
				continue
			}
		}
		if result > r1+r2 {
			result = r1 + r2
		}
	}

	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	maxN = 2010
)

var N int
var x1, y1, x2, y2 int64
var X [maxN]int
var Y [maxN]int
var D1 [maxN]int64
var D2 [maxN]int64

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	x1, y1, x2, y2 := fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64()
	for i := 0; i < N; i++ {
		X[i] = fsc.NextInt()
		Y[i] = fsc.NextInt()
	}

	for i := 0; i < N; i++ {
		var dist1, dist2 int64
		var x, y int64
		x = int64(X[i])
		y = int64(Y[i])
		dist1 = (x-x1)*(x-x1) + (y-y1)*(y-y1)
		dist2 = (x-x2)*(x-x2) + (y-y2)*(y-y2)
		D1[i] = dist1
		D2[i] = dist2
	}
	var result int64
	result = (1 << 62)
	for i := 0; i < N; i++ {
		r1 := D1[i]
		r2 := int64(0)
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r1 < d1 {
				if r2 < d2 {
					r2 = d2
				}
			} else if r1 >= d1 {
				continue
			}
		}
		if result > r1+r2 {
			result = r1 + r2
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	maxN = 2010
)

var N int
var x1, y1, x2, y2 int64
var X [maxN]int
var Y [maxN]int
var D1 [maxN]int64
var D2 [maxN]int64

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	x1, y1, x2, y2 := fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64()
	for i := 0; i < N; i++ {
		X[i] = fsc.NextInt()
		Y[i] = fsc.NextInt()
	}

	for i := 0; i < N; i++ {
		var dist1, dist2 int64
		var x, y int64
		x = int64(X[i])
		y = int64(Y[i])
		dist1 = (x-x1)*(x-x1) + (y-y1)*(y-y1)
		dist2 = (x-x2)*(x-x2) + (y-y2)*(y-y2)
		D1[i] = dist1
		D2[i] = dist2
	}
	var result int64
	result = (1 << 62)
	for i := 0; i < N; i++ {
		r1 := D1[i]
		r2 := int64(0)
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r1 < d1 {
				if d1 <= d2 {
					if r2 < d1 {
						r2 = d1
					}
				} else {
					if r2 < d2 {
						r2 = d2
					}
				}
			} else if r1 >= d1 {
				continue
			}
		}
		// fmt.Println(r1 + r2)
		if result > r1+r2 {
			result = r1 + r2
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

const (
	maxN = 2010
)

var N int
var x1, y1, x2, y2 int64
var X [maxN]int
var Y [maxN]int
var D1 [maxN]int64
var D2 [maxN]int64

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	x1, y1, x2, y2 := fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64(), fsc.NextInt64()
	for i := 0; i < N; i++ {
		X[i] = fsc.NextInt()
		Y[i] = fsc.NextInt()
	}

	for i := 0; i < N; i++ {
		var dist1, dist2 int64
		var x, y int64
		x = int64(X[i])
		y = int64(Y[i])
		dist1 = (x-x1)*(x-x1) + (y-y1)*(y-y1)
		dist2 = (x-x2)*(x-x2) + (y-y2)*(y-y2)
		D1[i] = dist1
		D2[i] = dist2
		fmt.Println(dist1, dist2)
	}
	var result int64
	result = (1 << 62)
	for i := 0; i < N; i++ {
		r1 := D1[i]
		r2 := int64(0)
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r1 < d1 {
				if r2 < d2 {
					r2 = d2
				}
			} else if r1 >= d1 {
				continue
			}
		}
		if result > r1+r2 {
			result = r1 + r2
		}
	}
	for i := 0; i < N; i++ {
		r1 := int64(0)
		r2 := D2[i]
		for j := 0; j < N; j++ {
			d1 := D1[j]
			d2 := D2[j]
			if r2 < d2 {
				if r1 < d1 {
					r1 = d1
				}
			} else if r2 >= d2 {
				continue
			}
		}
		if result > r1+r2 {
			result = r1 + r2
		}
	}

	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i + 1 for all i from 1 to k - 1. Now he wonders how many different ways this can happen.

The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors. Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000). The total number of balls doesn't exceed 1000.

A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.

NoteIn the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: 1 2 1 2 31 1 2 2 32 1 1 2 3

package main

import "fmt"

const mod = 1000000007

func fastPow(x, y int64) int64 {
    var ret int64 = 1
    for i := uint(0); (1 << i) <= y; i++ {
        if (y & (1 << i)) > 0 {
            ret = ret * x % mod
        }
        x = x * x % mod
    }
    return ret
}

func main() {
    var k int
    fmt.Scan(&k)
    c := make([]int64, k)
    for i := 0; i < k; i++ {
        fmt.Scan(&c[i])
        if i > 0 {
            c[i] += c[i-1]
        }
    }
    var m = c[k-1]
    fact := make([]int64, c[k-1])
    fact[0] = 1
    for i := int64(1); i < m; i++ {
        fact[i] = fact[i-1] * i % mod
    }
    ans := int64(1)
    var n int64
    for i := 1; i < k; i++ {
        n = c[i] - 1
        m = c[i] - c[i-1] - 1
        ans = ans * fact[n] % mod * fastPow(fact[m]*fact[n-m]%mod, mod-2) % mod
    }
    fmt.Println(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF553A(_r io.Reader, _w io.Writer) {
	const mod int64 = 1e9 + 7
	const mx int = 1e3
	C := [mx + 1][mx + 1]int64{}
	for i := 0; i <= mx; i++ {
		C[i][0] = 1
		for j := 1; j < i; j++ {
			C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod
		}
		C[i][i] = 1
	}

	in := bufio.NewReader(_r)
	var n, c, sum int
	ans := int64(1)
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &c)
		sum += c
		ans = ans * C[sum-1][c-1] % mod
	}
	Fprint(_w, ans)
}

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


You are given an integer $$$n$$$. Find any string $$$s$$$ of length $$$n$$$ consisting only of English lowercase letters such that each non-empty substring of $$$s$$$ occurs in $$$s$$$ an odd number of times. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single line containing the string $$$s$$$. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.

NoteIn the first test case, each substring of "abc" occurs exactly once.In the third test case, each substring of "bbcaabbba" occurs an odd number of times. In particular, "b" occurs $$$5$$$ times, "a" and "bb" occur $$$3$$$ times each, and each of the remaining substrings occurs exactly once.

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	if n == 1 {
		printf("a\n")
		return
	}
	var a = make([]byte, n)
	for i := range a {
		a[i] = 'a'
	}
	a[n/2] = 'b'
	if n%2 == 1 {
		a[n/2+1] = 'c'
	}
	for i := range a {
		printf("%v", string(a[i]))
	}
	printf("\n")
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    var testCases int
    var length int
    fmt.Scan(&testCases)

    for i := 0; i < testCases; i++ {
        fmt.Scan(&length)
        if length == 1 {
            fmt.Println("a")
            continue
        }
        k := length / 2
        before := strings.Repeat("a", k)
        after := ""
        if k > 1 {
            after = strings.Repeat("a", k-1)
        }
        if length % 2 == 0 {
            fmt.Printf("%sb%s\n", before, after)
        } else {
            fmt.Printf("%sbc%s\n", before, after)
        }
    }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1554D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		if n == 1 {
			Fprintln(out, "a")
		} else {
			Fprintln(out, strings.Repeat("a", n/2)+"b"+strings.Repeat("a", n&^1-n/2-1)+strings.Repeat("c", n&1))
		}
	}
}
func main() { CF1554D(os.Stdin, os.Stdout) }

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

func main() {
	defer out.Flush()
	for t := Read(); t > 0; t-- {
		n := Read()
		m := n / 2
		for i := 0; i < m; i++ {
			Fprint(out, "a")
		}
		Fprint(out, "b")
		for i := 0; i < m-1; i++ {
			Fprint(out, "a")
		}
		if n > 1 && n%2 == 1 {
			Fprint(out, "c")
		}
		Fprintln(out)
	}
}

package main

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

// 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
	}
}

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)

		if n%2 == 0 {
			q := int(n / 2)
			var s string
			for i := 1; i < q; i++ {
				s = s + "b"
			}
			s = s + "bj" + s
			fmt.Println(s)

		} else {
			if n > 1 {
				q := int(n / 2)
				var s string
				for i := 1; i < q; i++ {
					s = s + "b"
				}
				s = s + "bja" + s
				fmt.Println(s)
			} else {
				fmt.Println("b")
			}
		}

	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		fmt.Println(solve(n))
	}
}

func solve(n int) string {

	if n == 1 {
		return "b"
	} else if n == 2 {
		return "ab"
	} else if n == 3 {
		return "abc"
	}

	if n % 2 == 0 {
		var bts bytes.Buffer
		for j := 0; j < n/2; j++ {
			bts.WriteByte('b')
		}
		bts.WriteByte('a')

		for j := 0; j < n/2 - 1; j++ {
			bts.WriteByte('b')
		}

		return bts.String()
	}

	var bts bytes.Buffer

	bts.WriteByte('c')

	for j := 0; j < (n - 1)/2; j++ {
		bts.WriteByte('b')
	}
	bts.WriteByte('a')

	for j := 0; j < (n - 1)/2 - 1; j++ {
		bts.WriteByte('b')
	}

	return bts.String()

	//10

	//bbbbbabbbb

	//2 - 5
	//3 - 5
	//

	//cbbbabb
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    var testCases int
    var length int
    fmt.Scan(&testCases)

    for i := 0; i < testCases; i++ {
        fmt.Scan(&length)
        k := length / 2
        before := strings.Repeat("a", k)
        after := ""
        if k > 1 {
            after = strings.Repeat("a", k-1)
        }
        if length % 2 == 0 {
            fmt.Printf("%sb%s\n", before, after)
        } else {
            fmt.Printf("%sbc%s\n", before, after)
        }
    }
}

package main

import (
    "fmt"
    "strings"
)

func main() {
    var testCases int
    var length int
    fmt.Println("Reading testcases")
    fmt.Scan(&testCases)

    for i := 0; i < testCases; i++ {
        fmt.Scan(&length)
        k := length / 2
        before := strings.Repeat("a", k)
        after := strings.Repeat("a", k-1)
        if length % 2 == 0 {
            fmt.Printf("%sb%s\n", before, after)
        } else {
            fmt.Printf("%sbc%s\n", before, after)
        }
    }
}

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

func main() {
	defer out.Flush()
	for t := Read(); t > 0; t-- {
		n := Read()
		m := n / 2
		for i := 0; i < m; i++ {
			Fprint(out, "a")
		}
		Fprint(out, "b")
		for i := 0; i < m-1; i++ {
			Fprint(out, "a")
		}
		if n%2 == 1 {
			Fprint(out, "c")
		}
		Fprintln(out)
	}
}

package main

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

// 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
	}
}

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)

		if n%2 == 0 {
			q := int(n / 2)
			var s string
			for i := 1; i < q; i++ {
				s = s + "b"
			}
			s = s + "bj" + s
			fmt.Println(s)

		} else {
			q := int(n / 2)
			var s string
			for i := 1; i < q; i++ {
				s = s + "b"
			}
			s = s + "bja" + s
			fmt.Println(s)

		}

	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		fmt.Println(solve(n))
	}
}

func solve(n int) string {

	if n == 1 {
		return "b"
	} else if n == 2 {
		return "abc"
	} else if n == 3 {
		return "abc"
	}

	if n % 2 == 0 {
		var bts bytes.Buffer
		for j := 0; j < n/2; j++ {
			bts.WriteByte('b')
		}
		bts.WriteByte('a')

		for j := 0; j < n/2 - 1; j++ {
			bts.WriteByte('b')
		}

		return bts.String()
	}

	var bts bytes.Buffer

	bts.WriteByte('c')

	for j := 0; j < (n - 1)/2; j++ {
		bts.WriteByte('b')
	}
	bts.WriteByte('a')

	for j := 0; j < (n - 1)/2 - 1; j++ {
		bts.WriteByte('b')
	}

	return bts.String()

	//10

	//bbbbbabbbb

	//2 - 5
	//3 - 5
	//

	//cbbbabb
}


Igor is in 11th grade. Tomorrow he will have to write an informatics test by the strictest teacher in the school, Pavel Denisovich. Igor knows how the test will be conducted: first of all, the teacher will give each student two positive integers $$$a$$$ and $$$b$$$ ($$$a < b$$$). After that, the student can apply any of the following operations any number of times:   $$$a := a + 1$$$ (increase $$$a$$$ by $$$1$$$),  $$$b := b + 1$$$ (increase $$$b$$$ by $$$1$$$),  $$$a := a \ | \ b$$$ (replace $$$a$$$ with the bitwise OR of $$$a$$$ and $$$b$$$). To get full marks on the test, the student has to tell the teacher the minimum required number of operations to make $$$a$$$ and $$$b$$$ equal.Igor already knows which numbers the teacher will give him. Help him figure out what is the minimum number of operations needed to make $$$a$$$ equal to $$$b$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line for each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a < b \le 10^6$$$). It is guaranteed that the sum of $$$b$$$ over all test cases does not exceed $$$10^6$$$.

For each test case print one integer — the minimum required number of operations to make $$$a$$$ and $$$b$$$ equal.

NoteIn the first test case, it is optimal to apply the third operation.In the second test case, it is optimal to apply the first operation three times.In the third test case, it is optimal to apply the second operation and then the third operation.

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		s := 999999999
		for i:=a;i<=b;i++{
			if (b|i)==b{
				s = i-a+1
				break
			}
		}
		fmt.Fprintln(out,min(s,min(ans+1,b-a)))
	}
}

package main

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

// unfixed
func solve(a, b int) int {
	ans := b - a
	for i := 0; i < b-a; i++ {
		ans = min(ans, ((a+i)|b-b)+i+1)
	}

	for i := 0; i < b-a; i++ {
		c := b + i
		if c|a == c {
			ans = min(ans, i+1)
		}
	}
	return ans
}

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

	var T int
	var a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, solve(a, b))
	}
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func main() {
	CF1632C(os.Stdin, os.Stdout)
}

package main

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

var (
	DistanceStepsMap []int
)

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 readInt64(in *bufio.Reader) uint64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseUint(nStr, 10, 64)

	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
}

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

	return line
}

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

	return b
}

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

	return b
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}

	return r
}

func SwapInt(a *int, b *int) {
	t := *a
	*a = *b
	*b = t
}

func solve(a int, b int) {
	gap := b - a

	if gap == 0 {
		fmt.Println(0)
	}

	// After performing OR operation, b will be less equal a, eg. for a < b, b <= a | b

	// min steps without performing OR operation
	noOrStep := b - a

	// If perform OR operation
	minStep := math.MaxInt
	//var finalA, finalB int
	for a_ := a; a_ < b; a_++ {
		b_ := 0
		for bit := 1 << 20; bit != 0; bit >>= 1{
			//fmt.Printf("bit: %8x\n", bit)
			aMask := a_ & bit
			bMask := b & bit

			if !(aMask == 0 && bMask == 0) {
				b_ |= bit
			}

			if aMask > 0 && !(bMask > 0){
				break
			}

			//bit <<= 1
		}

		if (a_ | b_ + a_) + (1 - a - b) < minStep {
			minStep = (a_ | b_ + a_) + (1 - a - b)
			//finalA = a_
			//finalB = b_
		}
	}

	//fmt.Println(finalA, finalB)
	fmt.Println(Min(minStep, noOrStep))

}

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

	tc := readInt(in)
	//tc := 1

	//solve()

	for i := 0; i < tc; i++ {
		f := readArrInt(in)
		solve(f[0], f[1])
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

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

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

func solveB(a, b int) int {
	// can only do b++ and a|=b
	x := b | a
	for i := 0; i < 24; i++ {
		if ((x>>i)&1) > 0 && (x^(1<<i)) >= b && (a&(x^(1<<i))) == a {
			x ^= (1 << i)
		}
	}
	return (x - b) + 1
}

func solveCase(a, b int) int {
	if a >= b {
		return a - b
	}
	r := b - a
	cur := 0
	for a < b {
		r = min(r, cur+1+abs((a|b)-b))
		r = min(r, solveB(a, b)+cur)
		a++
		cur++
	}
	return r
}

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var a, b int
		scan(&a, &b)
		printf("%d\n", solveCase(a, b))
	}
}

// 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 a, b int
		fmt.Fscan(reader, &a, &b)
		c1, c2 := 0, 0
		y := b
		for a|y != y {
			y++
			c1++
		}
		if a != y {
			c1++
		}
		for a|b != b {
			a++
			c2++
		}
		if a != b {
			c2++
		}
		if c2 < c1 {
			c1 = c2
		}
		fmt.Println(c1)

	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1632C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		c1, c2 := 0, 0
		y := b
		for a|y != y {
			y++
			c1++
		}
		if a != y {
			c1++
		}
		for a|b != b {
			a++
			c2++
		}
		if a != b {
			c2++
		}
		if c2 < c1 {
			c1 = c2
		}
		Fprintln(out, c1)
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		s := 999999999
		for i:=0;i<=31;i++{
			m = 1<<i
			if (m&b)>a{
				s = (m&b)-a+1
			}
		}
		fmt.Fprintln(out,min(s,min(ans+1,b-a)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		s := 0
		for i:=0;i<=31;i++{
			m = 1<<i
			if (m&b)>a{
				s = (m&b)-a+1
			}
		}
		fmt.Fprintln(out,min(s,min(ans+1,b-a)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		if ct==42{
			fmt.Fprintln(out,a)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		if ct==42{
			fmt.Fprintln(out,b)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		if t==42{
			fmt.Fprintln(out,b)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		if t==4{
			fmt.Fprintln(out,b)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		if t==4{
			fmt.Fprintln(out,a)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func min(x, y int)int{
	if x<y{
		return x
	}
	return y
}
func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for ct:=1;ct<=t;ct++{
		var a, b int
		fmt.Fscan(in,&a,&b)
		ans := 0
		m := 1
		f:= false
		yota := 0
		tmp := 0
		for i:=31;i>=0;i--{
			m = 1<<i
			if f{
				ans += m&a
				tmp += m&b
			}
			if (m&a)!=0&&(m&b)==0{
				if !f{
					yota = m&a
					f=true
				}
			}
		}
		ans += yota-tmp
		if !f{
			fmt.Fprintln(out,1)
			continue
		}
		fmt.Fprintln(out,min(ans+1,b-a))
	}
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

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

func solveCase(a, b int) int {
	if a >= b {
		return a - b
	}
	r := b - a
	cur := 0
	for a != b {
		if (a | b) == b {
			a |= b
			cur++
		} else {
			b++
			cur++
		}
		r = min(r, cur+b-a)
	}
	return r
}

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var a, b int
		scan(&a, &b)
		printf("%d\n", solveCase(a, b))
	}
}


A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.You are given a regular bracket sequence $$$s$$$ and an integer number $$$k$$$. Your task is to find a regular bracket sequence of length exactly $$$k$$$ such that it is also a subsequence of $$$s$$$.It is guaranteed that such sequence always exists.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 2 \cdot 10^5$$$, both $$$n$$$ and $$$k$$$ are even) — the length of $$$s$$$ and the length of the sequence you are asked to find. The second line is a string $$$s$$$ — regular bracket sequence of length $$$n$$$.

Print a single string — a regular bracket sequence of length exactly $$$k$$$ such that it is also a subsequence of $$$s$$$. It is guaranteed that such sequence always exists.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, k int
	var s string
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s", &s)

	show := make([]bool, n)
	stack := make([]int, n)
	top, count := 0, 0
	for i := 0;i < n && count < k;i ++ {
		if s[i] == '(' {
			stack[top] = i
			top ++
		} else if top != 0 {
			show[stack[top - 1]] = true
			show[i] = true
			top --
			count += 2
		}
	}
	ans := make([]byte, 0, k)
	for i := 0;i < n;i ++ {
		if show[i] {
			ans = append(ans, s[i])
		}
	}
	fmt.Printf("%s", string(ans))
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n,k int
	Scan(&n,&k)
	if k==2{
		Print("()")
		return
	}
	in:=bufio.NewReader(os.Stdin)
	var s string
	Fscan(in,&s)

	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	if n==k{
		Fprint(out,s)
		return
	}
	open:=(n-k)>>1
	close:=open
	for i:=0;i<n;i++{
		if s[i]=='('{
			if open>0{
				open--
			}else{
				Fprint(out,string(s[i]))
			}
		}else{
			if close>0{
				close--
			}else{
				Fprint(out,string(s[i]))
			}
		}
	}
}

package main

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

func main()  {

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

	var n, k int
	fmt.Fscan(in, &n, &k)

	var s string
	fmt.Fscan(in, &s)

	x := (n - k) / 2
	s = strings.Replace(strings.Replace(s, "(", "", x), ")", "", x)

	fmt.Fprintln(out, s)
	return

}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	var str string
	fmt.Fscan(reader, &str)

	var cnt, mnt int
	for i := 0; i < n; i++ {
		if str[i] == '(' && cnt < m/2 {
			fmt.Print("(")
			cnt++
		} else if str[i] == ')' && mnt < cnt {
			fmt.Print(")")
			mnt++
		}
	}

	fmt.Println()
}

package main

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

func main()  {

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

	var n, k int
	fmt.Fscan(in, &n, &k)

	var s string
	fmt.Fscan(in, &s)
	s += "("

	result := make([]byte, n)
	resultPos := 0

	open, close := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			if close > 0 {
				if resultPos + close * 2 > k {
					close = (k - resultPos) / 2
				}
				for j := 0; j < close; j++ {
					result[resultPos] = '('
					resultPos++
				}
				for j := 0; j < close; j++ {
					result[resultPos] = ')'
					resultPos++
				}
				if resultPos == k {
					break
				}
				open -= close
				close = 0
			}
			open++
		} else {
			if open == close {
				continue
			}
			close++
		}
	}

	for i := 0; i < k; i++ {
		fmt.Fprint(out, string(result[i]))
	}

}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	var str string
	fmt.Fscan(reader, &str)

	var cnt, mnt int
	for i := 1; i < n; i++ {
		if str[i] == '(' && cnt < m/2 {
			fmt.Print("(")
			cnt++
		} else if str[i] == ')' && mnt < cnt {
			fmt.Print(")")
			mnt++
		}
	}

	fmt.Println()
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	var str string
	fmt.Fscan(reader, &str)

	bt := []rune(str)

	for i := 1; i < n; i++ {
		if bt[i-1] == '(' && bt[i] == ')' && n > m {
			bt[i-1], bt[i] = '*', '*'
			m += 2
		}
	}

	for _, vl := range bt {
		if vl != '*' {
			fmt.Print(string(vl))
		}
	}
}