package main

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

func main(){
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for (t>0){
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i:=0; i<n; i++{
			fmt.Fscan(in, &a[i])
		}

		sort.Ints(a)

		x := int64(0)
		y := int64(0)
		for i:=n-1; i>=0; i-=2{
			if (a[i] % 2 == 0){
				x += int64(a[i]);
			}
			if (i-1 >= 0 && a[i-1]%2 == 1){
				y += int64(a[i-1]);
			}
		}
		if (x > y){
			fmt.Println("Alice")
		}else if (y > x){
			fmt.Println("Bob")
		}else {
			fmt.Println("Tie")
		}

		t--
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		println(solve(ReadInts(n)))
	}
}

func solve(a []int) string {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	score := int64(0)
	for i, v := range a {
		if i%2 == 0 && v%2 == 0 {
			score += int64(v)
		}
		if i%2 == 1 && v%2 == 1 {
			score -= int64(v)
		}
	}

	if score == 0 {
		return "Tie"
	}
	if score > 0 {
		return "Alice"
	}
	return "Bob"
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		sc.NextInt()
		a := sc.NextIntArray()
		fmt.Println(solve(a))
	}

}

func solve(a []int) string {
	sort.Ints(a)
	reverse(a, 0, len(a))
	score := int64(0)
	for i := 0; i < len(a); i++ {
		if a[i]%2 == 0 && i%2 == 0 {
			score += int64(a[i])
		} else if a[i]%2 == 1 && i%2 == 1 {
			score -= int64(a[i])
		}
	}
	if score > 0 {
		return "Alice"
	} else if score < 0 {
		return "Bob"
	} else {
		return "Tie"
	}

}

func reverse(a []int, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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"
	"sort"
)

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(in, &a[i])
		}

		fmt.Fprintln(out, solve2(a, n))

	}

}

func solve2(a []int, n int) string {

	var (
		alice = int64(0)
		bob   = int64(0)
	)

	//quickSort(a, 0, n-1)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for i := range a {

		if i%2 == 0 && a[i]%2 == 0 {
			alice += int64(a[i])
		}

		if i%2 == 1 && a[i]%2 == 1 {
			bob += int64(a[i])
		}

	}

	if alice > bob {
		return "Alice"
	} else if bob > alice {
		return "Bob"
	} else {
		return "Tie"
	}

	//fmt.Println(alice, bob)

}

//逆向氣泡排序
func reverseBobbleSort(array []int) {

	for i := 0; i < len(array)-1; i++ {
		for j := i + 1; j < len(array); j++ {
			if array[j] > array[i] {
				temp := array[i]
				array[i] = array[j]
				array[j] = temp
			}
		}
	}

}

//數字陣列反轉
func reverseInt(array []int) {

	for i := 0; i < len(array)/2; i++ {
		temp := array[i]
		array[i] = array[len(array)-1-i]
		array[len(array)-1-i] = temp
	}

}

func solve(a []int, n int) string {

	var (
		odd  []int
		even []int
		oSum = 0
		eSum = 0
	)

	for i := range a {

		if a[i]%2 == 1 {
			odd = append(odd, a[i])
		} else {
			even = append(even, a[i])
		}

	}

	//printIntArr(odd)
	//printIntArr(even)

	for i := range odd {

		if i >= n/2 {
			break
		}

		oSum += odd[i]

	}

	for i := range even {

		if i > n/2 {
			break
		}

		eSum += even[i]

	}

	//fmt.Println(oSum, eSum)

	if eSum > oSum {
		return "Alice"
	} else if eSum < oSum {
		return "Bob"
	} else {
		return "Tie"
	}

}

//印出數字陣列
func printIntArr(array []int) {

	for i := range array {
		fmt.Printf("%d ", array[i])
	}

	fmt.Println()

}

//快速排序
func quickSort(array []int64, low int, high int) {
	if low < high {
		p := partition(array, low, high)
		quickSort(array, low, p-1)
		quickSort(array, p+1, high)
	}
}
func partition(Array []int64, low int, high int) int {

	pivot := Array[high]
	i := low

	for j := low; j < high; j++ {
		if Array[j] > pivot {
			temp := Array[i]
			Array[i] = Array[j]
			Array[j] = temp
			i++
		}
	}

	temp := Array[i]
	Array[i] = Array[high]
	Array[high] = temp

	return i

}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

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

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

		sort.Ints(a)
		var points [2]int64

		for i, turn := n-1, 0; i >= 0; i, turn = i-1, 1-turn {
			if a[i]%2 == turn {
				points[turn] += int64(a[i])
			}
		}

		if points[0] > points[1] {
			fmt.Println("Alice")
		} else if points[1] > points[0] {
			fmt.Println("Bob")
		} else {
			fmt.Println("Tie")
		}
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%s\n", sol(a))
	}
}

