package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// This example demonstrates a Priority queue built using the heap interface.
// A PqInt implements heap.Interface and holds int.
type PqInt []int

func (pq PqInt) Len() int { return len(pq) }

// func (pq PqInt) Less(i, j int) bool { return pq[i] < pq[j] }

func (pq PqInt) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PqInt) Push(x any) {
	*pq = append(*pq, x.(int))
}

func (pq *PqInt) Pop() any {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type LessFunction func(i, j any) bool

var lesser LessFunction

func GetPqInt(l LessFunction) PqInt {
	lesser = l
	return []int{}
}

func (pq PqInt) Less(i, j int) bool {
	return lesser(pq[i], pq[j])
}

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

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

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

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

func cal(x int) int {
	res := 0
	for x > 0 {
		res++
		x = x / 10
	}
	return res
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		x := readArrInt(in)
		y := readArrInt(in)
		a := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		b := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		res := 0
		for i := 0; i < n; i++ {
			heap.Push(&a, x[i])
			heap.Push(&b, y[i])
		}
		for len(a) > 0 {
			u := heap.Pop(&a).(int)
			v := heap.Pop(&b).(int)
			if u == v {
				continue
			}
			if u > v {
				u = cal(u)
			} else {
				v = cal(v)
			}
			res++
			heap.Push(&a, u)
			heap.Push(&b, v)
		}
		fmt.Println(res)
	}
}

package main

import (
	"bufio"
	"container/heap"
	"os"
	"strconv"
	"strings"
)

// This example demonstrates a Priority queue built using the heap interface.
// A PqInt implements heap.Interface and holds int.
type PqInt []int

func (pq PqInt) Len() int { return len(pq) }

// func (pq PqInt) Less(i, j int) bool { return pq[i] < pq[j] }

func (pq PqInt) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PqInt) Push(x any) {
	*pq = append(*pq, x.(int))
}

