package main

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

var used []bool

func solve() {
	n := readInt()
	used = make([]bool, n)
	adj := make([][]int, n)
	for i := 1; i < n; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	fmt.Printf("%f", dfs(adj, 0))
}

func dfs(adj [][]int, v int) float64 {
	used[v] = true
	cnt := 0
	var sum float64
	for _, u := range adj[v] {
		if !used[u] {
			cnt++
		}
	}
	if cnt == 0 {
		return 0
	}
	for _, u := range adj[v] {
		if !used[u] {
			sum += dfs(adj, u) + float64(1)
		}
	}
	return sum / float64(cnt)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF839C(_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)
	g[0] = append(g[0], -1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	var f func(v, fa int) float64
	f = func(v, fa int) (l float64) {
		if len(g[v]) == 1 {
			return
		}
		p := 1 / float64(len(g[v])-1)
		for _, w := range g[v] {
			if w != fa {
				l += p * (f(w, v) + 1)
			}
		}
		return
	}
	ans := f(0, -1)
	Fprintf(out, "%.15f", ans)
}

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

package main

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

type tuple struct {
	node         int
	branch_count float64
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	edge := make([][]int, N)
	for i := 0; i < N; i++ {
		edge[i] = make([]int, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt()-1, sc.NextInt()-1
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}

	checked := make([]bool, N)
	queue := make([]tuple, 1)
	queue[0] = tuple{0, 1}
	checked[0] = true
	count := 0
	p := 0

	ans := 0.0

	for {
		last := len(queue)
		if p == last {
			break
		}
		for ; p < last; p++ {
			branch_count := len(edge[queue[p].node]) - 1
			if p == 0 {
				branch_count++
			}
			for _, nx := range edge[queue[p].node] {
				if !checked[nx] {
					queue = append(queue, tuple{nx, queue[p].branch_count * float64(branch_count)})
					checked[nx] = true
				}
			}
			if branch_count == 0 {
				ans += float64(count) / float64(queue[p].branch_count)
			}
		}
		count++
	}
	fmt.Println(ans)
}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	in := NewScanner(os.Stdin)
	nV := in.NextInt()

	T := make([][]int, nV)
	for i := 0; i < nV-1; i++ {
		u, v := in.NextInt()-1, in.NextInt()-1
		T[u] = append(T[u], v)
		T[v] = append(T[v], u)
	}

	sums := make([]float64, nV)
	dfs(T, sums, 0, -1)
	fmt.Printf("%f\n", sums[0])
}

func dfs(T [][]int, sums []float64, current, parent int) {
	sum := 0
	for _, child := range T[current] {
		if child == parent {
			continue
		}
		dfs(T, sums, child, current)
		sum += 1
		sums[current] += sums[child] + 1
	}
	if sum > 0 {
		sums[current] /= float64(sum)
	}
}

//Boiler-Plate
func assert(x bool) {
	if !x {
		panic("assertion failed")
	}
}

type Scanner struct {
	is     io.Reader
	buffer [1 << 16]byte
	size   int
	pos    int
}

func NewScanner(in io.Reader) *Scanner {
	return &Scanner{is: in}
}

func (s *Scanner) nextChar() int {
	if s.pos >= s.size {
		var err error
		s.size, err = s.is.Read(s.buffer[:])
		s.pos = 0
		if err == io.EOF {
			return -1
		}
	}
	assert(s.pos < s.size)
	c := s.buffer[s.pos]
	s.pos++
	return int(c)
}

const BitsPerInt = 32 << uint(^uint(0)>>63)

const MinInt = -1 << (BitsPerInt - 1)

const MaxInt = -(MinInt + 1)

func (s *Scanner) NextInt() int {
	c := s.nextChar()
	for c == ' ' || c == '\r' || c == '\n' || c == '\t' {
		c = s.nextChar()
	}
	if c == '-' {
		c = s.nextChar()
		assert('0' <= c && c <= '9')
		n := -(c - '0')
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n > MinInt/10 || n == MinInt/10 && d <= -(MinInt%10))
			n = n*10 - d
		}
		return n
	} else {
		assert('0' <= c && c <= '9')
		n := c - '0'
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n < MaxInt/10 || n == MaxInt/10 && d <= MaxInt%10)
			n = n*10 + d
		}
		return n
	}
}

package main

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

func main() {
	in := NewScanner(os.Stdin)
	nV := in.NextInt()

	T := make([][]int, nV)
	for i := 0; i < nV-1; i++ {
		u, v := in.NextInt()-1, in.NextInt()-1
		T[u] = append(T[u], v)
		T[v] = append(T[v], u)
	}

	sums := make([]float64, nV)
	dfs(T, sums, 0, -1)
	fmt.Printf("%f\n", sums[0])
}

func dfs(T [][]int, sums []float64, current, parent int) {
	sum := 0
	for _, child := range T[current] {
		if child == parent {
			continue
		}
		dfs(T, sums, child, current)
		sum += 1
		sums[current] += sums[child] + 1
	}
	if sum > 0 {
		sums[current] /= float64(sum)
	} else {
		sums[current] = 0
	}
}

//Boiler-Plate
func assert(x bool) {
	if !x {
		panic("assertion failed")
	}
}

type Scanner struct {
	is     io.Reader
	buffer [1 << 16]byte
	size   int
	pos    int
}

func NewScanner(in io.Reader) *Scanner {
	return &Scanner{is: in}
}

func (s *Scanner) nextChar() int {
	if s.pos >= s.size {
		var err error
		s.size, err = s.is.Read(s.buffer[:])
		s.pos = 0
		if err == io.EOF {
			return -1
		}
	}
	assert(s.pos < s.size)
	c := s.buffer[s.pos]
	s.pos++
	return int(c)
}

const BitsPerInt = 32 << uint(^uint(0)>>63)

const MinInt = -1 << (BitsPerInt - 1)

const MaxInt = -(MinInt + 1)

func (s *Scanner) NextInt() int {
	c := s.nextChar()
	for c == ' ' || c == '\r' || c == '\n' || c == '\t' {
		c = s.nextChar()
	}
	if c == '-' {
		c = s.nextChar()
		assert('0' <= c && c <= '9')
		n := -(c - '0')
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n > MinInt/10 || n == MinInt/10 && d <= -(MinInt%10))
			n = n*10 - d
		}
		return n
	} else {
		assert('0' <= c && c <= '9')
		n := c - '0'
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n < MaxInt/10 || n == MaxInt/10 && d <= MaxInt%10)
			n = n*10 + d
		}
		return n
	}
}