func sol(a []int64) string {
	sort.Slice(a, func(il, ir int) bool {
		return a[il] < a[ir]
	})
	as := int64(0)
	bs := int64(0)
	isAlice := true
	for i := len(a) - 1; i > -1; i-- {
		if isAlice {
			if a[i]&1 == 0 {
				as += a[i]
			}
		} else {
			if a[i]&1 == 1 {
				bs += a[i]
			}
		}
		isAlice = !isAlice
	}
	if as > bs {
		return "Alice"
	}
	if bs > as {
		return "Bob"
	}
	return "Tie"
}

package main

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

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)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}

		var alice int64
		var bob int64

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

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

			if i%2 == 0 {

				if arr[i]%2 == 0 {
					alice += int64(arr[i])
				}

			} else {
				if arr[i]%2 == 1 {
					bob += int64(arr[i])
				}
			}
		}

		if alice == bob {
			fmt.Println("Tie")
		}

		if alice > bob {
			fmt.Println("Alice")
		}

		if bob > alice {
			fmt.Println("Bob")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		var a, b []int64
		for i := 0; i < n; i++ {
			var v int64
			Fscan(in, &v)
			if v&1 == 0 {
				a = append(a, v)
			} else {
				b = append(b, v)
			}
		}
		sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
		sort.Slice(b, func(i, j int) bool { return b[i] > b[j] })

		s := int64(0)
		for i := 0; i < n; i++ {
			if len(a) == 0 {
				if i&1 == 1 {
					s -= b[0]
				}
				b = b[1:]
			} else if len(b) == 0 {
				if i&1 == 0 {
					s += a[0]
				}
				a = a[1:]
			} else {
				if i&1 == 0 {
					if a[0] > b[0] {
						s += a[0]
						a = a[1:]
					} else {
						b = b[1:]
					}
				} else {
					if b[0] > a[0] {
						s -= b[0]
						b = b[1:]
					} else {
						a = a[1:]
					}
				}
			}
		}
		if s > 0 {
			Fprintln(out, "Alice")
		} else if s == 0 {
			Fprintln(out, "Tie")
		} else {
			Fprintln(out, "Bob")
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		var s, prev int64
		s = 0
		prev = 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += int64(v)
					if s < prev {
						out.WriteString("error")
					}
				} else {
					s -= int64(v)
					if s > prev {
						out.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

		sort.Slice(even, func(i, j int) bool { return even[i] < even[j] })
		sort.Slice(odd, func(i, j int) bool { return odd[i] < odd[j] })

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					turn ^= 1
					continue
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					turn ^= 1
					continue
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

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

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

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

// ---

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob int64
    fmt.Fscan(input, &n)
    a := make([]int64, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})

    for i := 0; i < len(a); i++ {
        if i & 1 == 0 {
            if a[i] & 1 == 0 { alice += a[i]}
        } else {
            if a[i] & 1 == 1 { bob += a[i]}
        }
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

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

func Solve() {
	n := ri()
	var st0, st1 Stack
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		x := a[i]
		if x%2 == 0 {
			st0.push(x)
		} else {
			st1.push(x)
		}
	}
	//println(st0.s, st1.s)
	x, y := int64(0), int64(0)
	for i := 0; i < n; i++ {
		if st0.size() == 0 {
			if i%2 == 1 {
				y += int64(st1.top())
			}
			st1.pop()
			continue
		}
		if st1.size() == 0 {
			if i%2 == 0 {
				x += int64(st0.top())
			}
			st0.pop()
			continue
		}
		if i%2 == 0 {
			if st0.top() >= st1.top() {
				x += int64(st0.top())
				st0.pop()
			} else {
				st1.pop()
			}
		} else {
			if st0.top() <= st1.top() {
				y += int64(st1.top())
				st1.pop()
			} else {
				st0.pop()
			}
		}
	}
	//println(x, y)
	switch {
	case x > y:
		println("Alice")
	case x < y:
		println("Bob")
	case x == y:
		println("Tie")
	}
}

func main() {
	T := 0 // 如果是多组样例，请讲 T := 1 改为 T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

var in *bufio.Reader
var out *bufio.Writer

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

// ri64 将直接读入并返回一个 int64
func ri64() (x int64) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。
//注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。
//这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//min64 可以传入多个 int64 变量，求出这些变量的最小值
func min64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//max64 可以传入多个 int64 变量，求出这些变量的最大值
func max64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

//sum64 可以传入多个 int64 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum64(a ...int64) int64 {
	ans := int64(0)
	for _, x := range a {
		ans += x
	}
	return ans
}

//reverse 用于翻转 int 切片，所有元素将会变成原切片的倒序
func reverse(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//reverse64 用于翻转 int64 切片，所有元素将会变成原切片的倒序
func reverse64(a []int64) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//lowerBound 类似于 C++ 中的 lower_bound。
//用于二分查找 int 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int 切片必须升序。
func lowerBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//lowerBound64 类似于 C++ 中的 lower_bound。
//用于二分查找 int64 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int64 切片必须升序。
func lowerBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound 类似于 C++ 中的 upper_bound。
//用于二分查找 int 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int 切片必须升序。
func upperBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound64 类似于 C++ 中的 upper_bound。
//用于二分查找 int64 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int64 切片必须升序。
func upperBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

type Stack struct {
	s []int
}

func (st *Stack) top() int   { return st.s[len(st.s)-1] }
func (st *Stack) size() int  { return len(st.s) }
func (st *Stack) pop()       { st.s = st.s[:len(st.s)-1] }
func (st *Stack) push(x int) { st.s = append(st.s, x) }

type Queue struct {
	que chan int
}

func MakeQueue(size int) Queue {
	var q Queue
	q.que = make(chan int, size)
	return q
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1472/D

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		n := nextNum()
		a := make([]int64, n)
		for i := int64(0); i < n; i++ {
			a[i] = nextNum()
		}
		sort.Sort(sort.Reverse(Ints64(a)))
		score := int64(0)
		for i := int64(0); i < n; i++ {
			if i&1 == 0 {
				if a[i]&1 == 0 {
					score += a[i]
				}
			} else {
				if a[i]&1 == 1 {
					score -= a[i]
				}
			}
		}
		switch {
		case score > 0:
			println("Alice")
		case score < 0:
			println("Bob")
		default:
			println("Tie")
		}
	}
}

func nextNum() int64 {
	in.Scan()
	var r, f int64
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int64(c - '0')
	}
	return r * f
}

type Ints64 []int64

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

package main

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

var tt int

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

	fmt.Fscan(input, &tt)

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}

		var alice int64
		var bob int64

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

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

			if i%2 == 0 {

				if arr[i]%2 == 0 {
					alice += int64(arr[i])
				}

			} else {
				if arr[i]%2 == 1 {
					bob += int64(arr[i])
				}
			}
		}

		if alice == bob {
			fmt.Println("Tie")
		}

		if alice > bob {
			fmt.Println("Alice")
		}

		if bob > alice {
			fmt.Println("Bob")
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		size := ReadInt()
		weights := ReadIntSliceln(size)
		fmt.Println(process(weights))
	}
}