func (pq *PqInt) Pop() any {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type LessFunction func(i, j any) bool

var lesser LessFunction

func GetPqInt(l LessFunction) PqInt {
	lesser = l
	return []int{}
}

func (pq PqInt) Less(i, j int) bool {
	return lesser(pq[i], pq[j])
}

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 writeInt(out *bufio.Writer, n int) {
	out.WriteString(strconv.Itoa(n) + "\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 cal(x int) int {
	res := 0
	for x > 0 {
		res++
		x = x / 10
	}
	return res
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		x := readArrInt(in)
		y := readArrInt(in)
		a := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		b := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		res := 0
		for i := 0; i < n; i++ {
			heap.Push(&a, x[i])
			heap.Push(&b, y[i])
		}
		for len(a) > 0 {
			u := heap.Pop(&a).(int)
			v := heap.Pop(&b).(int)
			if u == v {
				continue
			}
			if u > v {
				u = cal(u)
			} else {
				v = cal(v)
			}
			res++
			heap.Push(&a, u)
			heap.Push(&b, v)
		}
		writeInt(out, res)
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func numDigit(n int) int {
	cnt := 0
	for n > 0 {
		cnt++
		n /= 10
	}
	return cnt
}
func solve() {
	var n, x int
	scan(&n)
	a := make(map[int]int)
	for i := 0; i < n; i++ {
		scan(&x)
		a[x]++
	}
	for i := 0; i < n; i++ {
		scan(&x)
		a[x]--
	}
	r := 0
	flag := true
	firstLoop := true
	for flag == true && len(a) > 0 {
		flag = false
		for k, e := range a {
			if firstLoop {
				if e != 0 && k > 9 {
					// printf("1:%d %d\n", k, e)
					a[numDigit(k)] += e
					a[k] = 0
					flag = true // ok to continue loop
					r += int(math.Abs(float64(e)))
				}
			}
		}
		firstLoop = false
	}
	add := 0
	for k, e := range a {
		if e != 0 && k != 1 {
			// printf("need left:%d %d\n", k, e)
			add += int(math.Abs(float64(e)))
		}
	}
	printf("%d\n", r+add)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
)

var a [200005]int
var b [200005]int

type IntHeap []int

var heapA = &IntHeap{}
var heapB = &IntHeap{}

func (h IntHeap) Len() int {
	return len(h)
}

func (h IntHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h IntHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for cs := 0; cs < t; cs++ {
		heapA = &IntHeap{}
		heapB = &IntHeap{}
		var n int
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			heap.Push(heapA, a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
			heap.Push(heapB, b[i])
		}
		ans := 0
		for heapA.Len() > 0 {
			topA := heap.Pop(heapA).(int)
			topB := heap.Pop(heapB).(int)
			if topA == topB {
				continue
			}
			if topA > topB {
				topA = int(math.Log10(float64(topA))) + 1
			} else {
				topB = int(math.Log10(float64(topB))) + 1
			}
			heap.Push(heapA, topA)
			heap.Push(heapB, topB)
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func solve() {
	n := ReadInt()
	a := ReadInts(n)
	b := ReadInts(n)

	a1, c1 := f(a)
	a2, c2 := f(b)

	eq := func(a []int, pos int, val int) int {
		x := pos
		for ; pos < len(a) && a[pos] == val; pos++ {
		}
		return pos - x
	}

	ans := 0
	for p1, p2 := 0, 0; p1 < len(a1) || p2 < len(a2); {
		mx := 0
		if p1 < len(a1) {
			mx = a1[p1]
		}
		if p2 < len(a2) && (p1 == len(a1) || a2[p2] > a1[p1]) {
			mx = a2[p2]
		}
		l1 := eq(a1, p1, mx)
		l2 := eq(a2, p2, mx)
		p1 += l1
		p2 += l2
		mn := Min(l1, l2)
		l1 -= mn
		l2 -= mn
		c1[ff(mx)] += l1
		c2[ff(mx)] += l2
		ans += l1 + l2
	}

	for i := 9; i >= 1; i-- {
		cnt := Min(c1[i], c2[i])
		c1[i] -= cnt
		c2[i] -= cnt
		c1[1] += c1[i]
		c2[1] += c2[i]
		ans += c1[i] + c2[i]
	}
	Println(ans)
}

func f(a []int) ([]int, []int) {
	c := make([]int, 10)
	for _, i := range a {
		if i < 10 {
			c[i]++
		}
	}

	a = RemoveIf(a, func(x int) bool { return x < 10 })
	sort.Ints(a)
	Reverse(a)
	return a, c
}

func ff(x int) int {
	ans := 0
	for ; x > 0; x /= 10 {
		ans += 1
	}
	return ans
}

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

	t := 1
	t = ReadInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

func Print(a ...any) {
	fmt.Print(a...)
}

func Println(a ...any) {
	fmt.Println(a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

package main

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

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

func solve() {
	n := ReadInt()
	a := ReadInts(n)
	b := ReadInts(n)

	a1, c1 := f(a)
	a2, c2 := f(b)

	eq := func(a []int, pos int, val int) int {
		x := pos
		for ; pos < len(a) && a[pos] == val; pos++ {
		}
		return pos - x
	}

	ans := 0
	for p1, p2 := 0, 0; p1 < len(a1) || p2 < len(a2); {
		mx := 0
		if p1 < len(a1) {
			mx = a1[p1]
		}
		if p2 < len(a2) && (p1 == len(a1) || a2[p2] > a1[p1]) {
			mx = a2[p2]
		}
		l1 := eq(a1, p1, mx)
		l2 := eq(a2, p2, mx)
		p1 += l1
		p2 += l2
		mn := Min(l1, l2)
		l1 -= mn
		l2 -= mn
		c1[ff(mx)] += l1
		c2[ff(mx)] += l2
		ans += l1 + l2
	}

	for i := 9; i >= 1; i-- {
		cnt := Min(c1[i], c2[i])
		c1[i] -= cnt
		c2[i] -= cnt
		c1[1] += c1[i]
		c2[1] += c2[i]
		ans += c1[i] + c2[i]
	}
	Println(ans)
}

func f(a []int) ([]int, []int) {
	c := make([]int, 10)
	for _, i := range a {
		if i < 10 {
			c[i]++
		}
	}

	a = RemoveIf(a, func(x int) bool { return x < 10 })
	sort.Ints(a)
	Reverse(a)
	return a, c
}

func ff(x int) int {
	ans := 0
	for ; x > 0; x /= 10 {
		ans += 1
	}
	return ans
}

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

	t := 1
	t = ReadInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

func Print(a ...any) {
	fmt.Fprint(out, a...)
}

func Println(a ...any) {
	fmt.Fprintln(out, a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

package main

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

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

func solve() {
	n := ReadInt()
	a := ReadInts(n)
	b := ReadInts(n)

	a1, c1 := f(a)
	a2, c2 := f(b)

	eq := func(a []int, pos int, val int) int {
		x := pos
		for ; pos < len(a) && a[pos] == val; pos++ {
		}
		return pos - x
	}

	ans := 0
	for p1, p2 := 0, 0; p1 < len(a1) || p2 < len(a2); {
		mx := 0
		if p1 < len(a1) {
			mx = a1[p1]
		}
		if p2 < len(a2) && (p1 == len(a1) || a2[p2] > a1[p1]) {
			mx = a2[p2]
		}
		l1 := eq(a1, p1, mx)
		l2 := eq(a2, p2, mx)
		p1 += l1
		p2 += l2
		mn := Min(l1, l2)
		l1 -= mn
		l2 -= mn
		c1[ff(mx)] += l1
		c2[ff(mx)] += l2
		ans += l1 + l2
	}

	for i := 9; i >= 1; i-- {
		cnt := Min(c1[i], c2[i])
		c1[i] -= cnt
		c2[i] -= cnt
		c1[1] += c1[i]
		c2[1] += c2[i]
		ans += c1[i] + c2[i]
	}
	fmt.Println(ans)
}

func f(a []int) ([]int, []int) {
	c := make([]int, 10)
	for _, i := range a {
		if i < 10 {
			c[i]++
		}
	}

	a = RemoveIf(a, func(x int) bool { return x < 10 })
	sort.Ints(a)
	Reverse(a)
	return a, c
}

func ff(x int) int {
	ans := 0
	for ; x > 0; x /= 10 {
		ans += 1
	}
	return ans
}

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

	t := 1
	t = ReadInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

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

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

		aa := make(IntHeap, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		bb := make(IntHeap, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &bb[i])
		}
		heap.Init(&aa)
		heap.Init(&bb)
		var tot int
		for aa.Len() > 0 {
			a, b := heap.Pop(&aa).(int), heap.Pop(&bb).(int)
			if a == b {
				continue
			} else if a > b {
				a = len(fmt.Sprintf("%d", a))
			} else {
				b = len(fmt.Sprintf("%d", b))
			}
			heap.Push(&aa, a)
			heap.Push(&bb, b)
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var in *bufio.Reader

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

func FF(a int) (int, int) {
    if a < 10 {
        return a, 0
    }
    result := 0
    for a != 0 {
        result++
        a = a / 10
    }
    return result, 1
}

func main() {
    in = bufio.NewReader(os.Stdin)
    var t int
    //fmt.Scan(&t)
    fmt.Fscan(in, &t)
    for t != 0  {
        t--
        var n int
        //fmt.Scan(&n)
        fmt.Fscan(in, &n)
        a := make([]int, n)
        b := make([]int, n)
        for i := 0; i < n; i++ {
            //fmt.Scan(&a[i])
            fmt.Fscan(in, &a[i])
        }
        for i := 0; i < n; i++ {
            //fmt.Scan(&b[i])
            fmt.Fscan(in, &b[i])
        }
        sort.Ints(a)
        sort.Ints(b)
        var ca [10]int
        var cb [10]int
        result := 0
        addTo := func(p *int, c *[10]int, mass *[]int) {
            v, cnt := FF((*mass)[*p])
            (*c)[v]++
            result += cnt
            (*p)++
        }
        for pa, pb := 0, 0; pa < n || pb < n; {
            if pa >= n {
                addTo(&pb, &cb, &b)
                continue
            }
            if pb >= n {
                addTo(&pa, &ca, &a)
                continue
            }
            if a[pa] < b[pb] {
                addTo(&pa, &ca, &a)
            } else if a[pa] > b[pb] {
                addTo(&pb, &cb, &b)
            } else if a[pa] == b[pb] {
                pa++
                pb++
            }
        }
        for i := 2; i < 10; i++ {
            mn := Min(ca[i], cb[i])
            result = result + (ca[i] - mn) + (cb[i] - mn)
        }
        fmt.Println(result)
    }
}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }

func BAAL() {
	in := os.Stdin
	out := os.Stdout
	iost = NewIost(in, out)
}

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	BAAL()
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			for val > 0 {
				val--
				if key >= 10 {
					cnt := 0
					dum := key
					for dum > 0 {
						dum /= 10
						cnt++
					}
					A[cnt]++
					o++
				} else {
					A[key]++
				}
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		iost.Println(o)
	}
}

package main

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

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

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

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

func (in *R) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}
func NewR(r *bufio.Reader) *R {
	return &R{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}
func (in *R) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func main() {
	CF1728C()
}
func CF1728C() {
	r := NewR(bufio.NewReader(os.Stdin))
	f := func(x int) int {
		if x > 99999999 {
			return 9
		} else if x > 9999999 {
			return 8
		} else if x > 999999 {
			return 7
		} else if x > 99999 {
			return 6
		} else if x > 9999 {
			return 5
		} else if x > 999 {
			return 4
		} else if x > 99 {
			return 3
		} else if x > 9 {
			return 2
		} else {
			return x
		}
	}
	t := r.NextInt()
	for t > 0 {
		t--
		n := r.NextInt()
		am := make(map[int]int, n)
		bm := make(map[int]int, n)
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			am[tmp]++
		}
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			if v, ok := am[tmp]; ok {
				if v > 0 {
					am[tmp]--
					if am[tmp] == 0 {
						delete(am, tmp)
					}
					continue
				}
			}
			bm[tmp]++
		}
		res := 0
		for k, v := range am {
			if k > 9 {
				delete(am, k)
				res += v
				k = f(k)
				am[k] += v
			}
			if vb, ok := bm[k]; ok {
				if v < vb {
					delete(am, k)
					bm[k] -= v
				} else if v > vb {
					delete(bm, k)
					am[k] -= vb
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range bm {
			if k > 9 {
				delete(bm, k)
				res += v
				k = f(k)
				bm[k] += v
			}
			if va, ok := am[k]; ok {
				if v < va {
					delete(bm, k)
					am[k] -= v
				} else if v > va {
					delete(am, k)
					bm[k] -= va
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range am {
			if k > 1 {
				res += v
			}
		}
		for k, v := range bm {
			if k > 1 {
				res += v
			}
		}
		fmt.Println(res)
	}
}
func CF1728B() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			if n&1 == 0 {
				if j < n-1 {
					if j&1 == 0 {
						fmt.Print(j - 1)
					} else {
						fmt.Print(j + 1)
					}
				} else {
					fmt.Print(j)
				}
			} else {
				if j == 1 || j >= n-1 {
					fmt.Print(j)
				} else {
					if j&1 == 0 {
						fmt.Print(j + 1)
					} else {
						fmt.Print(j - 1)
					}
				}
			}
			if j == n {
				fmt.Println("")
			} else {
				fmt.Print(" ")
			}
		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }

func BAAL() {
	in := os.Stdin
	out := os.Stdout
	iost = NewIost(in, out)
}

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	BAAL()
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			for val > 0 {
				val--
				if key >= 10 {
					cnt := 0
					dum := key
					for dum > 0 {
						dum /= 10
						cnt++
					}
					A[cnt]++
					o++
				} else {
					A[key] = val
				}
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		iost.Println(o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

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

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

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

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func (in *CF1728B) Run() {
	t := in.NextInt()
	for t > 0 {
		t--
		n := in.NextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := in.NextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := in.NextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }

func Baal() {
}

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	in := os.Stdin
	out := os.Stdout
	// if isLocal() {
	// 	in, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	// }
	iost = NewIost(in, out)
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		// fmt.Println(o)
		iost.Println(o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }

func Baal() {
	in := os.Stdin
	out := os.Stdout
	if isLocal() {
		in, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(in, out)
	defer func() {
		iost.Writer.Flush()
	}()
}

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	Baal()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		// fmt.Println(o)
		iost.Println(o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }

func Baal() {
	in := os.Stdin
	out := os.Stdout
	if isLocal() {
		in, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(in, out)
	defer func() {
		iost.Writer.Flush()
	}()
}

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	Baal()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		n := iost.GetNextInt()
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			dum := iost.GetNextInt()
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
		// iost.Println(o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			mp[dum]++
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		scanf("\n")
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		printf("%d\n", o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			mp[dum]++
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		// if t > 0 {
		// 	scanf("\n")
		// }
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		printf("%d\n", o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			mp[dum]++
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if i < n-1 {
				scanf(" ")
			}
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		if t > 0 {
			scanf("\n")
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		printf("%d\n", o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			mp[dum]++
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		if t > 0 {
			scanf("\n")
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		printf("%d\n", o)
	}
}

package main

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

const N = 3e5
const inf = 1e9

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

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

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	defer out.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			mp[dum]++
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			scanf("%d", &dum)
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		scanf("\n")
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		printf("%d\n", o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			if i < n-1 {
				fmt.Scanf(" ")
			}
			mp[dum]++
		}
		fmt.Scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			if i < n-1 {
				fmt.Scanf(" ")
			}
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		fmt.Scanf("\n")
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			mp[dum]++
		}
		fmt.Scanf("\n")
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		fmt.Scanf("\n")
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d", &dum)
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scan("%d\n", &n)
		var b []int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d\n", &dum)
			mp[dum]++
		}
		for i := 0; i < n; i++ {
			var dum int
			fmt.Scanf("%d\n", &dum)
			if mp[dum] > 0 {
				mp[dum]--
			} else {
				b = append(b, dum)
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < len(b); i++ {
			if b[i] >= 10 {
				cnt := 0
				for b[i] > 0 {
					b[i] /= 10
					cnt++
				}
				B[cnt]++
				o++
			} else {
				B[b[i]]++
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d", &n)
		var a, b [N]int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			mp[a[i]]++
		}
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &b[i])
			if mp[b[i]] > 0 {
				mp[b[i]]--
				b[i] = 0
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < n; i++ {
			if b[i] > 0 {
				if b[i] >= 10 {
					cnt := 0
					for b[i] > 0 {
						b[i] /= 10
						cnt++
					}
					B[cnt]++
					o++
				} else {
					B[b[i]]++
				}
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func swap(a, b *int) {
	x := *a
	*a = *b
	*b = x
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d", &n)
		var a, b [N]int
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			mp[a[i]]++
		}
		for i := 0; i < n; i++ {
			fmt.Scan(&b[i])
			if mp[b[i]] > 0 {
				mp[b[i]]--
				b[i] = 0
			}
		}
		var A, B [10]int
		o := 0
		for key, val := range mp {
			if key >= 10 {
				cnt := 0
				for key > 0 {
					key /= 10
					cnt++
				}
				A[cnt]++
				o++
			} else {
				A[key] = val
			}
		}
		for i := 0; i < n; i++ {
			if b[i] > 0 {
				if b[i] >= 10 {
					cnt := 0
					for b[i] > 0 {
						b[i] /= 10
						cnt++
					}
					B[cnt]++
					o++
				} else {
					B[b[i]]++
				}
			}
		}
		for i := 2; i < 10; i++ {
			if A[i] < B[i] {
				swap(&A[i], &B[i])
			}
			o += A[i] - B[i]
		}
		fmt.Println(o)
	}
}

package main

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

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

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

		aa := []int{}
		cc := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				cc[x]++
			} else {
				aa = append(aa, x)
			}
		}

		bb := []int{}
		dd := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				if cc[x] > 0 {
					cc[x]--
				} else {
					dd[x]++
				}
			} else {
				bb = append(bb, x)
			}
		}
		sort.Ints(aa)
		sort.Ints(bb)

		var tot int64
		p1, p2 := len(aa)-1, len(bb)-1
		for p1 >= 0 && p2 >= 0 {
			if aa[p1] == bb[p2] {
				p1--
				p2--
			} else if p2 < 0 || aa[p1] > bb[p2] {
				d := len(fmt.Sprintf("%d", aa[p1]))
				if dd[d] > 0 {
					dd[d]--
				} else {
					cc[d]++
				}
				p1--
				tot++
			} else if p1 < 0 || aa[p1] < bb[p2] {
				d := len(fmt.Sprintf("%d", bb[p2]))
				if cc[d] > 0 {
					cc[d]--
				} else {
					dd[d]++
				}
				p2--
				tot++
			}
		}
		// fmt.Println(cc, dd)
		for i := p1; i >= 0; i-- {
			d := len(fmt.Sprintf("%d", aa[i]))
			if dd[d] > 0 {
				dd[d]--
			} else {
				cc[d]++
			}
			tot++
		}

		for i := p2; i >= 0; i-- {
			d := len(fmt.Sprintf("%d", bb[i]))
			if cc[d] > 0 {
				cc[d]--
			} else {
				dd[d]++
			}
			tot++
		}
		for i := 2; i <= 10; i++ {
			tot += int64(cc[i] + dd[i])
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

		aa := []int{}
		cc := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				cc[x]++
			} else {
				aa = append(aa, x)
			}
		}

		bb := []int{}
		dd := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				if cc[x] > 0 {
					cc[x]--
				} else {
					dd[x]++
				}
			} else {
				bb = append(bb, x)
			}
		}
		sort.Ints(aa)
		sort.Ints(bb)

		var tot int64
		p1, p2 := len(aa)-1, len(bb)-1
		for p1 >= 0 || p2 >= 0 {
			if p1 >= 0 && p2 >= 0 && aa[p1] == bb[p2] {
				p1--
				p2--
			} else if p1 >= 0 && (p2 < 0 || aa[p1] > bb[p2]) {
				d := len(fmt.Sprintf("%d", aa[p1]))
				if dd[d] > 0 {
					dd[d]--
				} else {
					cc[d]++
				}
				p1--
				tot++
			} else if p2 >= 0 && (p1 < 0 || aa[p1] < bb[p2]) {
				d := len(fmt.Sprintf("%d", bb[p2]))
				if cc[d] > 0 {
					cc[d]--
				} else {
					dd[d]++
				}
				p2--
				tot++
			}
		}
		// fmt.Println(cc, dd)
		for i := 2; i <= 10; i++ {
			tot += int64(cc[i] + dd[i])
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

		aa := []int{}
		cc := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				d := len(fmt.Sprintf("%d", x))
				cc[d]++
			} else {
				aa = append(aa, x)
			}
		}

		bb := []int{}
		dd := make([]int, 11)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x <= 10 {
				d := len(fmt.Sprintf("%d", x))
				if cc[d] > 0 {
					cc[d]--
				} else {
					dd[d]++
				}
			} else {
				bb = append(bb, x)
			}
		}
		sort.Ints(aa)
		sort.Ints(bb)

		var tot int64
		p1, p2 := len(aa)-1, len(bb)-1
		for p1 >= 0 || p2 >= 0 {
			if p1 >= 0 && p2 >= 0 && aa[p1] == bb[p2] {
				p1--
				p2--
			} else if p1 >= 0 && (p2 < 0 || aa[p1] > bb[p2]) {
				d := len(fmt.Sprintf("%d", aa[p1]))
				if dd[d] > 0 {
					dd[d]--
				} else {
					cc[d]++
				}
				p1--
				tot++
			} else if p2 >= 0 && (p1 < 0 || aa[p1] < bb[p2]) {
				d := len(fmt.Sprintf("%d", bb[p2]))
				if cc[d] > 0 {
					cc[d]--
				} else {
					dd[d]++
				}
				p2--
				tot++
			}
		}
		// fmt.Println(cc, dd)
		for i := 2; i <= 10; i++ {
			tot += int64(cc[i] + dd[i])
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

func (in *R) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}
func NewR(r *bufio.Reader) *R {
	return &R{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}
func (in *R) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func main() {
	CF1728C()
}
func CF1728C() {
	r := NewR(bufio.NewReader(os.Stdin))
	f := func(x int) int {
		if x > 99999999 {
			return 9
		} else if x > 9999999 {
			return 8
		} else if x > 999999 {
			return 7
		} else if x > 99999 {
			return 6
		} else if x > 9999 {
			return 5
		} else if x > 999 {
			return 4
		} else if x > 99 {
			return 3
		} else if x > 9 {
			return 2
		} else {
			return x
		}
	}
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		n := r.NextInt()
		am := make(map[int]int, n)
		bm := make(map[int]int, n)
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			am[tmp]++
		}
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			if v, ok := am[tmp]; ok {
				if v > 0 {
					am[tmp]--
					if am[tmp] == 0 {
						delete(am, tmp)
					}
					continue
				}
			}
			bm[tmp]++
		}
		res := 0
		for k, v := range am {
			if k > 9 {
				delete(am, k)
				res += v
				k = f(k)
				am[k] += v
			}
			if vb, ok := bm[k]; ok {
				if v < vb {
					delete(am, k)
					bm[k] -= v
				} else if v > vb {
					delete(bm, k)
					am[k] -= vb
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range bm {
			if k > 9 {
				delete(bm, k)
				res += v
				k = f(k)
				bm[k] += v
			}
			if va, ok := am[k]; ok {
				if v < va {
					delete(bm, k)
					am[k] -= v
				} else if v > va {
					delete(am, k)
					bm[k] -= va
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range am {
			if k > 1 {
				res += v
			}
		}
		for k, v := range bm {
			if k > 1 {
				res += v
			}
		}
		fmt.Println(res)
	}
}
func CF1728B() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			if n&1 == 0 {
				if j < n-1 {
					if j&1 == 0 {
						fmt.Print(j - 1)
					} else {
						fmt.Print(j + 1)
					}
				} else {
					fmt.Print(j)
				}
			} else {
				if j == 1 || j >= n-1 {
					fmt.Print(j)
				} else {
					if j&1 == 0 {
						fmt.Print(j + 1)
					} else {
						fmt.Print(j - 1)
					}
				}
			}
			if j == n {
				fmt.Println("")
			} else {
				fmt.Print(" ")
			}
		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

package main

import (
	"bufio"
	"container/heap"
	"os"
	"strconv"
	"strings"
)

// This example demonstrates a Priority queue built using the heap interface.
// A PqInt implements heap.Interface and holds int.
type PqInt []int

func (pq PqInt) Len() int { return len(pq) }

// func (pq PqInt) Less(i, j int) bool { return pq[i] < pq[j] }

func (pq PqInt) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PqInt) Push(x any) {
	*pq = append(*pq, x.(int))
}

func (pq *PqInt) Pop() any {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type LessFunction func(i, j any) bool

var lesser LessFunction

func GetPqInt(l LessFunction) PqInt {
	lesser = l
	return []int{}
}

func (pq PqInt) Less(i, j int) bool {
	return lesser(pq[i], pq[j])
}

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 writeInt(out *bufio.Writer, n int) {
	out.WriteString(strconv.Itoa(n) + "\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 cal(x int) int {
	res := 0
	for x > 0 {
		res++
		x = x / 10
	}
	return res
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		x := readArrInt(in)
		y := readArrInt(in)
		a := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		b := GetPqInt(func(i, j any) bool {
			return i.(int) > j.(int)
		})
		res := 0
		for i := 0; i < n; i++ {
			heap.Push(&a, x[i])
			heap.Push(&b, y[i])
		}
		for len(a) > 0 {
			u := heap.Pop(&a).(int)
			v := heap.Pop(&b).(int)
			if u == v {
				continue
			}
			if u > v {
				u = cal(u)
			} else {
				v = cal(v)
			}
			res++
			heap.Push(&a, u)
			heap.Push(&b, v)
		}
		writeInt(out, res)
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func numDigit(n int) int {
	cnt := 0
	for n > 0 {
		cnt++
		n /= 10
	}
	return cnt
}
func solve() {
	var n, x int
	scan(&n)
	a := make(map[int]int)
	for i := 0; i < n; i++ {
		scan(&x)
		a[x]++
	}
	for i := 0; i < n; i++ {
		scan(&x)
		a[x]--
	}
	r := 0
	flag := true
	firstLoop := true
	for flag == true && len(a) > 0 {
		flag = false
		for k, e := range a {
			if firstLoop {
				if e != 0 && k > 9 {
					// printf("1:%d %d\n", k, e)
					a[numDigit(k)] += e
					a[k] = 0
					flag = true // ok to continue loop
					r += 1
				}
			}
		}
		firstLoop = false
	}
	add := 0
	for k, e := range a {
		if e != 0 && k != 1 {
			// printf("need left:%d %d\n", k, e)
			add += int(math.Abs(float64(e)))
		}
	}
	printf("%d\n", r+add)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}


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 scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

// head
var n int
var e [][]int
var ret []int

type R struct {
	maxval int
	idx    int
	deps   []int
}

var stats []R

func dfs(u, f int) {
	if len(e[u]) == 0 {
		return
	}
	if len(e[u]) == 1 && e[u][0] == f {
		stats[u] = R{1, 0, []int{1}}
		ret[u] = 0
		return
	}

	maxdep := -1
	maxdep_idx := -1
	for _, v := range e[u] {
		if v == f {
			continue
		}
		dfs(v, u)
		if len(stats[v].deps) > maxdep {
			maxdep = len(stats[v].deps)
			maxdep_idx = v
		}
	}

	stats[u] = stats[maxdep_idx]

	for _, v := range e[u] {
		if v == f || v == maxdep_idx {
			continue
		}

		for iu, iv := len(stats[u].deps)-1, len(stats[v].deps)-1; iv >= 0; {
			stats[u].deps[iu] += stats[v].deps[iv]
			idx := len(stats[v].deps) - iv - 1
			if stats[u].deps[iu] > stats[u].maxval || (stats[u].deps[iu] == stats[u].maxval && idx < stats[u].idx) {
				stats[u].maxval = stats[u].deps[iu]
				stats[u].idx = idx
			}
			iv--
			iu--
		}
		stats[v].deps = nil
	}

	stats[u].deps = append(stats[u].deps, 1)
	if stats[u].maxval == 1 {
		stats[u].idx = 0
	} else {
		stats[u].idx++
	}

	ret[u] = stats[u].idx

	//println(u, stats[u])
}

func main() {
	defer writer.Flush()
	scan(&n)
	e = make([][]int, n+1)
	ret = make([]int, n+1)
	stats = make([]R, n+1)
	for i := 0; i < n-1; i++ {
		var u, v int
		scan(&u, &v)
		e[u] = append(e[u], v)
		e[v] = append(e[v], u)
	}

	dfs(1, -1)

	for i := 1; i < n+1; i++ {
		println(ret[i])
	}

}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1009F(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	n := r()
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		v, w := r()-1, r()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var _f func(v, fa int) int
	_f = func(v, fa int) int {
		maxDep, hs := 0, -1
		for _, w := range g[v] {
			if w != fa {
				if mxD := _f(w, v); mxD > maxDep {
					maxDep, hs = mxD, w
				}
			}
		}
		hson[v] = hs
		return maxDep + 1
	}
	_f(0, -1)

	ans := make([]int, n)
	var f func(v, fa int) ([]int, int)
	f = func(v, fa int) (cnt []int, maxI int) {
		if hson[v] == -1 {
			return []int{1}, 0
		}
		cnt, maxI = f(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				subCnt, _ := f(w, v)
				shift := len(cnt) - len(subCnt)
				for i, c := range subCnt {
					i += shift
					if cnt[i] += c; cnt[i] >= cnt[maxI] {
						maxI = i
					}
				}
			}
		}
		cnt = append(cnt, 1)
		if cnt[maxI] == 1 {
			maxI++
		}
		ans[v] = len(cnt) - 1 - maxI
		return
	}
	f(0, -1)
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	hson := make([]int, n)
	var _f func(v, fa int) int
	_f = func(v, fa int) int {
		maxDep, hs := 0, -1
		for _, w := range g[v] {
			if w != fa {
				if mxD := _f(w, v); mxD > maxDep {
					maxDep, hs = mxD, w
				}
			}
		}
		hson[v] = hs
		return maxDep + 1
	}
	_f(0, -1)

	ans := make([]int, n)
	var f func(v, fa int) ([]int, int)
	f = func(v, fa int) (cnt []int, maxI int) {
		if hson[v] == -1 {
			return []int{1}, 0
		}
		cnt, maxI = f(hson[v], v)
		for _, w := range g[v] {
			if w != fa && w != hson[v] {
				subCnt, _ := f(w, v)
				shift := len(cnt) - len(subCnt)
				for i, c := range subCnt {
					i += shift
					if cnt[i] += c; cnt[i] >= cnt[maxI] {
						maxI = i
					}
				}
			}
		}
		cnt = append(cnt, 1)
		if cnt[maxI] == 1 {
			maxI++
		}
		ans[v] = len(cnt) - 1 - maxI
		return
	}
	f(0, -1)
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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


package main

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

func main() {
    var n,k,i int
    var a [2000]int
    fmt.Scan(&n,&k)
    input:= bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)
    out := bufio.NewWriter(os.Stdout)
    for i=0;i<=2*n;i++ {
    	input.Scan()
	bb,_:=strconv.Atoi(input.Text())
	a[i]=bb
    	//fmt.Scan(&a[i])
    }
    out.WriteString(strconv.Itoa(a[0])+" ")
    //fmt.Print(a[0]," ")
    for i=1;i<=2*n;i++ {
    	if k!=0 && a[i]-1>a[i-1] && a[i]-1>a[i+1] {
    		out.WriteString(strconv.Itoa(a[i]-1)+" ")
    		//fmt.Print(a[i]-1," ")
    		k--
    	} else {
    		out.WriteString(strconv.Itoa(a[i])+" ")
    		//fmt.Print(a[i]," ")
    	}
    }
    out.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, k := scanInt(scanner), scanInt(scanner)
	ys := make([]int, 2*n+1)
	for i := 0; i < len(ys); i++ {
		ys[i] = scanInt(scanner)
	}
	for i := 1; i < len(ys); i += 2 {
		if ys[i]-ys[i-1] > 1 && ys[i]-ys[i+1] > 1 {
			ys[i]--
			k--
			if k == 0 {
				break
			}
		}
	}
	writer.WriteString(fmt.Sprintf("%d", ys[0]))
	for i := 1; i < len(ys); i++ {
		writer.WriteString(fmt.Sprintf(" %d", ys[i]))
	}
	writer.WriteString("\n")
}

package main

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

func main() {
    var n,k,i int
    var a [200]int
    fmt.Scan(&n,&k)
    input:= bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)
    out := bufio.NewWriter(os.Stdout)
    for i=0;i<=2*n;i++ {
    	input.Scan()
	bb,_:=strconv.Atoi(input.Text())
	a[i]=bb
    	//fmt.Scan(&a[i])
    }
    fmt.Print(a[0]," ")
    for i=1;i<=2*n;i++ {
    	if k!=0 && a[i]-1>a[i-1] && a[i]-1>a[i+1] {
    		out.WriteString(strconv.Itoa(a[i]-1)+" ")
    		//fmt.Print(a[i]-1," ")
    		k--
    	} else {
    		out.WriteString(strconv.Itoa(a[i])+" ")
    		//fmt.Print(a[i]," ")
    	}
    }
}


package main

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

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

func CF1671B(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		b := make([]int, n)
		p := [3]int{0, 1, -1}
		for _, v := range p {
			b[0] = a[0] + v
			for i := 1; i < n; i++ {
				b[i] = b[i-1] + 1
			}
			for i := range a {
				if a[i]-b[i] != 0 && a[i]-b[i] != 1 && a[i]-b[i] != -1 {
					goto h1
				}
			}
			fmt.Fprintln(out, "YES")
			goto h2
		h1:
		}
		fmt.Fprintln(out, "NO")
	h2:
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(in, &n)
		xs := make([]int, n)
		for i := range xs {
			fmt.Fscan(in, &xs[i])
		}
		ok := false
		if !ok {
			ok = true
			cur := xs[0] - 1
			for _, x := range xs {
				if cur-x < -1 || 1 < cur-x {
					ok = false
					break
				}
				cur++
			}
		}
		if !ok {
			ok = true
			cur := xs[0]
			for _, x := range xs {
				if cur-x < -1 || 1 < cur-x {
					ok = false
					break
				}
				cur++
			}
		}
		if !ok {
			ok = true
			cur := xs[0] + 1
			for _, x := range xs {
				if cur-x < -1 || 1 < cur-x {
					ok = false
					break
				}
				cur++
			}
		}
		if !ok {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i := range nums {
		fmt.Fscan(r, &nums[i])
	}
	outer:
	for i:=nums[0]-1;i<=nums[0]+1;i++ {
		for j:=i;j<i+n;j++ {
			if abs(j-nums[j-i]) > 1 {
				continue outer
			}
		}
		fmt.Fprintln(w, "Yes")
		return
	}
	fmt.Fprintln(w, "No")
}

func abs(a int) int {if a < 0 {return -a} else {return a}}
//func max(a, b int) int {if a > b {return a} else {return b}}

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ok := true
		two_count := 0
		three_count := 0

		for i := 1; i < n; i++ {
			diff := a[i] - a[i-1]
			if diff > 3 {
				ok = false
				break
			} else if diff > 1 {
				if diff == 2 {
					two_count++
				} else {
					three_count++
				}
				if two_count > 2 || three_count > 1 || (three_count >= 1 && two_count >= 1) {
					ok = false
					break
				}

			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

package main

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

const maxTokenSize = 2500000 * 7

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
    scanner.Scan()

    count, _ := strconv.Atoi(scanner.Text())

out:
    for i := 0; i < count; i++ {
        scanner.Scan()
        dotsCount, _ := strconv.Atoi(scanner.Text())

        var dots []int
        scanner.Scan()
        for _, dot := range strings.Split(scanner.Text(), " ") {
            d, _ := strconv.Atoi(dot)
            dots = append(dots, d)
        }

        if dotsCount == 1 {
            fmt.Println("YES")
            continue
        }

        var diff int
        for i := range dots {
            if len(dots)-1 == i {
				break
            }

            diff += dots[i+1] - dots[i] - 1
        }

        if diff <= 2 {
            fmt.Println("YES")
            continue out
        }

        fmt.Println("NO")
    }
}

package main

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

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

func solve() {
	var n int
	fmt.Fscan(in, &n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	cnt := 0
	for i := 1; i < n; i++ {
		cnt += v[i] - v[i-1] - 1
	}

	var ans string
	if cnt <= 2 {
		ans = "YES"
	} else {
		ans = "NO"
	}
	fmt.Fprintln(out, ans)
}
func main() {
	t := 0
	fmt.Fscan(in, &t)
	defer out.Flush()
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

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

var st [55]bool

func init() {
	for i := 0; i <= 50; i += 2 {
		for j := 0; i+j <= 50; j += 3 {
			st[i+j] = true
		}
	}
}

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

func solve() {
	// in := bufio.NewReader(os.Stdin)
	// s, _ := in.ReadString('\n')
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	cnt := 0
	for i := 1; i < n; i++ {
		cnt += v[i] - v[i-1] - 1
	}

	var ans string
	if cnt <= 2 {
		ans = "YES"
	} else {
		ans = "NO"
	}
	fmt.Fprintln(out, ans)
}
func main() {
	t := 0
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

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

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

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

	for ttmp := 0; ttmp < t; ttmp++ {
		var N int
		fmt.Fscan(in, &N)
		numbers := make([]int, N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &numbers[i])
		}
		sum := 0
		for i := 1; i < N; i++ {
			sum += (numbers[i] - numbers[i-1] - 1)
		}
		if sum <= 2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

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

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

	for ttmp := 0; ttmp < t; ttmp++ {
		var N int
		fmt.Fscan(in, &N)
		numbers := make([]int, N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &numbers[i])
		}
		sum := 0
		for i := 1; i < N; i++ {
			sum += (numbers[i] - numbers[i-1] - 1)
		}
		if sum <= 2 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

}

package main

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

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

func solve() {
	var N int
	fmt.Fscan(in, &N)
	//arr := make([]int64, N)

	check := true
	prev := 0

	ans := true

	for i := 0; i < N; i++ {
		//fmt.Fscan(in, &arr[i])
		var k int
		fmt.Fscan(in, &k)

		if i > 0 {
			switch dif := k - prev; dif {
			case 1:
				prev = k
			case 2:
				if check {
					prev = k
					check = false
				} else {
					prev = k - 1
				}
			case 3:
				if check {
					prev = k - 1
					check = false
				} else {
					ans = false
				}
			default:
				ans = false

			}
		} else {
			prev = k
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func main() {
	defer out.Flush()

	var N int
	fmt.Fscan(in, &N)

	for n := 0; n < N; n++ {
		solve()
	}

}

package main

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

const MOD int64 = 1000000007

var n int

var p []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		p = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

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

	prev := p[0] - 1

	res := true

	for i := 1; i < n; i++ {
		if p[i] - 2 == prev {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	res = true
	prev = p[0]

	for i := 1; i < n; i++ {
		if p[i] - 1 == prev {
			prev = p[i]
			continue
		} else if p[i] - 2 == prev {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	res = true
	prev = p[0] + 1

	for i := 1; i < n; i++ {
		if p[i] == prev {
			prev = p[i] + 1
			continue
		}
		if p[i] - 1 == prev {
			prev = p[i]
			continue
		} else if p[i] - 2 == prev {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

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

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		left := true
		right := true
		ans := "YES"
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] == 1 {
				continue
			} else if a[i]-a[i-1] == 2 {
				if left {
					left = false
				} else if right {
					right = false
				} else {
					ans = "NO"
					break
				}
			} else if a[i]-a[i-1] == 3 {
				if left && right {
					left = false
					right = false
				} else {
					ans = "NO"
					break
				}
			} else {
				ans = "NO"
				break
			}
		}
		Fprintln(out, ans)
	}
}

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

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

// https://codeforces.com/problemset/problem/1671/B

// 1671B - Consecutive Points Segment

// You are given n points with integer coordinates on a coordinate axis OX. The coordinate of the i-th point is xi. All points' coordinates are distinct and given in strictly increasing order.
// For each point i, you can do the following operation no more than once: take this point and move it by 1 to the left or to the right (i..e., you can change its coordinate xi to xi−1 or to xi+1). In other words, for each point, you choose (separately) its new coordinate. For the i-th point, it can be either xi−1, xi or xi+1.
// Your task is to determine if you can move some points as described above in such a way that the new set of points forms a consecutive segment of integers, i. e. for some integer l the coordinates of points should be equal to l,l+1,…,l+n−1.
// Note that the resulting points should have distinct coordinates.
// You have to answer t independent test cases.

// Input
// The first line of the input contains one integer t (1≤t≤2⋅10^4) — the number of test cases. Then t test cases follow.
// The first line of the test case contains one integer n (1≤n≤2⋅10^5) — the number of points in the set x.
// The second line of the test case contains n integers x1<x2<…<xn (1≤xi≤10^6), where xi is the coordinate of the i-th point.
// It is guaranteed that the points are given in strictly increasing order (this also means that all coordinates are distinct). It is also guaranteed that the sum of n does not exceed 2⋅10^5 (∑n≤2⋅10^5).

// Output
// For each test case, print the answer — if the set of points from the test case can be moved to form a consecutive segment of integers, print YES, otherwise print NO.

// Example
// input
// 5
// 2
// 1 4
// 3
// 1 2 3
// 4
// 1 2 3 7
// 1
// 1000000
// 3
// 2 5 6
// output
// YES
// YES
// NO
// YES
// YES

// Tutorial

// We can see that the answer is YES if and only if there are no more than two gaps of length 1 between the given points. If there is no gap, the answer is obviously YES. If there is only one gap of length 1, we can just move the left (or the right) part of the set to this gap. When there are two gaps, we can move the part before the first gap to the right and the part after the second gap to the left. Of course, if there is a gap of length at least 3 (or multiple gaps with the total length 3), we can't move the points from the left and the right part to satisfy the middle gap.
// Time complexity: O(n).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, i, first_x, last_x uint

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)

			fmt.Fscan(reader, &first_x)

			for i = 1; i < n; i++ {
				fmt.Fscan(reader, &last_x)
			}

			if last_x <= n+first_x+1 {
				fmt.Fprintln(writer, "YES")
			} else {
				fmt.Fprintln(writer, "NO")
			}
		}
	}

	writer.Flush()
}

package main

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

func test(a []int) {
	a[0] = 1
}

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t, "\n")
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		flag := false
		for i := -1; i < 2; i++ {
			for j := -1; j < 2; j++ {
				tmp := make([]int, n)
				copy(tmp, arr)
				tmp[0] += i
				tmp[n-1] += j
				f := true
				for k := 1; k < n-1; k++ {
					want := tmp[k-1] + 1
					if want == tmp[k] {
						continue
					}
					if want == tmp[k]+1 {
						tmp[k] += 1
					} else if want == tmp[k]-1 {
						tmp[k] -= 1
					} else {
						f = false
						break
					}
				}
				if n > 1 && tmp[n-1]-1 != tmp[n-2] {
					f = false
				}
				flag = flag || f
			}
		}

		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	var T, n int
O:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
	o:
		for l := a[0] - 1; l < a[0]+2; l++ {
			for i, v := range a {
				if abs(l+i-v) > 1 {
					continue o
				}
			}
			Fprintln(out, "YES")
			continue O
		}
		Fprintln(out, "NO")
	}
}

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

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

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		var d int
		for i := 1; i < n; i++ {
			d += arr[i] - arr[i-1] - 1
		}

		if d <= 2 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

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

/*
5
1
5
4
1 3 5 7
3
1 3 5
3
1 3 6
7
1 2 4 6 7 9 12
---
YES
NO
YES
NO
NO
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	x := make([]int, n)

	for i := range x {
		scanf("%d", &x[i])
	}
	scanf("\n")

	gapToCnt := make(map[int]int)

	for i, lft := range x[:n-1] {
		rht := x[i+1]

		gap := rht - lft
		if gap > 3 {
			fmt.Fprintln(writer, "NO")
			return
		}

		gapToCnt[gap]++
	}

	if gapToCnt[3] > 1 {
		fmt.Fprintln(writer, "NO")
		return
	}

	if gapToCnt[2] > 2 {
		fmt.Fprintln(writer, "NO")
		return
	}

	if gapToCnt[3] > 0 && gapToCnt[2] > 0 {
		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

	for ftr := 2; ftr <= sqrtA; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > sqrtA {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

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

	var T int
	var x int
	var n int

loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

		r := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r = append(r, x)
		}

		pre := r[0] + 1
		for i := 1; i < n; i++ {
			if r[i]-pre > 2 {
				Fprintln(out, "NO")
				continue loop
			}
			if r[i]-pre == 2 {
				pre = r[i] - 1
			} else if r[i]-pre == 1 {
				pre = r[i]
			} else if r[i] == pre {
				pre = r[i] + 1
			}
		}

		Fprintln(out, "YES")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ok := true
		two_count := 0
		three_count := 0

		for i := 1; i < n; i++ {
			diff := a[i] - a[i-1]
			if diff > 3 {
				ok = false
				break
			} else if diff > 1 {
				if diff == 2 {
					two_count++
				} else {
					three_count++
				}
				if two_count > 2 || three_count > 1 || three_count > 1 && two_count > 1 {
					ok = false
					break
				}

			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ok := true
		two_count := 0
		three_count := 0

		for i := 1; i < n; i++ {
			diff := a[i] - a[i-1]
			if diff > 3 {
				ok = false
				break
			} else if diff > 1 {
				if diff == 2 {
					two_count++
				} else {
					three_count++
				}
				if two_count > 2 || three_count > 1 {
					ok = false
					break
				}

			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ok := true
		used := false

		for i := 1; i < n; i++ {
			if a[i]-a[i-1] > 3 {
				ok = false
				break
			} else if a[i]-a[i-1] > 1 {
				if used {
					ok = false
					break
				} else {
					used = true
				}
			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ok := true
		used := false

		for i := 1; i < n; i++ {
			if a[i]-a[i-1] > 3 {
				ok = false
				break
			} else if a[i]-a[i] > 1 {
				if used {
					ok = false
					break
				} else {
					used = true
				}
			}
		}
		if ok {
			write(f, "YES\n")
		} else {
			write(f, "NO\n")
		}
	}
}

package main

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

const maxTokenSize = 2500000 * 7

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	count, _ := strconv.Atoi(scanner.Text())

out:
	for i := 0; i < count; i++ {
		scanner.Scan()
		dotsCount, _ := strconv.Atoi(scanner.Text())

		var dots []int
		scanner.Scan()
		for _, dot := range strings.Split(scanner.Text(), " ") {
			d, _ := strconv.Atoi(dot)
			dots = append(dots, d)
		}

		if dotsCount == 1 {
			fmt.Println("YES")
			continue
		}

		for i := range dots {
			if i == 0 {
				continue
			}

			if i == len(dots)-1 {
				if dots[i]-dots[i-1] > 3 {
					fmt.Println("NO")
					continue out
				}
				break
			}

			if dots[i]-dots[i-1] > 3 || dots[i+1]-dots[i] > 3 {
				fmt.Println("NO")
				continue out
			}

			if (dots[i]-dots[i-1])+(dots[i+1]-dots[i]) >= 5 {
				fmt.Println("NO")
				continue out
			}
		}

		fmt.Println("YES")
	}
}

package main

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

const maxTokenSize = 2500000 * 7

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	count, _ := strconv.Atoi(scanner.Text())

out:
	for i := 0; i < count; i++ {
		scanner.Scan()
		dotsCount, _ := strconv.Atoi(scanner.Text())

		var dots []int
		scanner.Scan()
		for _, dot := range strings.Split(scanner.Text(), " ") {
			d, _ := strconv.Atoi(dot)
			dots = append(dots, d)
		}

		if dotsCount == 1 {
			fmt.Println("YES")
			continue
		}

		for i := range dots {
			if i == 0 {
				continue
			}

			if i == len(dots)-1 {
				if dots[i]-dots[len(dots)-1] > 3 {
					fmt.Println("NO")
					continue out
				}
				break
			}

			if dots[i]-dots[i-1] > 3 || dots[i+1]-dots[i] > 3 {
				fmt.Println("NO")
				continue out
			}

			if (dots[i]-dots[i-1])+(dots[i+1]-dots[i]) >= 5 {
				fmt.Println("NO")
				continue out
			}
		}

		fmt.Println("YES")
	}
}

package main

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

const maxTokenSize = 2500000 * 7

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	count, _ := strconv.Atoi(scanner.Text())

out:
	for i := 0; i < count; i++ {
		scanner.Scan()
		dotsCount, _ := strconv.Atoi(scanner.Text())

		var dots []int
		scanner.Scan()
		for _, dot := range strings.Split(scanner.Text(), " ") {
			d, _ := strconv.Atoi(dot)
			dots = append(dots, d)
		}

		if dotsCount == 1 {
			fmt.Println("YES")
			continue
		}

		prevDot := dots[0]
		for _, dot := range dots[1:] {
			if dot - prevDot > 3 {
				fmt.Println("NO")
				continue out
			}

			prevDot = dot
		}

		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
)

var st [55]bool

func init() {
	for i := 0; i <= 50; i += 2 {
		for j := 0; i+j <= 50; j += 3 {
			st[i+j] = true
		}
	}
}

func solve() {
	// in := bufio.NewReader(os.Stdin)
	// s, _ := in.ReadString('\n')
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}
	cnt := 0
	for i := 1; i < n; i++ {
		cnt += v[i] - v[i-1] - 1
	}

	var ans string
	if cnt <= 2 {
		ans = "YES"
	} else {
		ans = "NO"
	}
	println(ans)
}
func main() {
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		//	fmt.Printf("i: %v\n", i)
		solve()
	}
}

package main

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

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

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

	for ttmp := 0; ttmp < t; ttmp++ {
		var N int
		fmt.Fscan(in, &N)
		numbers := make([]int, N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &numbers[i])
		}
		sum := 0
		for i := 1; i < N; i++ {
			sum += (numbers[i] - numbers[i-1] - 1)
		}
		if sum <= 2 {
			fmt.Println(out, "YES")
		} else {
			fmt.Println(out, "NO")
		}
	}

}

package main

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

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

func solve() {
	var N int
	fmt.Fscan(in, &N)
	//arr := make([]int64, N)

	check := true
	prev := 0

	ans := true

	for i := 0; i < N; i++ {
		//fmt.Fscan(in, &arr[i])
		var k int
		fmt.Fscan(in, &k)

		fmt.Println(k-prev, check)
		if i > 0 {
			switch dif := k - prev; dif {
			case 1:
				prev = k
			case 2:
				if check {
					prev = k
					check = false
				} else {
					prev = k - 1
				}
			case 3:
				if check {
					prev = k - 1
					check = false
				} else {
					ans = false
				}
			default:
				ans = false

			}
		} else {
			prev = k
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func main() {
	defer out.Flush()

	var N int
	fmt.Fscan(in, &N)

	for n := 0; n < N; n++ {
		solve()
	}

}

package main

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

const MOD int64 = 1000000007

var n int

var p []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		p = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

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

	prev := p[0] - 1

	res := true

	for i := 1; i < n; i++ {
		if p[i] - 1 == prev + 1 {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	res = true
	prev = p[0]

	for i := 1; i < n; i++ {
		if p[i] - 1 == prev {
			prev = p[i]
			continue
		} else if p[i] - 2 == prev {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	res = true
	prev = p[0] + 1

	for i := 1; i < n; i++ {
		if p[i] - 1 == prev {
			prev = p[i]
			continue
		} else if p[i] - 2 == prev {
			prev = p[i] - 1
			continue
		}
		res = false
		break
	}

	if res {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

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

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		left := true
		right := true
		ans := "YES"
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] == 1 {
				continue
			} else if a[i]-a[i-1] == 2 {
				if left {
					left = false
				} else {
					ans = "NO"
					break
				}
			} else if a[i]-a[i-1] == 3 {
				if left && right {
					left = false
					right = false
				} else {
					ans = "NO"
					break
				}
			} else {
				ans = "NO"
			}
		}
		Fprintln(out, ans)
	}
}

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

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