package main

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

func main() {
	in := NewScanner(os.Stdin)
	nV := in.NextInt()

	T := make([][]int, nV)
	for i := 0; i < nV-1; i++ {
		u, v := in.NextInt()-1, in.NextInt()-1
		T[u] = append(T[u], v)
		T[v] = append(T[v], u)
	}

	sums := make([]float64, nV)
	dfs(T, sums, 0, -1)
	fmt.Printf("%f\n", sums[0]/2.0)
}

func dfs(T [][]int, sums []float64, current, parent int) {
	for _, child := range T[current] {
		if child == parent {
			continue
		}
		dfs(T, sums, child, current)
		sums[current] += sums[child] + 1
	}
}

//Boiler-Plate
func assert(x bool) {
	if !x {
		panic("assertion failed")
	}
}

type Scanner struct {
	is     io.Reader
	buffer [1 << 16]byte
	size   int
	pos    int
}

func NewScanner(in io.Reader) *Scanner {
	return &Scanner{is: in}
}

func (s *Scanner) nextChar() int {
	if s.pos >= s.size {
		var err error
		s.size, err = s.is.Read(s.buffer[:])
		s.pos = 0
		if err == io.EOF {
			return -1
		}
	}
	assert(s.pos < s.size)
	c := s.buffer[s.pos]
	s.pos++
	return int(c)
}

const BitsPerInt = 32 << uint(^uint(0)>>63)

const MinInt = -1 << (BitsPerInt - 1)

const MaxInt = -(MinInt + 1)

func (s *Scanner) NextInt() int {
	c := s.nextChar()
	for c == ' ' || c == '\r' || c == '\n' || c == '\t' {
		c = s.nextChar()
	}
	if c == '-' {
		c = s.nextChar()
		assert('0' <= c && c <= '9')
		n := -(c - '0')
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n > MinInt/10 || n == MinInt/10 && d <= -(MinInt%10))
			n = n*10 - d
		}
		return n
	} else {
		assert('0' <= c && c <= '9')
		n := c - '0'
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n < MaxInt/10 || n == MaxInt/10 && d <= MaxInt%10)
			n = n*10 + d
		}
		return n
	}
}

package main

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

func main() {
	in := NewScanner(os.Stdin)
	nV := in.NextInt()

	T := make([][]int, nV)
	for i := 0; i < nV-1; i++ {
		u, v := in.NextInt()-1, in.NextInt()-1
		T[u] = append(T[u], v)
		T[v] = append(T[v], u)
	}

	sums := make([]int, nV)
	dfs(T, sums, 0, -1)
	fmt.Printf("%f\n", float64(sums[1]+sums[2])/2.0)
}

func dfs(T [][]int, sums []int, current, parent int) {
	sum := 0
	for _, child := range T[current] {
		if child == parent {
			continue
		}
		dfs(T, sums, child, current)
		sum += 1
	}
	sums[current] = sum + 1
}

//Boiler-Plate
func assert(x bool) {
	if !x {
		panic("assertion failed")
	}
}

type Scanner struct {
	is     io.Reader
	buffer [1 << 16]byte
	size   int
	pos    int
}

func NewScanner(in io.Reader) *Scanner {
	return &Scanner{is: in}
}

func (s *Scanner) nextChar() int {
	if s.pos >= s.size {
		var err error
		s.size, err = s.is.Read(s.buffer[:])
		s.pos = 0
		if err == io.EOF {
			return -1
		}
	}
	assert(s.pos < s.size)
	c := s.buffer[s.pos]
	s.pos++
	return int(c)
}

const BitsPerInt = 32 << uint(^uint(0)>>63)

const MinInt = -1 << (BitsPerInt - 1)

const MaxInt = -(MinInt + 1)

func (s *Scanner) NextInt() int {
	c := s.nextChar()
	for c == ' ' || c == '\r' || c == '\n' || c == '\t' {
		c = s.nextChar()
	}
	if c == '-' {
		c = s.nextChar()
		assert('0' <= c && c <= '9')
		n := -(c - '0')
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n > MinInt/10 || n == MinInt/10 && d <= -(MinInt%10))
			n = n*10 - d
		}
		return n
	} else {
		assert('0' <= c && c <= '9')
		n := c - '0'
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n < MaxInt/10 || n == MaxInt/10 && d <= MaxInt%10)
			n = n*10 + d
		}
		return n
	}
}

package main

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

func main() {
	in := NewScanner(os.Stdin)
	nV := in.NextInt()

	T := make([][]int, nV)
	for i := 0; i < nV-1; i++ {
		u, v := in.NextInt()-1, in.NextInt()-1
		T[u] = append(T[u], v)
		T[v] = append(T[v], u)
	}

	sums := make([]float64, nV)
	dfs(T, sums, 0, -1)
	fmt.Println(sums)
	fmt.Printf("%f\n", sums[0])
}

func dfs(T [][]int, sums []float64, current, parent int) {
	for _, child := range T[current] {
		if child == parent {
			continue
		}
		dfs(T, sums, child, current)
		sums[current] += sums[child] + 1
	}
}

//Boiler-Plate
func assert(x bool) {
	if !x {
		panic("assertion failed")
	}
}

type Scanner struct {
	is     io.Reader
	buffer [1 << 16]byte
	size   int
	pos    int
}

func NewScanner(in io.Reader) *Scanner {
	return &Scanner{is: in}
}

func (s *Scanner) nextChar() int {
	if s.pos >= s.size {
		var err error
		s.size, err = s.is.Read(s.buffer[:])
		s.pos = 0
		if err == io.EOF {
			return -1
		}
	}
	assert(s.pos < s.size)
	c := s.buffer[s.pos]
	s.pos++
	return int(c)
}

const BitsPerInt = 32 << uint(^uint(0)>>63)

const MinInt = -1 << (BitsPerInt - 1)

const MaxInt = -(MinInt + 1)