func process(w []int) (ans string) {
	sort.Sort(sort.Reverse(sort.IntSlice(w)))
	var alice, bob int64
	isAlice := true
	for _, v := range w {
		if isAlice {
			if v&1 == 0 {
				alice = alice + int64(v)
			}
		} else {
			if v&1 != 0 {
				bob = bob + int64(v)
			}
		}
		//fmt.Println("Alice:", isAlice, alice, bob)
		isAlice = !isAlice
	}
	if alice == bob {
		return "Tie"
	} else if alice > bob {
		return "Alice"
	}
	return "Bob"
}

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

// ReadInt Read a single integer followed by a space
func ReadInt() (v int) {
	fmt.Fscan(reader, &v)
	return v
}

// ReadIntSliceln reads a line of integers into a slice.
func ReadIntSliceln(size int) []int {
	a := make([]int, size)
	for i := range a {
		fmt.Fscan(reader, &a[i])
	}
	//fmt.Scanf("\n")
	return a
}

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(in, &a[i])
		}

		fmt.Fprintln(out, solve2(a, n))
		//solve2(a, n)

	}

}

func solve2(a []int, n int) string {

	var (
		alice = 0
		bob   = 0
	)

	quickSort(a, 0, n-1)
	reverseInt(a)

	//printIntArr(a)

	for i := range a {

		if i%2 == 0 && a[i]%2 == 0 {
			alice += a[i]
		}

		if i%2 == 1 && a[i]%2 == 1 {
			bob += a[i]
		}

	}

	if alice > bob {
		return "Alice"
	} else if bob > alice {
		return "Bob"
	} else {
		return "Tie"
	}

	//fmt.Println(alice, bob)

}

//數字陣列反轉
func reverseInt(array []int) {

	for i := 0; i < len(array)/2; i++ {
		temp := array[i]
		array[i] = array[len(array)-1-i]
		array[len(array)-1-i] = temp
	}

}

func solve(a []int, n int) string {

	var (
		odd  []int
		even []int
		oSum = 0
		eSum = 0
	)

	for i := range a {

		if a[i]%2 == 1 {
			odd = append(odd, a[i])
		} else {
			even = append(even, a[i])
		}

	}

	//printIntArr(odd)
	//printIntArr(even)

	for i := range odd {

		if i >= n/2 {
			break
		}

		oSum += odd[i]

	}

	for i := range even {

		if i > n/2 {
			break
		}

		eSum += even[i]

	}

	//fmt.Println(oSum, eSum)

	if eSum > oSum {
		return "Alice"
	} else if eSum < oSum {
		return "Bob"
	} else {
		return "Tie"
	}

}

