Let's define $$$f(x)$$$ for a positive integer $$$x$$$ as the length of the base-10 representation of $$$x$$$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that.You are given two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ positive integers. In one operation, you do the following:   pick some integer $$$i$$$ from $$$1$$$ to $$$n$$$;  assign either $$$f(a_i)$$$ to $$$a_i$$$ or $$$f(b_i)$$$ to $$$b_i$$$. Two arrays are considered similar to each other if you can rearrange the elements in both of them, so that they are equal (e. g. $$$a_i = b_i$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$).What's the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in each of the arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < 10^9$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_j < 10^9$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other.

NoteIn the first testcase, you can apply the digital logarithm to $$$b_1$$$ twice.In the second testcase, the arrays are already similar to each other.In the third testcase, you can first apply the digital logarithm to $$$a_1$$$, then to $$$b_2$$$.

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"
	"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 (
    "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"
	"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 (
	"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"
	"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"
	"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"
	"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"
	"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()
	}
}


You are given a rooted undirected tree consisting of $$$n$$$ vertices. Vertex $$$1$$$ is the root.Let's denote a depth array of vertex $$$x$$$ as an infinite sequence $$$[d_{x, 0}, d_{x, 1}, d_{x, 2}, \dots]$$$, where $$$d_{x, i}$$$ is the number of vertices $$$y$$$ such that both conditions hold:  $$$x$$$ is an ancestor of $$$y$$$;  the simple path from $$$x$$$ to $$$y$$$ traverses exactly $$$i$$$ edges. The dominant index of a depth array of vertex $$$x$$$ (or, shortly, the dominant index of vertex $$$x$$$) is an index $$$j$$$ such that:  for every $$$k < j$$$, $$$d_{x, k} < d_{x, j}$$$;  for every $$$k > j$$$, $$$d_{x, k} \le d_{x, j}$$$. For every vertex in the tree calculate its dominant index.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the number of vertices in a tree. Then $$$n - 1$$$ lines follow, each containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$, $$$x \ne y$$$). This line denotes an edge of the tree. It is guaranteed that these edges form a tree.

Output $$$n$$$ numbers. $$$i$$$-th number should be equal to the dominant index of vertex $$$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 (
	"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])
	}

}


Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1. We shall call a vertex of a polyline with an even x coordinate a mountain peak.   The figure to the left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k = 2.  Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).Given Bolek's final picture, restore the initial one.

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integers r1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture. It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.

Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.

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]," ")
    	}
    }
}