func (s *Scanner) NextInt() int {
	c := s.nextChar()
	for c == ' ' || c == '\r' || c == '\n' || c == '\t' {
		c = s.nextChar()
	}
	if c == '-' {
		c = s.nextChar()
		assert('0' <= c && c <= '9')
		n := -(c - '0')
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n > MinInt/10 || n == MinInt/10 && d <= -(MinInt%10))
			n = n*10 - d
		}
		return n
	} else {
		assert('0' <= c && c <= '9')
		n := c - '0'
		c = s.nextChar()
		for '0' <= c && c <= '9' {
			d := c - '0'
			c = s.nextChar()
			assert(n < MaxInt/10 || n == MaxInt/10 && d <= MaxInt%10)
			n = n*10 + d
		}
		return n
	}
}

package main

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

var lastSum int
var lastCnt int

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	vis := make(map[int]bool)
	dfs(adj, 0, -1, 0, vis)
	fmt.Printf("%f", float64(lastSum)/float64(lastCnt))
}

func dfs(adj [][]int, cur, from, l int, vis map[int]bool) {
	vis[cur] = true
	last := true
	for _, v := range adj[cur] {
		if v != from && vis[v] == false {
			dfs(adj, v, cur, l+1, vis)
			last = false
		}
	}
	if last {
		lastCnt++
		lastSum += l
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}

	fmt.Printf("%f", dfs(adj, 0, -1))
}

func dfs(adj [][]int, v, p int) float64 {
	var sum float64
	for _, u := range adj[v] {
		if u != p {
			sum += dfs(adj, u, v) + float64(1)
		}
	}
	cnt := len(adj[v])
	if p != -1 {
		cnt--
	}
	if cnt > 0 {
		sum /= float64(cnt)
	}
	return sum
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var res []int

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	vis := make(map[int]bool)
	dfs(adj, 0, -1, 0, vis)
	total := int64(0)
	for i := 0; i < len(res); i++ {
		total += int64(res[i])
	}
	fmt.Printf("%+v", float64(total)/float64(len(res)))
}