//印出數字陣列
func printIntArr(array []int) {

	for i := range array {
		fmt.Printf("%d ", array[i])
	}

	fmt.Println()

}

//快速排序
func quickSort(array []int, low int, high int) {
	if low < high {
		p := partition(array, low, high)
		quickSort(array, low, p-1)
		quickSort(array, p+1, high)
	}
}
func partition(Array []int, low int, high int) int {

	pivot := Array[high]
	i := low

	for j := low; j < high; j++ {
		if Array[j] < pivot {
			temp := Array[i]
			Array[i] = Array[j]
			Array[j] = temp
			i++
		}
	}

	temp := Array[i]
	Array[i] = Array[high]
	Array[high] = temp

	return i

}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s, prev := 0, 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
					if s < prev {
						out.WriteString("error")
					}
				} else {
					s -= v
					if s > prev {
						out.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	errWriter := bufio.NewWriter(os.Stderr)
	defer out.Flush()
	defer errWriter.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s, prev := 0, 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
					if s < prev {
						errWriter.WriteString("error")
					}
				} else {
					s -= v
					if s > prev {
						errWriter.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s := 0
		for i, v := range p{
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
				} else {
					s -= v
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s := make ([]int, 2)
		for i, v := range p{
			if v%2 == i%2{
				s[i%2]+=v
			}
		}
		ans := "Tie"
		if s[0] > s[1] {
			ans = "Alice"
		} else if s[0] < s[1] {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

		sort.Slice(even, func(i, j int) bool { return even[i] < even[j] })
		sort.Slice(odd, func(i, j int) bool { return odd[i] < odd[j] })

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					continue
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					continue
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

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

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

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

// ---

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

		sort.Slice(even, func(i, j int) bool { return even[i] < even[j] })
		sort.Slice(odd, func(i, j int) bool { return odd[i] < odd[j] })

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					break
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					break
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

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

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

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

// ---

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})
    for i := 0; i < len(a); i++ {
        if i & 1 == 0 {
            if a[i] & 1 == 0 { alice += a[i]}
        } else {
            if a[i] & 1 == 1 { bob += a[i]}
        }
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob, turn int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})
    for len(a) > 0  {
        if turn == 0 {
            if a[0] & 1 == 0 {
                alice += a[0]
            }
        } else {
            if a[0] & 1 == 1 {
                bob += a[0]
            }
        }
        a = a[1:]
        turn ^= 1
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

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

func Solve() {
	n := ri()
	var st0, st1 Stack
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		x := a[i]
		if x%2 == 0 {
			st0.push(x)
		} else {
			st1.push(x)
		}
	}
	//println(st0.s, st1.s)
	x, y := 0, 0
	for i := 0; i < n; i++ {
		if st0.size() == 0 {
			if i%2 == 1 {
				y += st1.top()
			}
			st1.pop()
			continue
		}
		if st1.size() == 0 {
			if i%2 == 0 {
				x += st0.top()
			}
			st0.pop()
			continue
		}
		if i%2 == 0 {
			if st0.top() >= st1.top() {
				x += st0.top()
				st0.pop()
			} else {
				st1.pop()
			}
		} else {
			if st0.top() <= st1.top() {
				y += st1.top()
				st1.pop()
			} else {
				st0.pop()
			}
		}
	}
	//println(x, y)
	switch {
	case x > y:
		println("Alice")
	case x < y:
		println("Bob")
	case x == y:
		println("Tie")
	}
}

func main() {
	T := 0 // 如果是多组样例，请讲 T := 1 改为 T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

var in *bufio.Reader
var out *bufio.Writer

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

// ri64 将直接读入并返回一个 int64
func ri64() (x int64) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。
//注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。
//这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//min64 可以传入多个 int64 变量，求出这些变量的最小值
func min64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//max64 可以传入多个 int64 变量，求出这些变量的最大值
func max64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

//sum64 可以传入多个 int64 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum64(a ...int64) int64 {
	ans := int64(0)
	for _, x := range a {
		ans += x
	}
	return ans
}

//reverse 用于翻转 int 切片，所有元素将会变成原切片的倒序
func reverse(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//reverse64 用于翻转 int64 切片，所有元素将会变成原切片的倒序
func reverse64(a []int64) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//lowerBound 类似于 C++ 中的 lower_bound。
//用于二分查找 int 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int 切片必须升序。
func lowerBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//lowerBound64 类似于 C++ 中的 lower_bound。
//用于二分查找 int64 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int64 切片必须升序。
func lowerBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound 类似于 C++ 中的 upper_bound。
//用于二分查找 int 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int 切片必须升序。
func upperBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound64 类似于 C++ 中的 upper_bound。
//用于二分查找 int64 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int64 切片必须升序。
func upperBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

type Stack struct {
	s []int
}

func (st *Stack) top() int   { return st.s[len(st.s)-1] }
func (st *Stack) size() int  { return len(st.s) }
func (st *Stack) pop()       { st.s = st.s[:len(st.s)-1] }
func (st *Stack) push(x int) { st.s = append(st.s, x) }

type Queue struct {
	que chan int
}

func MakeQueue(size int) Queue {
	var q Queue
	q.que = make(chan int, size)
	return q
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1472/D

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		n := nextNum()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextNum()
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		score := 0
		for i := 0; i < n; i++ {
			if i&1 == 0 {
				if a[i]&1 == 0 {
					score += a[i]
				}
			} else {
				if a[i]&1 == 1 {
					score -= a[i]
				}
			}
		}
		switch {
		case score > 0:
			println("Alice")
		case score < 0:
			println("Bob")
		default:
			println("Tie")
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		size := ReadInt()
		weights := ReadIntSliceln(size)
		fmt.Println(process(weights))
	}
}

func process(w []int) (ans string) {
	sort.Sort(sort.Reverse(sort.IntSlice(w)))
	alice, bob := 0, 0
	isAlice := true
	for _, v := range w {
		if isAlice {
			if v&1 == 0 {
				alice = alice + v
			}
		} else {
			if v&1 != 0 {
				bob = bob + v
			}
		}
		//fmt.Println("Alice:", isAlice, alice, bob)
		isAlice = !isAlice
	}
	if alice == bob {
		return "Tie"
	} else if alice > bob {
		return "Alice"
	}
	return "Bob"
}

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

// ReadInt Read a single integer followed by a space
func ReadInt() (v int) {
	fmt.Fscan(reader, &v)
	return v
}

// ReadIntSliceln reads a line of integers into a slice.
func ReadIntSliceln(size int) []int {
	a := make([]int, size)
	for i := range a {
		fmt.Fscan(reader, &a[i])
	}
	//fmt.Scanf("\n")
	return a
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		println(solve(ReadInts(n)))
	}
}

func solve(a []int) string {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	score := 0
	for i, v := range a {
		if i%2 == 0 && v%2 == 0 {
			score += v
		}
		if i%2 == 1 && v%2 == 1 {
			score -= v
		}
	}

	if score == 0 {
		return "Tie"
	}
	if score > 0 {
		return "Alice"
	}
	return "Bob"
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		sc.NextInt()
		a := sc.NextIntArray()
		fmt.Println(solve(a))
	}

}

func solve(a []int) string {
	sort.Ints(a)
	reverse(a, 0, len(a))
	score := 0
	for i := 0; i < len(a); i++ {
		if a[i]%2 == 0 && i%2 == 0 {
			score += a[i]
		} else if a[i]%2 == 1 && i%2 == 1 {
			score -= a[i]
		}
	}
	if score > 0 {
		return "Alice"
	} else if score < 0 {
		return "Bob"
	} else {
		return "Tie"
	}

}

func reverse(a []int, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var q, op, fa, v, wt int
	Fscan(in, &q)
	const mx = 19
	pa := make([][mx]int, q+1)
	dep := make([]int, q+1)
	left := make([]int, q+1)
	price := make([]int, q+1)
	Fscan(in, &left[0], &price[0])
	for i := 0; i < mx; i++ {
		pa[0][i] = -1
	}
	uptoDep := func(v, d int) int {
		for i := 0; i < mx; i++ {
			if (dep[v]-d)>>i&1 > 0 {
				v = pa[v][i]
				//if v == -1 { panic(-9) }
			}
		}
		return v
	}

	for w := 1; w <= q; w++ {
		Fscan(in, &op)
		if op == 1 {
			Fscan(in, &fa, &left[w], &price[w])
			pa[w][0] = fa
			v := w
			for i := 0; i+1 < mx; i++ {
				if p := pa[v][i]; p != -1 {
					pa[v][i+1] = pa[p][i]
				} else {
					pa[v][i+1] = -1
				}
			}
			dep[w] = dep[fa] + 1
		} else {
			Fscan(in, &v, &wt)
			actualWt := 0
			ans := int64(0)
			tar := v
			for i := mx - 1; i >= 0; i-- {
				if p := pa[tar][i]; p != -1 && left[p] > 0 {
					tar = p
				}
			}
			for d := dep[tar]; d <= dep[v]; d++ {
				w := uptoDep(v, d)
				if left[w] > wt {
					ans += int64(wt) * int64(price[w])
					actualWt += wt
					left[w] -= wt
					break
				}
				ans += int64(left[w]) * int64(price[w])
				actualWt += left[w]
				wt -= left[w]
				left[w] = 0
			}
			Fprintln(out, actualWt, ans)
		}
	}
}

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

package main
import ("bufio";."fmt";."os")

// github.com/EndlessCheng/codeforces-go
func main(){
	in:=bufio.NewReader(Stdin)
	var q,op,v,wt int
	Fscan(in,&q)
	F:=make([][19]int,q+1)
	for i:=0;i<19;i++{F[0][i]=-1}
	D:=make([]int,q+1)
	a:=make([]int,q+1)
	c:=make([]int,q+1)
	Fscan(in,&a[0],&c[0])
	for w:=1;w<=q;w++{
		if Fscan(in,&op);op==1{
			Fscan(in,&F[w][0],&a[w],&c[w])
			for i:=0;i+1<19;i++{if f:=F[w][i];f>=0{F[w][i+1]=F[f][i]}else{F[w][i+1]=-1}}
			D[w]=D[F[w][0]]+1
			continue
		}
		Fscan(in,&v,&wt)
		s,f,t:=int64(0),v,wt
		for i:=18;i>=0;i--{if p:=F[f][i];p>=0&&a[p]>0{f=p}}
		for d:=D[f];d<=D[v];d++{
			w:=v
			for i:=0;i<19;i++{if(D[w]-d)>>i&1>0{w=F[w][i]}}
			if t<a[w]{
				s+=int64(t)*int64(c[w])
				t=0
				a[w]-=wt
				break
			}
			s+=int64(a[w])*int64(c[w])
			t-=a[w]
			a[w]=0
		}
		Println(wt-t,s)
	}
}


package main

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

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

var dp [][]int
var a, b, c []int
var n int

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	n = NextInt()
	a, b, c = make([]int, n), make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = NextInt()
	}
	for i := 0; i < n; i++ {
		b[i] = NextInt()
	}
	for i := 0; i < n; i++ {
		c[i] = NextInt()
	}

	dp = make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			dp[i][j] = -1
		}
	}

	r := Dp(0, 0)

	fmt.Fprintln(out, r)
}