func dfs(adj [][]int, cur, from, l int, vis map[int]bool) {
	vis[cur] = true
	last := true
	for _, v := range adj[cur] {
		if v != from && vis[v] == false {
			dfs(adj, v, cur, l+1, vis)
			last = false
		}
	}
	if last {
		res = append(res, l)
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var lastSum int
var lastCnt int

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	dfs(adj, 0, -1, 0)
	fmt.Printf("%+v", float64(lastSum)/float64(lastCnt))
}

func dfs(adj [][]int, cur, from, l int) {
	last := true
	for _, v := range adj[cur] {
		if v != from {
			dfs(adj, v, cur, l+1)
			last = false
		}
	}
	if last {
		lastCnt++
		lastSum += l
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}

	fmt.Printf("%f", dfs(adj, 0, -1))
}

func dfs(adj [][]int, cur, from int) float64 {
	cnt := 0
	var sum float64
	for _, v := range adj[cur] {
		if v != from {
			sum += dfs(adj, v, cur) + 1
			cnt++
		}
	}
	if cnt != 0 {
		sum /= float64(cnt)
	}
	return sum
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var lastSum int
var lastCnt int

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	dfs(adj, 0, 0, -1)
	fmt.Printf("%+v", float64(lastSum)/float64(lastCnt))
}

func dfs(adj [][]int, cur, from, l int) {
	last := true
	for _, v := range adj[cur] {
		if v != from {
			dfs(adj, v, cur, l+1)
			last = false
		}
	}
	if last {
		lastCnt++
		lastSum += l + 1
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var res float64

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	dfs(adj, 0, -1, 0, 1.0)
	fmt.Printf("%+v", res)
}

func dfs(adj [][]int, cur, from, l int, prob float64) {
	cnt := 0
	for _, v := range adj[cur] {
		if v != from {
			cnt++
		}
	}
	if cnt == 0 {
		res += float64(l) * prob
		return
	}
	for _, v := range adj[cur] {
		if v != from {
			dfs(adj, v, cur, l+1, prob/float64(cnt))
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var lastSum int
var lastCnt int

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	vis := make(map[int]bool)
	dfs(adj, 0, -1, 0, vis)
	fmt.Printf("%+v", float64(lastSum)/float64(lastCnt))
}

func dfs(adj [][]int, cur, from, l int, vis map[int]bool) {
	vis[cur] = true
	last := true
	for _, v := range adj[cur] {
		if v != from && vis[v] == false {
			dfs(adj, v, cur, l+1, vis)
			last = false
		}
	}
	if last {
		lastCnt++
		lastSum += l
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

var res float64

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}
	dfs(adj, 0, -1, 0, 1.0)
	fmt.Printf("%f", res)
}

func dfs(adj [][]int, cur, from, l int, prob float64) {
	cnt := 0
	for _, v := range adj[cur] {
		if v != from {
			cnt++
		}
	}
	if cnt == 0 {
		res += float64(l) * prob
		return
	}
	for _, v := range adj[cur] {
		if v != from {
			dfs(adj, v, cur, l+1, prob/float64(cnt))
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	n := readInt()
	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		adj[u] = append(adj[u], v)
	}

	fmt.Printf("%f", dfs(adj, 0, -1))
}

func dfs(adj [][]int, cur, from int) float64 {
	cnt := 0
	var sum float64
	for _, v := range adj[cur] {
		if v != from {
			sum += dfs(adj, v, cur) + float64(1)
			cnt++
		}
	}
	if cnt != 0 {
		sum /= float64(cnt)
	}
	return sum
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

type tuple struct {
	node         int
	branch_count int64
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	edge := make([][]int, N)
	for i := 0; i < N; i++ {
		edge[i] = make([]int, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt()-1, sc.NextInt()-1
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}

	checked := make([]bool, N)
	queue := make([]tuple, 1)
	queue[0] = tuple{0, 1}
	checked[0] = true
	count := 0
	p := 0

	ans := 0.0

	for {
		last := len(queue)
		if p == last {
			break
		}
		for ; p < last; p++ {
			branch_count := len(edge[queue[p].node]) - 1
			if p == 0 {
				branch_count++
			}
			for _, nx := range edge[queue[p].node] {
				if !checked[nx] {
					queue = append(queue, tuple{nx, queue[p].branch_count * int64(branch_count)})
					checked[nx] = true
				}
			}
			if branch_count == 0 {
				ans += float64(count) / float64(queue[p].branch_count)
			}
		}
		count++
	}
	fmt.Println(ans)
}

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

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

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

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

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

	return mp
}

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

package main

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

type tuple struct {
	edge         int
	branch_count int
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	edge := make([][]int, N)
	for i := 0; i < N; i++ {
		edge[i] = make([]int, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt()-1, sc.NextInt()-1
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}

	checked := make([]bool, N)
	queue := make([]tuple, 1)
	queue[0] = tuple{0, 1}
	checked[0] = true
	count := 0
	p := 0

	ans := 0.0

	for {
		last := len(queue)
		if p == last {
			break
		}
		for ; p < last; p++ {
			branch_count := len(edge[queue[p].edge]) - 1
			if p == 0 {
				branch_count++
			}
			for _, nx := range edge[queue[p].edge] {
				if !checked[nx] {
					queue = append(queue, tuple{nx, queue[p].branch_count * branch_count})
					checked[nx] = true
				}
			}
			if branch_count == 0 {
				ans += float64(count) / float64(queue[p].branch_count)
			}
		}
		count++
	}
	fmt.Println(ans)
}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	edge := make([][]int, N)
	for i := 0; i < N; i++ {
		edge[i] = make([]int, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt()-1, sc.NextInt()-1
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}

	checked := make([]float64, N)
	queue := make([]int, 1)
	queue[0] = 0
	checked[0] = 1
	count := 0
	p := 0

	ans := 0.0
	for {
		last := len(queue)
		if p == last {
			break
		}
		for ; p < last; p++ {
			branch_count := len(edge[queue[p]]) - 1
			if p == 0 {
				branch_count++
			}
			for _, nx := range edge[queue[p]] {
				if checked[nx] == 0 {
					queue = append(queue, nx)
					checked[nx] = checked[queue[p]] * 1 / float64(branch_count)
				}
			}
			if branch_count == 0 {
				ans += checked[queue[p]] * float64(count)
			}
		}
		count++
	}
	fmt.Println(ans)
}

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

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

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

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

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

	return mp
}

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


package main

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

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

	var t, n, k, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		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)
		}
		if k == 1 {
			Fprintln(out, n-1)
			continue
		}
		if n == 2 {
			Fprintln(out, 0)
			continue
		}

		ans := 0
		q := []int{}
		onQ := make([]bool, n)
		lc := make([]int, n)
		isLeaf := make([]bool, n)
		for v, vs := range g {
			for _, w := range vs {
				if len(g[w]) == 1 {
					lc[v]++
					isLeaf[w] = true
				}
			}
			if lc[v] > 0 &&  lc[v]+1 >= len(vs) && lc[v]%k == 0 {
				q = append(q, v)
				onQ[v] = true
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			onQ[v] = false
			ans += lc[v] / k
			lc[v] = 0
			isLeaf[v] =true
			for _, w := range g[v] {
				if isLeaf[w] {
					continue
				}
				lc[w]++
				if lc[w]+1 >= len(g[w]) && lc[w]%k == 0 {
					if !onQ[w] {
						q = append(q, w)
						onQ[w] = true
					}
					//g[v] = []int{w}
					break
				}
			}
		}
		for _, c := range lc {
			ans += c / k
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,k int
		Fscan(in,&n,&k)
		e := make([][] int ,n)
		vis := make([] bool, n)
		stk := make([] int,0,n)
		deg := make([] int,n)
		ct := make([] int,n)
		ans:=0

		for i:=0;i<n-1;i++{
			var u,v int
			Fscan(in,&u,&v)
			u--
			v--
			deg[u]++
			deg[v]++
			e[u]=append(e[u],v)
			e[v]=append(e[v],u)
		}
		if k==1{
			Fprintln(out,n-1)
			continue
		}
		findPar := func(u int) int {
			for _,v := range(e[u]){
				if vis[v]{
					return v
				}
			}
			return -1
			// panic("No Parent")
		}

		for i:=0;i<n;i++{
			vis[i]=true
			if deg[i]==1{
				stk=append(stk,i)
			}
		}

		for i:=0;i<n-1;i++{
			if len(stk)==i{
				break
			}
			cur:=stk[i]
			vis[cur]=false
			// Fprintln(out,"remove",cur+1)
			par:=findPar(cur)
			deg[par]--
			deg[cur]--
			ct[par]++
			if ct[par]==k{
				ct[par]=0
				ans++
			}
			if deg[par]==1 && (len(e[par])-1)%k==0{
				stk=append(stk,par)
			}
		}

		Fprintln(out,ans)
	}
}

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

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n, k := io.nextInt(), io.nextInt()
		g := make([][]int, n+1)
		deg := make([]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v := io.nextInt(), io.nextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
			deg[u]++
			deg[v]++
		}

		var q []int
		for u := 1; u <= n; u++ {
			if deg[u] == 1 {
				q = append(q, u)
			}
		}

		ans := 0
		cnt := make([]int, n+1)
		ded := make([]bool, n+1)
		for len(q) > 0 {
			u := q[0]
			ded[u] = true
			q = q[1:]
			for _, p := range g[u] {
				if ded[p] {
					continue
				}
				cnt[p]++
				deg[p]--
				if cnt[p]%k == 0 {
					ans++
					if deg[p] == 1 {
						q = append(q, p)
					}
				}
			}
		}

		io.println(ans)
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) next() string {
	f.Read(f.p)
	for f.p[0] <= ' ' {
		f.Read(f.p)
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p)
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

package main

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

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

	var t, n, k, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		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)
		}
		if k == 1 {
			Fprintln(out, n-1)
			continue
		}

		ans := 0
		q := []int{}
		lc := make([]int, n)
		used := make([]bool, n)
		for v, vs := range g {
			for _, w := range vs {
				if len(g[w]) == 1 {
					lc[v]++
					used[w] = true
				}
			}
			if len(vs) > 1 && lc[v]+1 >= len(vs) && lc[v]%k == 0 {
				q = append(q, v)
			}
		}
		for len(q) > 0 {
			v, q = q[0], q[1:]
			ans += lc[v] / k
			lc[v] = 0
			used[v] = true
			for _, w := range g[v] {
				if !used[w] {
					lc[w]++
					if lc[w]+1 >= len(g[w]) && lc[w]%k == 0 {
						q = append(q, w)
					}
					break
				}
			}
		}
		for _, c := range lc {
			ans += c / k
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, k, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		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)
		}
		if k == 1 {
			Fprintln(out, n-1)
			continue
		}

		ans := 0
		q := []int{}
		lc := make([]int, n)
		for v, vs := range g {
			for _, w := range vs {
				if len(g[w]) == 1 {
					lc[v]++
				}
			}
			if lc[v]+1 >= len(vs) && lc[v] >= k {
				q = append(q, v)
			}
		}
		//Println(q)
		for len(q) > 0 {
			v, q = q[0], q[1:]
			if lc[v]%k == 0 {
				ans += lc[v] / k
				for _, w := range g[v] {
					if len(g[w]) > 1 && lc[w]+2 >= len(g[w]) {
						q = append(q, w)
						lc[w]++
						g[v] = []int{w}
						break
					}
				}
				lc[v] = 0
			}
		}
		for _, c := range lc {
			ans += c / k
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, k, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		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)
		}
		if k == 1 {
			Fprintln(out, n-1)
			continue
		}

		ans := 0
		q := []int{}
		lc := make([]int, n)
		for v, vs := range g {
			for _, w := range vs {
				if len(g[w]) == 1 {
					lc[v]++
				}
			}
			if lc[v]+1 >= len(vs) && lc[v] >= k {
				q = append(q, v)
			}
		}
		//Println(q)
		for len(q) > 0 {
			v, q = q[0], q[1:]
			ans += lc[v] / k
			if lc[v] > 0 && lc[v]%k == 0 {
				for _, w := range g[v] {
					if len(g[w]) > 1 && lc[w]+2 >= len(g[w]) {
						q = append(q, w)
						lc[w]++
						g[v] = []int{w}
						break
					}
				}
			}
			lc[v] %= k
		}
		// 收拾残局
		for _, c := range lc {
			ans += c / k
		}
		Fprintln(out, ans)
	}
}

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


package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &data[i].a)
	}

	fmt.Scanf("%d\n", &data[n-1].a)

	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a
	}

	fmt.Scanf("%d\n", &data[n-1].b)
	data[n-1].c = k*data[n-1].b - data[n-1].a

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}
const MAXN = 200000 + 10
const fi = 100000
func max(a , b int) int{

	if(a > b){
		return a
	}

	return b
}

func main(){
	scanner = bufio.NewScanner(os.Stdin)
  	scanner.Split(bufio.ScanWords)
 	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n := getI()
	k := getI()

	var a,b [100+10]int
	var vis [MAXN]bool
	var dp,x [MAXN]int
	vis[fi] = true
	for i := 0 ; i < n ; i ++{
		a[i] = getI()
	}

	for i := 0 ; i < n ; i ++{
		b[i] = getI()
	}

	ch := false

	for i := 0 ; i < n ; i ++{
		tmp := a[i] - k*b[i]
		var v []int
		for j := 0 ; j <= 200000 ; j ++{
			x[j] = 0
			if vis[j]{
				v = append(v,j)
			}
		}
		l := len(v)

		for j := 0 ; j < l ; j ++{
			idx := v[j] + tmp
			if idx < 0 {
				continue
			}

			x[idx] = max(x[idx], dp[v[j]] + a[i])

			vis[idx] = true
			if idx == fi {
				ch = true
			}
		 }

		 for j := 0 ; j <= 200000 ; j ++ {
			 dp[j] = max(dp[j],x[j])
		 }
	}

	if ch {
		writer.WriteString(fmt.Sprintf("%v\n",dp[fi]))
	}else{
		writer.WriteString(fmt.Sprintf("-1\n"))
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k, s int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
		if a[i] == k*b[i] {
			s += a[i]
		}
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		if w := v - k*b[i]; w > 0 {
			for j := mx; j >= w; j-- {
				dp1[j] = max(dp1[j], dp1[j-w]+v)
			}
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		if w := k*b[i] - v; w > 0 {
			for j := mx; j >= w; j-- {
				dp2[j] = max(dp2[j], dp2[j-w]+v)
			}
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	ans += s
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		w := v - k*b[i]
		if w < 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp1[j] = max(dp1[j], dp1[j-w]+v)
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		w := k*b[i] - v
		if w <= 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp2[j] = max(dp2[j], dp2[j-w]+v)
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k, s int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
		if a[i] == k*b[i] {
			s += a[i]
		}
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		w := v - k*b[i]
		if w < 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp1[j] = max(dp1[j], dp1[j-w]+v)
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		w := k*b[i] - v
		if w <= 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp2[j] = max(dp2[j], dp2[j-w]+v)
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	ans += s
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].a)
		fmt.Printf("%d ", data[i].a)
	}

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a

		fmt.Printf("%d ", data[i].b)
	}

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}

package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].a)
	}

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a
	}

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}


package main

import (
	"fmt"
	"sort"
)

var (
	t, n int
	a    = make([]int, 1024)
	b    = make([]int, 1024)
)

func main() {
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &a[j])
		}
		fmt.Scanf("\n")
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &b[j])
		}
		fmt.Scanf("\n")
		sort.Ints(a[0:n])
		sort.Ints(b[0:n])
		// fmt.Printf("a is %v\n", a)
		// fmt.Printf("b is %v\n", b)
		ret := true
		for j := 0; j < n; j++ {
			if b[j] < a[j] || b[j] > a[j]+1 {
				ret = false
				break
			}
		}
		if ret {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

/*
3
1
4
5
1
3
5
3
1 2 4
2 3 4
---
YES
NO
YES
====
1
1
3
5
---
NO
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		b := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &b[i])
		}
		scanf("\n")

		sort.Ints(a)
		sort.Ints(b)

		possible := true

		for i, numA := range a {
			numB := b[i]
			if numA != numB && numA+1 != numB {
				possible = false
				break
			}
		}

		if possible {
			fmt.Fprintln(&bld, "YES")
		} else {
			fmt.Fprintln(&bld, "NO")
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(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 {
	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))
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&b[j])
		}
		sort.Slice(b, func(i, j int) bool {
			return b[i] < b[j]
		})

		no := false
		for j := 0; j < n; j++ {
			if a[j] == b[j] {
				continue
			}
			if a[j]+1 != b[j] {
				fmt.Println("NO")
				no = true
				break
			}
		}

		if !no {
			fmt.Println("YES")
		}

	}
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)
		b := readArrayInt(reader)

		sort.Ints(a)
		sort.Ints(b)
		ok := true
		for i := 0; i < n; i++ {
			if a[i] == b[i] || a[i] + 1 == b[i] {
				continue
			}
			fmt.Fprintln(writer, "NO")
			ok = false
			break
		}

		if ok {
			fmt.Fprintln(writer, "YES")
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)
		b := readArrayInt(reader)

		sort.Ints(a)
		sort.Ints(b)
		ok := true
		for i := 0; i < n; i++ {
			if a[i] == b[i] || a[i] + 1 == b[i] {
				continue
			}
			fmt.Fprintln(writer, "NO")
			ok = false
		}

		if ok {
			fmt.Fprintln(writer, "YES")
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}

package main

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

/*
3
1
4
5
1
3
5
3
1 2 4
2 3 4
---
YES
NO
YES
====
1
1
3
5
---
NO
*/

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

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		b := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &b[i])
		}
		scanf("\n")

		possible := equals(a, b)

		if !possible {
			for k := 0; k < n; k++ {
				a[k]++

				if equals(a, b) {
					possible = true
					break
				}
			}
		}

		if possible {
			fmt.Fprintln(&bld, "YES")
		} else {
			fmt.Fprintln(&bld, "NO")
		}
	}

	printf("%s", bld.String())
}