func Dp(pos, prev int) int {
	if pos == n - 1 {
		if prev == 0 {
			return a[pos]
		}
		return b[pos]
	}
	if dp[pos][prev] != -1 {
		return dp[pos][prev]
	}

	var ret int = 0

	if prev == 0 {
		ret = Max(ret, Dp(pos + 1, 0) + b[pos])
		ret = Max(ret, Dp(pos + 1, 1) + a[pos])
	}else {
		ret = Max(ret, Dp(pos + 1, 0) + c[pos])
		ret = Max(ret, Dp(pos + 1, 1) + b[pos])
	}

	dp[pos][prev] = ret
	return ret
}

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

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF358D(_r io.Reader, out io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([][3]int, n)
	for j := 0; j < 3; j++ {
		for i := range a {
			Fscan(in, &a[i][j])
		}
	}
	dp := make([][2]int, n+1)
	dp[0][0] = -1e9
	for i, v := range a {
		dp[i+1][0] = max(dp[i][0]+v[1], dp[i][1]+v[0])
		dp[i+1][1] = max(dp[i][0]+v[2], dp[i][1]+v[1])
	}
	Fprint(out, dp[n][0])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF358D(_r io.Reader, out io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([][3]int, n)
	for j := 0; j < 3; j++ {
		for i := range a {
			Fscan(in, &a[i][j])
		}
	}
	dp := make([][2]int, n+1)
	for i, v := range a {
		dp[i+1][0] = max(dp[i][1]+v[0], dp[i][0]+v[1])
		dp[i+1][1] = max(dp[i][1]+v[1], dp[i][0]+v[2])
	}
	Fprint(out, dp[n][0])
}

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


package main

import (
	"fmt"
)

func main() {

	t := 0
	fmt.Scanln(&t)

	for t > 0 {

		//var x, y = 0, 0
		step := 0
		//dir := 0
		var tx, ty int
		//pStep := 5

		fmt.Scanln(&tx, &ty)

		if tx == ty {
			step = 2 * tx
		} else {
			if tx > ty {
				step = 2*tx - 1
			} else {
				step = 2*ty - 1
			}
		}

		/*
			pri := priority(tx, ty)

			//dir := nStep(x, y, tx, ty, pStep)
			//fmt.Println(dir)

			for !(x == tx && y == ty) {

				switch pri {
				case 1:
					dir = nStep1(x, y, tx, ty, pStep)
				case 2:
					dir = nStep2(x, y, tx, ty, pStep)
				case 3:
					dir = nStep3(x, y, tx, ty, pStep)
				case 4:
					dir = nStep4(x, y, tx, ty, pStep)
				}

				//fmt.Printf("%d %d %d\n", x, y, dir)

				switch dir {
				case 4:
					x, y = up(x, y)
					pStep = 4
				case 1:
					x, y = right(x, y)
					pStep = 1
				case 2:
					x, y = down(x, y)
					pStep = 2
				case 3:
					x, y = left(x, y)
					pStep = 3
				case 0:
					pStep = 0
				}

				step++
			}
		*/

		fmt.Printf("%d\n", step)
		t--
	}

}

func priority(x int, y int) int {
	if abs(x) >= abs(y) {
		if x >= 0 {
			return 1
		} else {
			return 3
		}
	} else {
		if y >= 0 {
			return 4
		} else {
			return 2
		}
	}
}

func nStep1(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep2(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep3(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep4(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	return dir
}

func abs(n int) int {
	if n >= 0 {
		return n
	} else {
		return -n
	}
}

func up(x int, y int) (int, int) {
	y = y + 1
	return x, y
}

func down(x int, y int) (int, int) {
	y = y - 1
	return x, y
}

func left(x int, y int) (int, int) {
	x = x - 1
	return x, y
}

func right(x int, y int) (int, int) {
	x = x + 1
	return x, y
}

/*
URL:
https://codeforces.com/contest/1452/problem/A
*/

package main

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

var (
	t    int
	x, y int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		x, y = readi2()

		solve()
	}
}

func solve() {
	maxi := max(x, y)
	mini := min(x, y)

	a := maxi - mini

	// ans := 2*mini + (2*a - 1)
	ans := 2 * mini
	if a > 0 {
		ans += 2*a - 1
	}

	printf("%d\n", ans)
}

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

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

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

/********** 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"
	"io"
	"os"
)

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

	solve := func(Case int) {
		var x,y int
		Fscan(in, &x, &y)
		if y > x {
			y, x = x, y
		}
		if x-y<=1 {
			Fprintln(out, x+y)
		} else {
			Fprintln(out, x+y+(x-y-1))
		}

	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

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

package main

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

var t int

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

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

		if x > y {
			a := x
			x = y
			y = a
		}

		ans := x * 2
		if (y - x) > 1 {
			ans += ((y - x) * 2) - 1
		}

		if (y - x) == 1 {
			ans++
		}

		fmt.Println(ans)
	}
}

package main
import "fmt"
func max(a, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Scan(&x, &y)
		res := 2 * max(x, y)
		if x != y {
			res--
		}
		fmt.Println(res)
	}
}

package main

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

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

	var t, x, y int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &x, &y)
		if x > y {
			x, y = y, x
		}
		if y-x <= 1 {
			fmt.Println(x + y)
		} else {
			fmt.Println(x + y + (y - x - 1))
		}
	}
}

package main
import "fmt"
func max(a, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Scan(&x, &y)
		res := max(x, y)
		if x != y {
			res--
		}
		fmt.Println(res)
	}
}


package main

import (
	"fmt"
)

func main(){
	var alph = "qwertyuiopasdfghjklzxcvbnm"
	var s string
	fmt.Scan(&s)
	min := len(s)
	for i := range alph {
		max := 1
		counter := 1
		for j := range s {
			if alph[i] != s[j] {
				counter ++
				if counter > max {
					max = counter
				}
			} else {
				counter = 1
			}
		}
		if max < min {
			min = max
		}
	}
	fmt.Print(min)
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i := 0; ; i++ {
		ch := readChar()
		if len(ch) < 1 || ch[0] < 97 || ch[0] > 122 {
			break
		}
		c := rune(ch[0])

		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := math.MaxInt32
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanRunes)
}

func readChar() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	inp := readString()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i, c := range inp {
		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := 100001
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	inp := readString()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i, c := range inp {
		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := math.MaxInt32
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}


package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int = 1e9 + 7

	dp := make([][]int, 10)
	for i := range dp {
		dp[i] = make([]int, 2e5+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	var f func(int, int) int
	f = func(d, k int) (res int) {
		if k == 0 {
			return 1
		}
		dv := &dp[d][k]
		if *dv != -1 {
			return *dv
		}
		defer func() { *dv = res }()
		if d == 9 {
			return (f(1, k-1) + f(0, k-1)) % mod
		}
		return f(d+1, k-1)
	}

	solve := func(Case int) {
		var n, k, ans int
		Fscan(in, &n, &k)

		for x := n; x > 0; x /= 10 {
			d := x % 10
			res := f(d, k)
			ans = (ans + res) % mod
		}
		Fprintln(out, ans)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int64(1E9+7)
	table := [200010][10]int64 {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=int64(0)
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200100
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] = (nextDigits[0] + digits[9]) % modulo
		nextDigits[1] = (nextDigits[1] + digits[9]) % modulo
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = (nd + nextDigits[j]) % modulo
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)

		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

		for n > 0 {
			x := modi(n, 10)
			digits[x]++
			n /= 10
		}

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			// result += mod(int64(digitCount)*dpv, modulo)
			for i := 0; i < digitCount; i++ {
				result = (dpv + result) % modulo
			}
		}
		Fprintln(out, result)
	}
}

func modi(a, b int) int {
	return (a%b + b) % b
}

package main

import (
	"bufio"
	"fmt"
	"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 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)

	const MAX_M int = 200007
	var dp [MAX_M]int

	for i := 0; i <= 8; i++ {
		dp[i] = 2
	}

	dp[9] = 3

	var MOD_FACTOR = 1000000000 + 7

	for i := 10; i < MAX_M; i++ {
		dp[i] = (dp[i-9] + dp[i-10]) % MOD_FACTOR
	}

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

		var n string
		var m int
		scanf("%s %d\n", &n, &m);

		var res int = 0
		for _, r := range n {
			var d int = int(r - '0')
			if (m + d < 10) {
				res = (res % MOD_FACTOR + 1) % MOD_FACTOR
			} else {
				res = ((res % MOD_FACTOR) + (dp[m + d - 10] % MOD_FACTOR)) % MOD_FACTOR
			}
		}

		printf("%d\n", res)

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var mod = 1000000007
type M struct{
	m [15][15]int
	r int
	c int
}
func mul(x M, y M) M{
	var ret M
	for i:=1;i<=x.r;i++{
		for j:=1;j<=y.c;j++{
			for k:=1;k<=x.c;k++ {
				ret.m[i][j] += x.m[i][k]*y.m[k][j]%mod
				ret.m[i][j]%=mod
			}
		}
	}
	ret.c = y.c
	ret.r = x.r
	return ret
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	f := [200050]int{}
	for i:=0;i<9;i++{
		f[i]=2
	}
	f[9]=3
	for i:=10;i<=200005;i++{
		f[i]=(f[i-9]+f[i-10])%mod
	}
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		ans := 0
		for n>0{
			now := n%10
			if m+now<10{
				ans++
				ans %=mod
			}else{
				ans += f[m+now-10]
				ans %= mod
			}
			n/=10
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var mod = 1000000007
type M struct{
	m [15][15]int
	r int
	c int
}
func mul(x M, y M) M{
	var ret M
	for i:=1;i<=x.r;i++{
		for j:=1;j<=y.c;j++{
			for k:=1;k<=x.c;k++ {
				ret.m[i][j] += x.m[i][k]*y.m[k][j]%mod
				ret.m[i][j]%=mod
			}
		}
	}
	return ret
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		f:=[10]int{}
		temp := n
		for temp>0{
			f[temp%10]++
			temp = temp/10
		}
		var a M
		for i:=1;i<=10;i++{
			a.m[i][1]=f[i-1]
		}
		a.c=1
		a.r=10
		var b M
		for i:=1;i<=10;i++{
			if i==1{
				b.m[i][10]=1
				continue
			}
			if i==2{
				b.m[i][1]=1
				b.m[i][10]=1
				continue
			}
			b.m[i][i-1]=1
		}
		b.r=10
		b.c=10
		cnt := m
		for cnt>0{
			if cnt%2==1{
				a = mul(b,a)
			}
			b = mul(b,b)
			cnt = cnt>>1
		}
		ans := 0
		for i:=1;i<=10;i++{
			ans = (ans +a.m[i][1])%mod
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int(1E9+7)
	table := [200010][10]int {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=0
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int(1E9+7)
	table := [100010][10]int {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	fmt.Println(table[100:200])

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=0
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200100
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] += digits[9]
		nextDigits[1] += digits[9]
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = mod(nd+nextDigits[j], modulo)
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		s := strconv.Itoa(n)
		l := len(s)
		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for i := 0; i < l; i++ {
			digits[s[i]-48] += 1
		}

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			for i := 0; i < digitCount; i++ {
				result = mod(dpv+result, modulo)
			}
		}
		Fprintln(out, result)
	}
}

func mod(a, b int64) int64 {
	return (a%b + b) % b
}

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200001
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] += digits[9]
		nextDigits[1] += digits[9]
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = mod(nd+nextDigits[j], modulo)
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		s := strconv.Itoa(n)
		l := len(s)
		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for i := 0; i < l; i++ {
			digits[s[i]-48] += 1
		}
		Printf("%+v\n", digits)

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			for i := 0; i < digitCount; i++ {
				result = mod(dpv+result, modulo)
				Println(result)
			}
		}
		Fprintln(out, result)
	}
}

func mod(a, b int64) int64 {
	return (a%b + b) % b
}

package main

import (
	"bufio"
	"fmt"
	"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 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)

	const MAX_M int = 200007
	var dp [MAX_M]int

	for i := 0; i <= 8; i++ {
		dp[i] = 2
	}

	dp[9] = 3

	for i := 10; i < MAX_M; i++ {
		dp[i] = dp[i-9] + dp[i-10]
	}

	var MOD_FACTOR = 1000000000 + 7

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

		var n string
		var m int
		scanf("%s %d\n", &n, &m);

		var res int = 0
		for _, r := range n {
			var d int = int(r - '0')
			if (m + d < 10) {
				res = (res % MOD_FACTOR + 1) % MOD_FACTOR
			} else {
				res = ((res % MOD_FACTOR) + (dp[m + d - 10] % MOD_FACTOR)) % MOD_FACTOR
			}
		}

		printf("%d\n", res)

	}

}