func equals(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}

	sortedA := make([]int, len(a))
	sortedB := make([]int, len(b))

	copy(sortedA, a)
	copy(sortedB, b)

	sort.Ints(sortedA)
	sort.Ints(sortedB)

	for i, num := range sortedA {
		if num != sortedB[i] {
			return false
		}
	}

	return true
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(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 {
	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))
}


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 s string
		fmt.Fscan(in, &s)

		var idx int
	Loop:
		for i := 'a'; i <= 'z'; i++ {
			for k, ch := range s {
				if ch == i {
					idx = k
					break Loop
				}
			}
		}

		fmt.Fprintf(out, "%c %s\n", s[idx], s[:idx]+s[idx+1:])
	}
}

package main

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

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

func (in *CF1602A) 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 *CF1602A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1602A
Date: 21/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1602/A
Problem: CF1602A
**/
func (in *CF1602A) Run() {
	var ans strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		min := str[0]
		for i := 0; i < len(str); i++ {
			if str[i] < min {
				min = str[i]
			}
		}
		ans.WriteString(fmt.Sprintf("%s ", string(min)))
		found := false
		for i := 0; i < len(str); i++ {
			if str[i] == min && !found {
				found = true
				continue
			} else {
				ans.WriteString(string(str[i]))
			}
		}
		ans.WriteString("\n")
	}
	fmt.Print(ans.String())
}

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

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

package main

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

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

func (in *CF1602A) 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 *CF1602A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1602A
Date: 21/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1602/A
Problem: CF1602A
**/
func (in *CF1602A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		arr := make([]int, len(str))
		for i := 0; i < len(str); i++ {
			arr[i] = int(str[i])
		}
		sort.Ints(arr)

		fmt.Print(string(arr[0]), " ")

		found := false
		for i := 0; i < len(str); i++ {
			if str[i] == uint8(arr[0]) && !found {
				found = true
				continue
			} else {
				fmt.Print(string(str[i]))
			}
		}
		fmt.Println()
	}
}

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

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

package main

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

var s string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		solve()

		fmt.Println()
	}
}

func solve() {

	var min byte = 'z'
	var minidx int

	for i := 0; i < len(s); i++ {
		if s[i] - 'a' < min - 'a' {
			min = s[i]
			minidx = i
		}
	}

	fmt.Print(string(min))
	fmt.Print(" ")
	if minidx == 0 {
		fmt.Print(s[1 :])
	} else if minidx == len(s) - 1 {
		fmt.Print(s[ : len(s) - 1])
	} else {
		fmt.Print(s[0 : minidx] + s[minidx + 1 :])
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
)

func solve(s []byte) string {
	var (
		a byte
		b []byte
		m = make(map[byte]int)
		r = len(s)
	)
	for i := 0; i < r; i++ {
		if m[s[i]] == 0 {
			m[s[i]] = i + 1
		}
	}
	for i := byte('a'); i <= 'z'; i++ {
		if m[i] > 0 {
			a = i
			b = append(s[:m[i]-1], s[m[i]:]...)
			break
		}
	}
	return fmt.Sprintf("%c %s", a, b)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var s []byte
		fmt.Fscan(reader, &s)
		fmt.Println(solve(s))
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

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

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var s string
    fmt.Fscan(input, &s)
    pos := 0
    for i := 0; i < len(s); i++ {
        if s[pos] > s[i] {
            pos = i
        }
    }
    fmt.Fprint(output, string(s[pos]), " ")
    for i := 0; i < len(s); i++ {
        if i != pos {
            fmt.Fprint(output, string(s[i]))
        }
    }
    fmt.Fprintln(output)
    output.Flush()
}

func abs(x int64) int64 {
    if x >= 0 { return x}
    return -x
}

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

package main

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

/*
5
fc
aaaa
thebrightboiler
ab
ba
---
c f
a aaa
b therightboiler
a b
a b
*/

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

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var s string
		scanf("%s\n", &s)

		chars := make([]pair, 0)

		for i, ch := range s {
			chars = append(chars, pair{ch, i})
		}

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

		a := string(chars[0].fst)

		var b string

		idx := chars[0].snd
		b = s[0:idx] + s[idx+1:]

		fmt.Fprintf(&bld, "%s %s\n", a, b)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

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

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

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

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

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

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

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

func Ans(ARR []int) {
	if len(ARR) < 2 {
		return
	}
	if len(ARR) == 2 {
		fmt.Println(ARR[1])
		fmt.Println(-ARR[0])
	} else {
		if len(ARR) == 3 {
			first := ARR[0]
			Midd := ARR[1]
			Last := ARR[2]
			var F, M, L int
			Pos := 0
			Neg := 0
			if first > 0 {
				Pos++
			} else {
				Neg++
			}
			if Midd > 0 {
				Pos++
			} else {
				Neg++
			}
			if Last > 0 {
				Pos++
			} else {
				Neg++
			}
			if Pos*Neg != 0 {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					if first == Midd {
						if Midd == Last {
							F = -1
							M = -1
							L = 2
						} else {
							F = 1
							M = 1
							L = 2
						}
					} else {
						if first == Last {
							F = 1
							L = 1
							M = 2
						} else {
							M = 1
							L = 1
							F = 2
						}
					}
				} else {
					One := first + Midd
					Two := Midd + Last
					Thr := first + Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = Last
						M = Last
						L = -One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = -Two
						M = first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = Midd
						M = -Thr
						L = Midd
					}

				}
			} else {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					F = -1
					M = -1
					L = 2
				} else {
					One := first - Midd
					Two := Midd - Last
					Thr := first - Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = -Last
						M = Last
						L = One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = Two
						M = -first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = -Midd
						M = Thr
						L = Midd
					}

				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)
		} else {
			Q := make([]int, 0)
			P := make([]int, 0)
			P = append(P, ARR[0], ARR[1])
			p := len(ARR)
			for i := 2; i < p; i++ {
				Q = append(Q, ARR[i])
			}
			Ans(P)
			Ans(Q)
		}
	}
}

var t int

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

	for o := 0; o < t; o++ {
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		k := len(STRING)
		ARR := make([]int, 0)
		for i := 0; i < k; i++ {
			ARR = append(ARR, int(STRING[i]))
		}

		sort.Ints(ARR)

		for i := 0; i < k; i++ {
			if int(STRING[i]) == ARR[0] {
				fmt.Println(string(STRING[i]))
				ans := string(STRING[:i]) + string(STRING[i+1:])

				fmt.Println(ans)
				break
			}
		}
	}

}


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 scanws(a ...interface{})           { fmt.Fscan(reader, a...) }

func main() {

	defer writer.Flush()
	var tc int
	var s string
	var ch []byte
	var ans int
	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&s)
		ans = 1
		n := len(s)
		ch = nil
		for i := 0; i < n; i++ {
			nn := len(ch)
			flag := true
			for j := 0; j < nn; j++ {
				if byte(s[i]) == ch[j] {
					flag = false
				}
			}
			if flag == true {
				if nn == 3 {
					ans++
					ch = nil
				}
				ch = append(ch, s[i])
			}
		}
		printf("%d\n", ans)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		if len(mem) > 3 {
			i--
		}

		res++
	}

	return res
}

package main

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

var maxSize int

func init() {
	maxSize = 2 * int(math.Pow(10, 5)) + 3
}

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

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

	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()

		c := 0
		uniq := make(map[rune]struct{}, 3)

		for _, r := range t {
			uniq[r] = struct{}{}

			if len(uniq) > 3 {
				c++
				uniq = map[rune]struct{}{r: {}}
			}
		}

		if len(uniq) > 0 {
			c++
		}

		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	m := make(map[byte]struct{})
	for t > 0 {
		var s string
		fmt.Scan(&s)
		var cnt, ans int
		for i := range s {
			if _, ok := m[s[i]]; !ok {
				cnt++
				if cnt > 3 {
					cnt = 1
					ans++
					m = make(map[byte]struct{})
				}
				m[s[i]] = struct{}{}
			}
		}
		if cnt > 0 {
			ans += 1
		}
		fmt.Println(ans)
		t--
		m = make(map[byte]struct{})
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var str string
	fmt.Fscan(in, &str)
	var ans int

	for i := 0; i < len(str); i++ {
		ans++
		mp := make(map[byte]bool)
		mp[str[i]] = true
		for i+1 < len(str) {
			if len(mp) == 3 && !mp[str[i+1]] {
				break
			}
			mp[str[i+1]] = true
			i++
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, os.Stdout)
		t--
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		var days int
		for j:=0;j<len(word);j++{
			days++
			mapper:= make(map[string]bool)
			counter:=0
			for k:=j;k<len(word);k++{
				if mapper[string(word[k])] == true {
					continue
				}
				mapper[string(word[k])] = true
				counter++
				if counter > 3 {
					j=(k-1)
					goto out
				}
			}
			break
			out:
		}
		fmt.Fprintln(out,days)
	}
}

package main

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

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

	numCases := 0
	fmt.Fscan(in, &numCases)

	for ; numCases > 0; numCases-- {
		str := ""
		fmt.Fscan(in, &str)
		uniq := make(map[rune]struct{}, 3)
		daysCnt := 0
		for _, r := range str {
			_, ok := uniq[r]
			if !ok {
				if len(uniq) == 3 {
					daysCnt++
					uniq = map[rune]struct{}{}
				}
				uniq[r] = struct{}{}
			}
		}
		if len(uniq) > 0 {
			daysCnt++
		}
		fmt.Fprintln(out, daysCnt)
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) int {
	var result = 1
	var charInDay = make(map[rune]bool)
	for _, x := range s {
		charInDay[x] = true
		if len(charInDay) == 4 {
			result++
			charInDay = make(map[rune]bool)
			charInDay[x] = true
		}
	}
	return result
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &s)
		fmt.Println(solve(s))
	}
}

package main

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

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 solve() {
	var s string
	scan(&s)
  r := 0
  // a := []int{}
  m := map[int]bool{}
  for _, c := range s{
    // fmt.Println(m)
    m[int(c)] = true
    if len(m) > 3{
      r += 1
      m = map[int]bool{
        int(c) : true,
      }
    }
  }
  if len(m) > 0{
    r += 1
  }
  printf("%d\n",r)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func main() {
	TC := new(int)
	fmt.Scan(TC)
	for (*TC) > 0 {
		var str string
		fmt.Scan(&str)
		hashmap := make(map[byte]bool)
		l := len(str)

		count := 0
		oscilator := 0

		for i := 0; i < l; i++ {
			if(!hashmap[str[i]]) {
//				hashmap[str[i]] = true;
//				count += 1
				if(oscilator >= 3 && !hashmap[str[i]]) {
					oscilator = 1
					count += 1
//					hashmap = nil
					hashmap = make(map[byte]bool)
				} else {
					oscilator += 1
				}
				hashmap[str[i]] = true
			}
		}
		if oscilator > 0 {
			count += 1
		}
		fmt.Println(count)
		*TC -= 1
	}
}

package main

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

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

func (in *CF1702B) 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 *CF1702B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1702B
Date: 16/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1702/B
Problem: CF1702B
**/
func (in *CF1702B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()

		ans := 1
		last := 0
		for last < len(str) {
			mapa := make(map[uint8]bool)
			for i := last; i < len(str); i++ {
				mapa[str[i]] = true
				if len(mapa) == 4 {
					ans++
					last = i
					break
				}
				if i + 1 == len(str){
					last = len(str)
				}
			}
		}

		fmt.Println(ans)
	}
}

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

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

package main

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

func Solve(s string) int {
	m := map[byte]bool{}
	l := len(s)
	ans := 0
	for i := 0; i < l; i++ {
		if _, ok := m[s[i]]; !ok {
			m[s[i]] = true
			if len(m) == 4 {
				m = map[byte]bool{}
				ans += 1
				m[s[i]] = true
			}
		}
	}
	if len(m) > 0 {
		ans += 1
	}
	return ans
}

func main(){

	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(cin, &s)
		fmt.Println(Solve(s))
	}

}

package main

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

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

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	ans := 0
	hash := make(map[byte]bool)
	for i:=0;i<=len(s);i++ {
		if i == len(s) || (len(hash) == 3 && !hash[s[i]]) {
			ans++
			hash = make(map[byte]bool)
		}
		if i == len(s) {
			break
		}
		hash[s[i]] = true
	}
	fmt.Fprintln(ww, ans)
}

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

package main

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

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

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

	var T int
	var x string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		ans := 0
		a := map[int32]bool{}
		for _, v := range x {
			if a[v] {
				continue
			}
			if len(a) < 3 {
				a[v] = true
			} else {
				ans++
				a = map[int32]bool{v: true}
			}
		}
		if len(a) > 0 {
			ans++
		}
		Fprintln(out, ans)

	}
}

package main

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

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

type Tint interface {
	int | int32 | int64
}

func min[T Tint](x, y T) T {
	if x <= y {
		return x
	}
	return y
}
func max[T Tint](x, y T) T {
	if x >= y {
		return x
	}
	return y
}
func main() {
	defer _w.Flush()

	var _t int
	// n = 1
	fmt.Fscan(_r, &_t)
	for ; _t > 0; _t-- {
		var s string
		fmt.Fscan(_r, &s)
		mp := make(map[uint8]bool)
		ans := 0
		for i := 0; i < len(s); i++ {
			ans++
			for ; i < len(s); i++ {
				if _, ok := mp[s[i]]; !ok {
					if len(mp) >= 3 {
						i--
						mp = make(map[uint8]bool, 0)
						break
					}
					mp[s[i]] = true
				}
			}
		}
		fmt.Fprintln(_w, ans)
	}
}

package main

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

func toi(s string) int64 {
  x, _ := strconv.ParseInt(s, 10, 64)
  return x
}

func tos(i int64) string {
  return strconv.FormatInt(i, 10)
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  sc.Scan()
  s := []rune(sc.Text())
  counter := int64(0)
  for len(s) != 0 {
    a := map[rune]struct{}{}
    i := 0
    for i < len(s) && len(a) < 4 {
      a[s[i]] = struct{}{}
      i++
    }
    if i != len(s) || len(a) > 3 {
      i--
    }
    s = s[i:]
    counter++
  }
  wr.WriteString(tos(counter))
  wr.WriteRune('\n')
}

const (
  once = false
  maxBufSize = 10000000
)

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

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    sc.Scan()
    times, _ := strconv.Atoi(sc.Text())
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

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 s string
		fmt.Fscan(in, &s)

		var tot int
		aa := make([]int, 26)
		var c int
		for i := 0; i < len(s); i++ {
			if aa[s[i]-'a'] == 0 {
				aa[s[i]-'a']++
				c++
				if c == 1 {
					tot++
				} else if c == 4 {
					i--
					c = 0
					aa = make([]int, 26)
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var s string
		fmt.Fscan(r, &s)
		w1 := do(s)
		fmt.Fprintln(w, w1)
	}
}

func do(s string) int {
	var m map[rune]struct{}
	a := 0
	for _, c := range s {
		if _, ok := m[c]; ok {
			continue
		}
		if len(m) == 0 || len(m) == 3 {
			a++
			m = make(map[rune]struct{})
		}
		m[c] = struct{}{}
	}
	return a
}

package main

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

func A0() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var s string
		Fscan(in, &s)
		var i int
		var cnt int
		for i < len(s) {
			m := map[byte]int{}
			cnt++
			for i < len(s) && len(m) <= 3 {
				m[s[i]]++
				i++
			}
			if len(m) > 3 {
				i--
			}
		}
		Fprintln(out, cnt)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A0() }

// 1702B. Polycarp Writes a String from Memory
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		m := make(map[byte]int)
		ans := 0
		for i := 0; i < len(s); i++ {
			m[s[i]]++
			if len(m) == 4 {
				ans++
				m = make(map[byte]int)
				m[s[i]]++
			}
		}
		if len(m) > 0 {
			ans++
		}
		fmt.Println(ans)

	}
}

package main

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

func solve(str string) int {
	day := 0
	i := 0

	for {
		day += 1
		cache := map[byte]bool{}

		for {
			if i == len(str) {
				break
			}

			ch := str[i]
			if _, ok := cache[ch]; ok {
				i++
				continue
			}

			if len(cache) == 3 {
				break
			} else {
				cache[ch] = true
				i++
				continue
			}
		}

		if i == len(str) {
			break
		}
	}

	return day
}

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

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

	for test > 0 {
		test--

		var str string
		fmt.Fscanln(inp, &str)

		res := solve(str)

		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		if len(mem) > 3 {
			i--
		}

		res++
	}

	return res
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		res++
		if len(mem) > 3 {
			i--
		}
	}

	return res
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2<<4), 2*int(math.Pow(10, 5)))
	scanner.Scan()

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

	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()

		c := 0
		uniq := make(map[rune]struct{})

		for _, r := range t {
			uniq[r] = struct{}{}

			if len(uniq) > 3 {
				c++
				uniq = map[rune]struct{}{r: {}}
			}
		}

		if len(uniq) > 0 {
			c++
		}

		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	m := make(map[byte]struct{})
	for t > 0 {
		var s string
		fmt.Scan(&s)
		var cnt, ans int
		for i := range s {
			if _, ok := m[s[i]]; !ok {
				cnt++
				if cnt > 3 {
					cnt = 1
					ans++
					m = make(map[byte]struct{})
				}
				m[s[i]] = struct{}{}
			}
		}
		if cnt > 0 {
			ans += 1
		}
		fmt.Println(ans)
		t--
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var str string
	fmt.Fscan(in, &str)
	var ans int

	for i := 0; i < len(str); i++ {
		ans++
		mp := make(map[byte]bool)
		mp[str[i]] = true
		for i+1 < len(str) {
			if len(mp) == 3 && !mp[str[i+1]] {
				break
			}
			mp[str[i+1]] = true
			i++
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	f, _ := os.Create("out.txt")
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, f)
		t--
	}
}