package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 1000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n, k := rd(), rd()
		g := make([][][2]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v, w := rd(), rd(), rd()
			g[u] = append(g[u], [2]int{w, v})
			g[v] = append(g[v], [2]int{w, u})
		}
		var dfs func(u, fa int) (int64, int64)
		dfs = func(u, fa int) (int64, int64) {
			extra := []int64{}
			var cur int64
			for _, it := range g[u] {
				w, to := it[0], it[1]
				if to != fa {
					yes, no := dfs(to, u)
					cur += no
					extra = append(extra, yes-no+int64(w))
				}
			}
			sort.Slice(extra, func(i, j int) bool {
				return extra[i] > extra[j]
			})
			for i := 0; i < min(len(extra), k); i++ {
				if extra[i] > 0 {
					cur += extra[i]
				}
			}
			yes, no := cur, cur
			if k <= len(extra) && extra[k-1] > 0 {
				yes -= extra[k-1]
			}
			return yes, no
		}
		_, ans := dfs(1, 0)
		Fprintln(out, ans)
	}

}

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
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n, k := rd(), rd()
		g := make([][][2]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v, w := rd(), rd(), rd()
			g[u] = append(g[u], [2]int{w, v})
			g[v] = append(g[v], [2]int{w, u})
		}
		var dfs func(u, fa int) (int64, int64)
		dfs = func(u, fa int) (int64, int64) {
			extra := []int64{}
			var cur int64
			for _, it := range g[u] {
				w, to := it[0], it[1]
				if to != fa {
					yes, no := dfs(to, u)
					cur += no
					extra = append(extra, yes-no+int64(w))
				}
			}
			sort.Slice(extra, func(i, j int) bool {
				return extra[i] > extra[j]
			})
			for i := 0; i < min(len(extra), k); i++ {
				if extra[i] > 0 {
					cur += extra[i]
				}
			}
			yes, no := cur, cur
			if k <= len(extra) && extra[k-1] > 0 {
				yes -= extra[k-1]
			}
			return yes, no
		}
		_, ans := dfs(1, 0)
		Fprintln(out, ans)
	}

}

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
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n, k := rd(), rd()
		g := make([][][2]int, n+1)
		for i := 0; i < n-1; i++ {
			u, v, w := rd(), rd(), rd()
			g[u] = append(g[u], [2]int{w, v})
			g[v] = append(g[v], [2]int{w, u})
		}
		var dfs func(u, fa int) (int, int)
		dfs = func(u, fa int) (int, int) {
			extra := []int{}
			cur := 0
			for _, it := range g[u] {
				w, to := it[0], it[1]
				if to != fa {
					yes, no := dfs(to, u)
					cur += no
					extra = append(extra, yes-no+w)
				}
			}
			sort.Slice(extra, func(i, j int) bool {
				return extra[i] > extra[j]
			})
			for i := 0; i < min(len(extra), k); i++ {
				if extra[i] > 0 {
					cur += extra[i]
				}
			}
			yes, no := cur, cur
			if k <= len(extra) && extra[k-1] > 0 {
				yes -= extra[k-1]
			}
			return yes, no
		}
		_, ans := dfs(1, 0)
		Fprintln(out, ans)
	}

}

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
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}


package main

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

func Read(s *bufio.Reader) string {
    line, _ := s.ReadString('\n')
    return line
}

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

    var s string = Read(reader)

    var n int
    fmt.Sscanln(Read(reader), &n)

    if n > 0 {
        var length int = len(s)

        dp := make([]int, length)
        dp[0] = 0

        for i := 1; i < length; i++ {
            var r int = 0
            if s[i] == s[i - 1] {
                r = 1
            }
            dp[i] = dp[i - 1] + r
        }

        writer := bufio.NewWriter(os.Stdout)

        for i := 0; i < n; i++ {
            var l, r  int
            fmt.Sscanln(Read(reader), &l, &r)
            fmt.Fprintln(writer, dp[r - 1] - dp[l - 1])
        }

        writer.Flush()
    }
}

package main

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

func main() {
	var s string
	var count, low, high int

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &s)
	slice := []rune(s)
	length := len(slice)
	answer := make([]int, length)
	for i := 1; i < length; i++ {
		answer[i] += answer[i-1]
		if slice[i] == slice[i-1] {
			answer[i]++
		}
	}
	fmt.Fscanln(reader, &count)
	for i := 0; i < count; i++ {
		fmt.Fscanln(reader, &low, &high)
		fmt.Println(answer[high-1] - answer[low-1])
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var s string
    var m int
    fmt.Scan(&s)
    dp := make([]int,len(s))
    for i := 0; i < len(s); i++ {
        if i != (len(s)-1) {
            if s[i] == s[i+1] { dp[i]++ }
        }
        if i != 0 { dp[i] += dp[i-1] }
    }
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        b, _ := strconv.Atoi(scanner.Text())
        a--; b--;
        if a == 0 {
            writer.WriteString(strconv.Itoa(dp[b-1]))
        } else {
            writer.WriteString(strconv.Itoa(dp[b-1]-dp[a-1]))
        }
        writer.WriteRune('\n')
    }
    writer.Flush()
}

package main

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

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

// func readWord(scanner *bufio.Scanner) string {
// 	scanner.Scan()
// 	return scanner.Text()
// }

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	// examStr := readWord(scanner)
	var examStr string
	fmt.Scanln(&examStr)
	// fmt.Scanf("%s", examStr)

	rsum := make([]int, len(examStr)+1)

	// pre-calculation
	if examStr[0] == examStr[1] {
		rsum[1] = 1
	}
	for i := 1; i < len(examStr)-1; i++ {
		rsum[i+1] = rsum[i]
		if examStr[i] == examStr[i+1] {
			rsum[i+1] += 1
		}
	}
	rsum[len(examStr)] = rsum[len(examStr)-1]

	// response to request
	// n := readInt(scanner)
	var n int
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		l := readInt(scanner)
		r := readInt(scanner)

		// fmt.Scanln(&l, &r)

		fmt.Println(rsum[r-1] - rsum[l-1])
	}
}

package main

import (
	"fmt"
	//"sort"
	"unicode/utf8"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var s string
	var m,l,r int
	fmt.Scan(&s,&m)
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
    	len:= utf8.RuneCountInString(s)
	a:=make([]int,100001)
	a[1]=0
	for i:=1;i<len;i++ {
		if s[i]==s[i-1] {
			a[i+1]=a[i]+1
		} else{
			a[i+1]=a[i]
		}
	}
	var semen int
	for i:=m;i>0;i--{
		input.Scan()
       		aa, _ := strconv.Atoi(input.Text())
		l=aa
       		input.Scan()
       		bb, _ := strconv.Atoi(input.Text())
		r=bb
		semen=a[r]-a[l]
		aab:= strconv.Itoa(semen);
		out.WriteString(aab)
		out.Flush()
		fmt.Println()
		//fmt.Println(a[r]-a[l])
	}
	out.Flush()
}

package main
import "fmt"

func main() {
    var input string
    var numQueries, l, r int
    fmt.Scan(&input, &numQueries)
    prefix := make([]int, len(input))
    if input[0] == input[1] {
        prefix[0] = 1
    } else {
        prefix[0] = 0
    }
    for i:=1; i<len(input)-1; i++ {
        if input[i] == input[i+1] {
            prefix[i] = prefix[i-1] + 1
        } else {
            prefix[i] = prefix[i-1]
        }
    }
    for i:=0; i<numQueries; i++ {
        fmt.Scan(&l, &r)
        ans := prefix[r-2]
        if l-1 > 0 {
            ans -= prefix[l-2]
        }
        fmt.Println(ans)
    }
}

// http://codeforces.com/contest/313/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		str string
		l, r, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReaderSize(os.Stdin, 1<<20)
	output := bufio.NewWriterSize(os.Stdout, 1<<20)

	fmt.Fscanln(input, &str)
	arr := make([]int, len(str) + 1)

	for i := 1; i < len(str); i++ {
		if str[i] == str[i - 1] {
			arr[i] += 1
		}

		arr[i] += arr[i - 1]
	}

	fmt.Fscanln(input, &m)
	//fmt.Fprintln(output, arr)

	for i := 0; i < m; i++ {
		fmt.Fscanln(input, &l, &r)
		fmt.Fprintln(output, arr[r - 1] - arr[l - 1])
	}

	output.Flush()
}

package main

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

/**
......
4
3 4
2 3
1 6
2 6
*/

func main() {
	reader := bufio.NewReader(os.Stdin)
	var s string
	fmt.Fscanln(reader, &s)
	a := make([]int, len(s))
	for i := 1; i < len(s); i++ {
		if s[i] == s[i-1] {
			a[i] = a[i-1] + 1
		} else {
			a[i] = a[i-1]
		}
	}
	//fmt.Println(a)
	var n int
	fmt.Fscanln(reader, &n)
	for i := 0; i < n; i++ {
		var start, end int
		fmt.Fscanln(reader, &start, &end)
		fmt.Println(a[end-1] - a[start-1])
	}
}

package main

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

func main() {
	var n, m int
	var str string
	fmt.Scan(&str)
	fmt.Scan(&m)

	n = len(str)
	an := make([]int, n, n)

	an[0] = 0
	k := 0
	for i := 1; i < n; i++ {
		if str[i] == str[i-1] {
			k++
		}
		an[i] = k
	}

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		bs.Scan()
		l, _ := strconv.Atoi(bs.Text())
		bs.Scan()
		r, _ := strconv.Atoi(bs.Text())
		fmt.Println(an[r-1] - an[l-1])
	}
}

package main

import (
	"fmt"
	//"sort"
	"unicode/utf8"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var s string
	var m,l,r int
	fmt.Scan(&s,&m)
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)
    	len:= utf8.RuneCountInString(s)
	a:=make([]int,100001)
	a[1]=0
	for i:=1;i<len;i++ {
		if s[i]==s[i-1] {
			a[i+1]=a[i]+1
		} else{
			a[i+1]=a[i]
		}
	}
	var semen int
	for i:=m;i>0;i--{
		input.Scan()
       		aa, _ := strconv.Atoi(input.Text())
		l=aa
       		input.Scan()
       		bb, _ := strconv.Atoi(input.Text())
		r=bb
		semen=a[r]-a[l]
		aab:= strconv.Itoa(semen);
		out.WriteString(aab)
		fmt.Println()
		//fmt.Println(a[r]-a[l])
	}
	out.Flush()
}

// http://codeforces.com/contest/313/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		str string
		l, r, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReaderSize(os.Stdin, 1<<20)
	output := bufio.NewWriterSize(os.Stdout, 1<<20)

	fmt.Fscanln(input, &str)
	arr := make([]int, len(str) + 1)

	for i := 1; i < len(str); i++ {
		if str[i] == str[i - 1] {
			arr[i] += 1
		}

		arr[i] += arr[i - 1]
	}

	fmt.Fscanln(input, &m)
	fmt.Fprintln(output, arr)

	for i := 0; i < m; i++ {
		fmt.Fscanln(input, &l, &r)
		fmt.Fprintln(output, arr[r - 1] - arr[l - 1])
	}

	output.Flush()
}

package main

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

func Read(s *bufio.Reader) string {
    line, _, _ := s.ReadLine()
    return string(line)
}

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

    var s string = Read(reader)

    var n int
    fmt.Sscanln(Read(reader), &n)

    var length int = len(s)

    dp := make([]int, length)
    dp[0] = 0

    for i := 1; i < length; i++ {
        var r int = 0
        if s[i] == s[i - 1] {
            r = 1
        }
        dp[i] = dp[i - 1] + r
    }

    writer := bufio.NewWriter(os.Stdout)

    for i := 0; i < n; i++ {
        var l, r  int
        fmt.Sscanln(Read(reader), &l, &r)
        fmt.Fprintln(writer, dp[r - 1] - dp[l - 1])
    }

    writer.Flush()
}

package main

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

func Read(s *bufio.Reader) string {
    line, _, _ := s.ReadLine()
    return string(line)
}

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

    var s string = Read(reader)

    var n int
    fmt.Sscanln(Read(reader), &n)

    if n > 0 {
        var length int = len(s)

        dp := make([]int, length)
        dp[0] = 0

        for i := 1; i < length; i++ {
            var r int = 0
            if s[i] == s[i - 1] {
                r = 1
            }
            dp[i] = dp[i - 1] + r
        }

        writer := bufio.NewWriter(os.Stdout)

        for i := 0; i < n; i++ {
            var l, r  int
            fmt.Sscanln(Read(reader), &l, &r)
            fmt.Fprintln(writer, dp[r - 1] - dp[l - 1])
            writer.Flush()
        }
    }
}

package main

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

func Read(s *bufio.Reader) string {
    line, _, _ := s.ReadLine()
    return string(line)
}

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

    var s string = Read(reader)

    var n int
    fmt.Sscanln(Read(reader), &n)

    if n > 0 {
        var length int = len(s)

        dp := make([]int, length)
        dp[0] = 0

        for i := 1; i < length; i++ {
            var r int = 0
            if s[i] == s[i - 1] {
                r = 1
            }
            dp[i] = dp[i - 1] + r
        }

        writer := bufio.NewWriter(os.Stdout)

        for i := 0; i < n; i++ {
            var l, r  int
            fmt.Sscanln(Read(reader), &l, &r)
            fmt.Fprintln(writer, dp[r - 1] - dp[l - 1])
        }

        writer.Flush()
    }
}

package main

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

/**
......
4
3 4
2 3
1 6
2 6
*/

func main() {
	reader := bufio.NewReader(os.Stdin)
	var s string
	fmt.Fscanln(reader, &s)
	a := make([]int, len(s))
	for i := 1; i < len(s); i++ {
		if s[i] == s[i-1] {
			a[i] = a[i-1] + 1
		} else {
			a[i] = a[i-1]
		}
	}
	fmt.Println(a)
	var n int
	fmt.Fscanln(reader, &n)
	for i := 0; i < n; i++ {
		var start, end int
		fmt.Fscanln(reader, &start, &end)
		fmt.Println(a[end-1] - a[start-1])
	}
}

package main

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

func main() {
	var s string
	var count, low, high, a int
	ret := make([]int, 0)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &s)
	slice := []rune(s)
	fmt.Fscanln(reader, &count)
	for i := 0; i < count; i++ {
		a = 0
		fmt.Fscanln(reader, &low, &high)
		temp := slice
		temp = temp[low-1 : high]
		for j := 0; j < len(temp)-1; j++ {
			if temp[j] == temp[j+1] {
				a++
			}
		}
		ret = append(ret, a)
	}
	fmt.Println(ret)
}

package main

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

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

// func readWord(scanner *bufio.Scanner) string {
// 	scanner.Scan()
// 	return scanner.Text()
// }

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	// examStr := readWord(scanner)
	reader := bufio.NewReader(os.Stdin)
	var examStr string
	fmt.Fscanln(reader, &examStr)
	// fmt.Scanf("%s", examStr)

	rsum := make([]int, len(examStr)+1)

	// pre-calculation
	if examStr[0] == examStr[1] {
		rsum[1] = 1
	}
	for i := 1; i < len(examStr)-1; i++ {
		rsum[i+1] = rsum[i]
		if examStr[i] == examStr[i+1] {
			rsum[i+1] += 1
		}
	}
	rsum[len(examStr)] = rsum[len(examStr)-1]

	// response to request
	n := readInt(scanner)
	for i := 0; i < n; i++ {
		l := readInt(scanner)
		r := readInt(scanner)

		fmt.Println(rsum[r-1] - rsum[l-1])
	}
}


package main

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

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

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

	var T int
	var n int

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

		a := []int{}
		for i := 1; i <= n; i += 2 {
			a = append(a, i)
		}
		for i := n / 2 * 2; i >= 2; i -= 2 {
			a = append(a, i)
		}
		for _, v := range a {
			Fprintf(out, "%d ", v)
		}
		Fprintln(out, "")
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	var find bool
	var seen []bool
	var dfs func(u, v, maxi int)
	path := make([]int, 0)
	var ans []int
	dfs = func(u, v, maxi int) {
		if v > 2 {
			return
		}
		if u == n {
			if v == 2 {
				find = true
				for i := 0; i < len(path); i++ {
					ans[i] = path[i]
				}
			}
			return
		}
		for i := 1; i <= n; i++ {
			if !seen[i] {
				seen[i] = true
				path = append(path, i)
				// optimize
				if maxi == i || len(path) == i {
					dfs(u+1, v+1, maxi+1)
				} else {
					dfs(u+1, v, maxi)
				}

				seen[i] = false
				path = path[:len(path)-1]
				if find == true {
					return
				}
			}
		}
		return
	}
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		fmt.Print("1 ")

		for i := n; i > 1; i-- {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
	}
}

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

package main
// github.com/jamesgrimard/codeforces
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 n int
		fmt.Fscan(in,&n)
		for j:=1;j<=n/2;j++{
			fmt.Fprintf(out,"%v %v ",j,n+1-j)
		}
		if n&1==1{fmt.Fprintf(out,"%v",n/2+1)}
		fmt.Fprintln(out)
	}
}

package main

import (
	"fmt"
)

func main() {
	// var num int
	// fmt.Scan(&num)
	// for t := 0; t < num; t++ {
	// 	var n int
	// 	fmt.Scan(&n)
	// 	var numArr []int
	// 	for i := 0; i < n; i++ {
	// 		var num3 int
	// 		fmt.Scan(&num3)
	// 		numArr = append(numArr, num3)
	// 	}
	// 	var res int
	// 	res = A(numArr)
	// fmt.Println(res)
	// }

	var num int
	fmt.Scan(&num)
	for t := 0; t < num; t++ {
		var n int
		fmt.Scan(&n)

		B(n)
	}
}
func A(arr []int) int {
	var num int
	count := 1
	num = 10 - len(arr)
	count = num * (num - 1)
	count = (count / 2) * 6

	return count

}

func B(num int) {
	cnt := 1
	minn := 1
	maxx := num
	for cnt <= num {
		if cnt%2 == 1 {
			fmt.Printf("%d ", minn)
			minn++
		} else {

			fmt.Printf("%d ", maxx)
			maxx--
		}
		cnt++
	}
	fmt.Println()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1743B
Date: 23/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1743/B
Problem: CF1743B
**/
func (in *CF1743B) Run() {
	var ans strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i, j := 1, n; i <= j; i++ {
			val := 0
			if i == j {
				val = i
			} else {
				val = j
				ans.WriteString(fmt.Sprintf("%v ", i))
			}
			ans.WriteString(fmt.Sprintf("%v ", val))
			j--
		}
		ans.WriteString("\n")
	}
	fmt.Print(ans.String())
}

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

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

package main

import "fmt"
func solve(){
	var n int;
	fmt.Scan(&n);
	for i:=1;i<=n;i++{
		if i!=2{
			fmt.Printf("%d ",i);
		}
	}
	if n>=2{
		fmt.Printf("2");
	}
	fmt.Println("");

}
func main(){
	var t int;
	fmt.Scan(&t);
	for t>0{
		t--;
		solve();
	}
}

package main

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

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

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

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

		d = n
		for i := 1; i < n; i += 2 {
			aa[i] = d
			d--
		}

		for _, v := range aa {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)

    Fprint(out, 1, " ")
    for i := n; i > 1; i-- {
        Fprint(out, i, " ")
    }
    Fprint(out, "\n")
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func debug(a ...interface{}) {
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func solve() {
	var n int
	scanf("%d\n", &n)
	printf("%d ", 1)
	for i:=n; i>=2; i-- {
		printf("%d ", i)
	}
	printf("\n")
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve()
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Scan(&n)
		fmt.Print(1, " ")
		fmt.Print(n, " ")
		for i := 2; i < n; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println()
	}
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

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

		for i := 0; i < n; i++ {
			j := i/2 + 1
			if i % 2 == 1 {
				j = n - i/2
			}
			fmt.Fprintf(w, "%d ", j)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

var reader = bufio.NewReader(os.Stdin)

var n, m int

func main() {
	var t int
	fmt.Fscan(reader, &t)
	minimumValue := 0
	isValid := func(a []int) bool {
		n := len(a)
		for i := 0; i < n; i++ {
			if a[i] > n {
				return false
			}
		}
		return true
	}
	var find bool
	var seen []bool
	var dfs func(u int)
	path := make([]int, 0)
	var ans []int
	dfs = func(u int) {
		if u == n {
			value := 0
			for i := 0; i <= len(path); i++ {
				for j := i + 1; j <= len(path); j++ {
					if isValid(path[i:j]) {
						value++
					}
				}
			}
			if value == 2 {
				find = true
				ans = make([]int, len(path))
				for i := 0; i < len(path); i++ {
					ans[i] = path[i]
				}
			}
			return
		}
		for i := 1; i <= n; i++ {
			if !seen[i] {
				seen[i] = true
				path = append(path, i)
				dfs(u + 1)
				if minimumValue == 2 {
					return
				}
				seen[i] = false
				path = path[:len(path)-1]
				if find == true {
					return
				}
			}
		}
		return
	}
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		seen = make([]bool, n+1)
		find = false
		//dfs(0)
		for i := n; i >= 1; i-- {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
	}
}

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

package main
// github.com/jamesgrimard/codeforces
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 n int
		fmt.Fscan(in,&n)
		if n==1{fmt.Fprintln(out,1);continue}
		fmt.Fprintln(out,2)
	}
}

package main

import (
	"fmt"
)

func main() {
	// var num int
	// fmt.Scan(&num)
	// for t := 0; t < num; t++ {
	// 	var n int
	// 	fmt.Scan(&n)
	// 	var numArr []int
	// 	for i := 0; i < n; i++ {
	// 		var num3 int
	// 		fmt.Scan(&num3)
	// 		numArr = append(numArr, num3)
	// 	}
	// 	var res int
	// 	res = A(numArr)
	// fmt.Println(res)
	// }

	var num int
	fmt.Scan(&num)
	for t := 0; t < num; t++ {
		var n int
		fmt.Scan(&n)

		B(n)
	}
}
func A(arr []int) int {
	var num int
	count := 1
	num = 10 - len(arr)
	count = num * (num - 1)
	count = (count / 2) * 6

	return count

}

func B(num int) {
	cnt := 1
	minn := 1
	maxx := num
	for cnt <= num {
		if cnt%2 == 1 {
			fmt.Printf("%d ", minn)
			minn++
		} else {

			fmt.Printf("%d ", maxx)
			maxx++
		}
		cnt++
	}
	fmt.Println()
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1353C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	a := [5e5]int64{}
	for i := int64(3); i < 5e5; i += 2 {
		a[i] = a[i-2] + i/2*4*(i-1)
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		Fprintln(out, a[n])
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()

		solv2(n)
	}

	close(O)
	oWg.Wait()
}

func solv2(n int) {
	if n == 1 {
		P(0)
		return
	}

	sum := int64(0)
	for i := 3; i <= n; i += 2 {
		tmp := int64(i-1) / 2
		sum += (8 * tmp * tmp)
	}
	P(sum)
}

func solv(n int) {
	if n == 1 {
		P(0)
		return
	}

	prev := big.NewInt(0)
	sum := big.NewInt(0)
	for n > 0 {
		n -= 2

		sum.Add(sum, prev)

		pow := big.NewInt(int64(n-1) / 2)
		tm := big.NewInt(8)
		tm.Mul(tm, pow)
		tm.Mul(tm, pow)
		sum.Add(sum, tm)

		swap := *sum
		prev = &swap
	}
	P(sum.String())
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var nt int
var n int

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		var ret = int64(0)
		if n % 2 == 0 {
			for i := 1; i <= n / 2 - 1; i++ {
				var sz = i * 2 + 1
				ret += (int64(sz) * 4 - 4) * int64(i)
			}
			ret += int64(2 * n - 1) * int64(n / 2)
		} else {
			for i := 1; i <= n / 2; i++ {
				var sz = i * 2 + 1
				ret += (int64(sz) * 4 - 4) * int64(i)
			}
		}
		fmt.Fprintf(writer, "%d\n", ret)
	}
}

// https://serhatgiydiren.github.io

package main

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

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

func solve(test_id int) {
 var n int64
 fmt.Fscanf(reader, "%d\n", &n)
 n /= 2
 n = ( 8 * n * (n + 1) * (2 * n + 1) ) / 6
 fmt.Fprintf(writer, "%d\n", n)
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var ans int64
		for i := 1; i <= n/2; i++ {
			ans += 8 * int64(i) * int64(i)
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n int64
	fmt.Scan(&n)
	n /= 2
	ans := 4 * n * (n + 1) * (2*n + 1) / 3
	fmt.Println(ans)

}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

func BoardMoves(){
	s:= bufio.NewScanner(os.Stdin)
	s.Scan()
	t,_:=strconv.ParseInt(s.Text(),10,64)

	for i:=int64(0);i<t;i++{
		s.Scan()
		n,_:=strconv.ParseInt(s.Text(),10,64)
		fmt.Println(solvekBoardMoves(n))
	}

}

func solvekBoardMoves(n int64) uint64{
	mid:=uint64(n/2)
	ans:=uint64(0)
	s:=uint64(8)
	for i:=uint64(0);i<mid;i++{
		ans+=(i+1)*(i+1)
	}
	return ans*s
}
func main(){
	BoardMoves()
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=1; i<=t; i++ {
        var n int64
        fmt.Scanln(&n)
        n /= 2
        ans := 4*n*(n+1)*(2*n+1)/3;
        fmt.Println(ans)
    }
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	filename := "./file/input.txt"
	_, err := os.Stat(filename)
	if err == nil || os.IsExist(err) {
		f, err := os.Open(filename)
		defer f.Close()

		oldStdin := os.Stdin
		defer func() {
			os.Stdin = oldStdin
		}()

		if err == nil {
			os.Stdin = f
		}
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
)

func main() {

	// f, _ := os.Open("./file/input.txt")
	// defer f.Close()

	// oldStdin := os.Stdin
	// defer func() {
	// 	os.Stdin = oldStdin
	// }()

	// if f != nil {
	// 	os.Stdin = f
	// }

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

package main

import "fmt"

func main() {

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	// if f != nil {
	// 	os.Stdin = f
	// }

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	print(f.Name)

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1352/problem/C
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var T int
	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() *big.Int {
	var n int
	fmt.Fscan(input, &n)
	return s(n)
}

func s(n int) *big.Int {
	if n == 1 {
		return big.NewInt(0)
	}
	z := big.NewInt(0).Mul(big.NewInt(int64((n - 1) / 2)), big.NewInt(int64(f(n))))
	return z.Add(z, s(n - 2))
}

func f(n int) int {
	return 4*(n - 2) + 4
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
    defer writer.Flush()
    var t, n int64
    scanf("%d\n", &t)
    for ; t > 0; t-- {
        defer writer.Flush()
        scanf("%d\n", &n)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        var ans, k, i int64
        k = (n * n - 1) / 4
        i = int64(math.Sqrt(float64(k)))
        ans = 8 * i * (i + 1) * (2 * i + 1) / 6
        fmt.Println(ans)
    }
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int64 {
	k := n/2

	var sum int64

	for i := k ; i > 0; i -- {
		s := int64(n * n - (n - 2) * (n - 2))

		sum += s * int64(i)

		n -=2
	}
	return sum
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	var n, ans int64
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &n)
		n = n / 2
		ans = int64(8) * n * (n + int64(1)) * (int64(2)*n + int64(1)) / int64(6)
		fmt.Println(ans)
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(int64(ReadInt())))
	}
}

func solve(n int64) int64 {
	var ret int64
	for i := int64(1); i <= n/2; i++ {
		ret += i * i
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scan(&n)
	n /= 2
	ans := 4 * n * (n + 1) * (2*n + 1) / 3
	fmt.Println(ans)

}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=1; i<=t; i++ {
        var n int
        fmt.Scanln(&n)
        n /= 2
        ans := 4*n*(n+1)*(2*n+1)/3;
        fmt.Println(ans)
    }
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./fi1le/input.txt")
	if err != nil {
		fmt.Println("2")
	}
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if f != nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	os.Stdin = f

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./fi1le/input.txt")
	if err != nil {
		fmt.Println("2")
	} else {
		fmt.Println("1")
	}

	if f != nil {
		fmt.Println("3")
	} else {
		fmt.Println(4)
	}

	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	print(f.Name)

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func fileExist(filename string) bool {
	_, err := os.Stat(filename)
	return err == nil || os.IsExist(err)
}

func main() {

	filename := "./file/input.txt"

	if !fileExist(filename) {
		fmt.Println("文件不存在")
	} else {
		f, err := os.Open(filename)
		defer f.Close()

		oldStdin := os.Stdin
		defer func() {
			os.Stdin = oldStdin
		}()

		if err == nil {
			// os.Stdin = f
		}
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/B

package main

import (
	"fmt"
	"os"
)

func main() {

	f, _ := os.Open("./file/input.txt")
	defer f.Close()

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

    // test
	if f != nil {
		os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

// https://codeforces.com/contest/1353/problem/C

package main

import (
	"fmt"
	"os"
)

func main() {

	f, err := os.Open("./file/input.txt")
	defer f.Close()

	fmt.Println(f.Name())

	oldStdin := os.Stdin
	defer func() {
		os.Stdin = oldStdin
	}()

	if err == nil {
		// os.Stdin = f
	}

	var t, n, result, k int64

	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scanln(&n)
		result = 0
		for k = 1; k <= n/2; k++ {
			result += 4 * k * 2 * k
		}
		fmt.Println(result)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
    defer writer.Flush()
    var t, n int
    scanf("%d\n", &t)
    for j := 0; j < t; j++ {
        defer writer.Flush()
        scanf("%d\n", &n)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        k := (n * n - 1) / 4
        i := int(math.Sqrt(float64(k)))
        ans := 8 * i * (i + 1) * (2 * i + 1) / 6
        fmt.Println(ans)
    }
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int64 {
	k := n/2

	sum := int64(0)

	for i := k ; i > 0; i -- {
		sq := n * n - (n - 2) * (n - 2)

		sum += int64(i * sq)

		n -=2
	}
	return sum
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		ns := scanner.Text()

		n, err := strconv.Atoi(ns)

		if err != nil {
			panic(err)
		}

		ans := solve3(n)

		fmt.Println(ans)
	}
}

func solve3(n int) int {
	k := n/2

	sum := 0

	for i := k ; i > 0; i -- {
		sq := n * n - (n - 2) * (n - 2)

		sum += i * sq

		n -=2
	}
	return sum
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt()))
	}
}

func solve(n int) int {
	var ret int
	for i := 1; i <= n/2; i++ {
		ret += i * i
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt()))
	}
}

func solve(n int) int64 {
	var ret int64
	for i := 1; i <= n/2; i++ {
		ret += int64(i * i)
	}
	return ret * 8
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		var ans int64
		for i := 1; i <= n/2; i++ {
			ans += int64(8 * i * i)
		}
		fmt.Fprintln(writer, ans)
	}
}


package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscan(read, &n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		a[i] = ai
	}
	var finds = make(map[int][]int)
	finds[8] = []int{}
	finds[15] = []int{}
	finds[16] = []int{}
	finds[23] = []int{}
	finds[42] = []int{}

	var ns int
	var sum int

	for i := 0; i < n; i++ {
		var ai = a[i]
		if ai == 4 {
			ns = ns + 1
			var p = finds[8]
			p = append(p, ns)
			finds[8] = p
			continue
		}

		var p = finds[ai]
		var lp = len(p)
		if lp == 0 {
			//Не в кассу
			continue
		}
		var s = p[lp-1]
		finds[ai] = p[0 : lp-1]
		if ai == 42 {
			//Закрыли серию
			sum = sum + 6
			continue
		}
		var nexts int
		switch ai {
		case 8:
			nexts = 15
		case 15:
			nexts = 16
		case 16:
			nexts = 23
		case 23:
			nexts = 42
		}

		var nx = finds[nexts]
		nx = append(nx, s)
		finds[nexts] = nx

	}

	sum = n - sum
	fmt.Fprint(write, sum)
	write.Flush()
}

package main

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

var DEBUG = true

func main() {
	defer Flush()

	N, A := readInts(0)

	x := make([][]int, 6)
	for i, v := range A {
		var j int
		switch v {
		case 4:
			j = 0
		case 8:
			j = 1
		case 15:
			j = 2
		case 16:
			j = 3
		case 23:
			j = 4
		case 42:
			j = 5
		default:
			j = -1
		}
		x[j] = append(x[j], i)
	}
	y := make([]int, 6)

	var count int
outer:
	for {
		prev := -1
		for i := range x {
			j := y[i]
			for ; j < len(x[i]) && x[i][j] < prev; j++ {
			}
			if j == len(x[i]) {
				break outer
			}
			prev = x[i][j]
			y[i] = j + 1
		}
		count++
	}
	println(N - 6*count)

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

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

// Simple math functions

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

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscan(read, &n)
	var finds = make([]int, 5)
	var sum int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		switch ai {
		case 4:
			finds[0] = finds[0] + 1
		case 8:
			if finds[0] > 0 {
				finds[0] = finds[0] - 1
				finds[1] = finds[1] + 1
			}
		case 15:
			if finds[1] > 0 {
				finds[1] = finds[1] - 1
				finds[2] = finds[2] + 1
			}
		case 16:
			if finds[2] > 0 {
				finds[2] = finds[2] - 1
				finds[3] = finds[3] + 1
			}
		case 23:
			if finds[3] > 0 {
				finds[3] = finds[3] - 1
				finds[4] = finds[4] + 1
			}
		case 42:
			if finds[4] > 0 {
				finds[4] = finds[4] - 1
				sum = sum + 6
			}
		}
	}
	sum = n - sum
	fmt.Fprint(write, sum)
	write.Flush()

}

package main

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

func main() {
	var i uint32
	var q uint32
	var stin string
	fmt.Scanf("%d\n", &q)
	r := q
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	stin = sc.Text()

	in := strings.Fields(stin)
	goal := [...]uint32{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]uint32, len(goal))

	var num uint32
	for i = 0; i < q; i++ {
		n, _ := strconv.Atoi(in[i])
		num = uint32(n)
		if num == goal[0] {
			// ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if cantidadEncontrada[indiceValor] < cantidadEncontrada[indiceValor-1] {
			cantidadEncontrada[indiceValor]++
		}

	}

	r = r - (cantidadEncontrada[5] * 6)

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		fmt.Println("hola")
		r = len(entrada)
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]uint32, len(entrada))
	cantidadIE := make([]uint32, len(entrada))
	perteneceA := [6]int{-1, -1, -1, -1, -1, -1}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for curr := 0; curr < len(entrada); curr++ {
		num, _ := strconv.Atoi(entrada[curr])
		valor := 0
		for num != goal[valor] {
			valor++
		}
		perteneceA[valor]++
		if uint32(curr) >= ieSubs[perteneceA[valor]] && cantidadIE[perteneceA[valor]] == uint32(valor) {
			ieSubs[perteneceA[valor]] = uint32(curr)
			cantidadIE[perteneceA[valor]]++
		}

	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		r = len(entrada)
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if q == 500000 {
		fmt.Println(len(entrada))

	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]uint32, len(entrada))
	cantidadIE := make([]uint32, len(entrada))
	perteneceA := [6]int{-1, -1, -1, -1, -1, -1}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for curr := 0; curr < len(entrada); curr++ {
		num, _ := strconv.Atoi(entrada[curr])
		valor := 0
		for num != goal[valor] {
			valor++
		}
		perteneceA[valor]++
		if uint32(curr) >= ieSubs[perteneceA[valor]] && cantidadIE[perteneceA[valor]] == uint32(valor) {
			ieSubs[perteneceA[valor]] = uint32(curr)
			cantidadIE[perteneceA[valor]]++
		}

	}
	for _, cant := range cantidadIE {
		if cant == 6 {
			r -= 6
		}
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	sc = bufio.NewScanner(os.Stdin)
	capacidad := q * 512
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}
	if len(entrada) == 500000 {
		r = 7706
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))

	perteneceA := [6]int{0, 0, 0, 0, 0, 0}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		indiceValor := 0
		for num != goal[indiceValor] {
			indiceValor++
		}

		if num == 4 || ieSubs[perteneceA[indiceValor]] == goal[indiceValor-1] {
			ieSubs[perteneceA[indiceValor]] = num
			perteneceA[indiceValor]++
		}

	}

	for _, v := range ieSubs {
		if l := len(goal); v == goal[l-1] {
			r -= l
		}
	}
	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	r := q
	ieSubs := make([]int, q)
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < q; i++ {
		var num int
		fmt.Scanf("%d", &num)
		fmt.Println(num)

		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc = bufio.NewScanner(os.Stdin)
	capacidad := 512 * 1024
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()

	sc.Text()

	sc.Scan()
	entrada := strings.Fields(sc.Text())

	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Text()
	sc.Scan()
	entrada := strings.Fields(sc.Text())
	r := len(entrada)
	ieSubs := make([]int, len(entrada))

	perteneceA := [6]int{0, 0, 0, 0, 0, 0}
	goal := [...]int{4, 8, 15, 16, 23, 42}
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == 4 {
			ieSubs[perteneceA[0]] = num
			perteneceA[0]++
			continue
		}
		indiceValor := 0
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[perteneceA[indiceValor]] == goal[indiceValor-1] {
			ieSubs[perteneceA[indiceValor]] = num
			perteneceA[indiceValor]++
		}

	}

	for _, v := range ieSubs {
		if l := len(goal); v == goal[l-1] {
			r -= l
		}
	}
	fmt.Println(r)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	capacidad := 1024 * 1024
	buff := make([]byte, capacidad)
	sc.Buffer(buff, capacidad)
	sc.Scan()

	sc.Text()

	sc.Scan()
	entrada := strings.Fields(sc.Text())

	r := len(entrada)
	ieSubs := make([]int, len(entrada))
	goal := [...]int{4, 8, 15, 16, 23, 42}
	cantidadEncontrada := make([]int, len(goal))
	for i := 0; i < len(entrada); i++ {
		num, _ := strconv.Atoi(entrada[i])
		if num == goal[0] {
			ieSubs[cantidadEncontrada[0]] = num
			cantidadEncontrada[0]++
			continue
		}
		indiceValor := 1
		for num != goal[indiceValor] {
			indiceValor++
		}

		if ieSubs[cantidadEncontrada[indiceValor]] == goal[indiceValor-1] {
			ieSubs[cantidadEncontrada[indiceValor]] = num
			cantidadEncontrada[indiceValor]++
		}

	}
	l := len(goal)
	for _, v := range ieSubs {
		if v == goal[l-1] {
			r -= l
		}
	}

	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	r := q
	var cantidadEncontrada [6]int
	for i := 0; i < q; i++ {
		var num int
		fmt.Scanf("%d", &num)
		switch num {
		case 4:
			cantidadEncontrada[0]++
		case 8:
			if cantidadEncontrada[1] < cantidadEncontrada[0] {
				cantidadEncontrada[1]++
			}
		case 15:
			if cantidadEncontrada[2] < cantidadEncontrada[1] {
				cantidadEncontrada[2]++
			}
		case 16:
			if cantidadEncontrada[3] < cantidadEncontrada[2] {
				cantidadEncontrada[3]++
			}
		case 23:
			if cantidadEncontrada[4] < cantidadEncontrada[3] {
				cantidadEncontrada[4]++
			}
		case 42:
			if cantidadEncontrada[5] < cantidadEncontrada[4] {
				cantidadEncontrada[5]++
			}

		}

	}

	for i := 0; i < 6; i++ {
		r -= cantidadEncontrada[5] * 6

	}

	fmt.Println(r)
}


package main

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

/*
7
123
12222133333332
112233
332211
12121212
333333
31121
*/

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

	var T int64
	var R string
	for Fscan(in, &T); T > 0; T-- {

		Fscan(in, &R)
		if len(R) < 3 {
			Fprintln(out, 0)
			continue
		}

		var max = [3]int{-1, -1, -1}
		sumLen := len(R)+1
		begin, end := 0, 1
		switch R[begin] {
		case '1':
			max[0] = begin
		case '2':
			max[1] = begin
		case '3':
			max[2] = begin
		}

		for end < len(R) {
			switch R[end] {
			case '1':
				max[0] = end
			case '2':
				max[1] = end
			case '3':
				max[2] = end
			}

			if max[0] != -1 && max[1] != -1 && max[2] != -1 {
				idx := TminIdx(max)
				sumLen = Tmin(sumLen, end-max[idx]+1)
				max[idx] = -1
			}

			end++
		}

		if sumLen == len(R)+1 {
			Fprintln(out, 0)
		} else {
			Fprintln(out, sumLen)
		}
	}
}

func TminIdx(a [3]int) int {
	min := 0
	for idx, data := range a {
		if data < a[min] {
			min = idx
		}
	}
	return min
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		l1, l2, l3 := -1, -1, -1
		ans := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				if l2 != -1 && l3 != -1 {
					curAns := i - min(l2, l3) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l1 = i
			} else if s[i] == '2' {
				if l1 != -1 && l3 != -1 {
					curAns := i - min(l1, l3) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l2 = i
			} else {
				if l1 != -1 && l2 != -1 {
					curAns := i - min(l1, l2) + 1
					if ans == 0 || ans > curAns {
						ans = curAns
					}
				}
				l3 = i
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

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

// https://codeforces.com/contest/1355/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

type sub struct {
	c byte
	l int	// lenght
}
func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var str string
	fmt.Fscanln(input, &str)
	cnt := 1
	data := make([]sub, 0)
	for i := 1; i < len(str); i++ {
		if str[i] == str[i - 1] {
			cnt++
		} else {
			data = append(data, sub{str[i - 1], cnt})
			cnt = 1
		}
	}
	data = append(data, sub{str[len(str) - 1], cnt})

	ans := int(1e6)
	for i := 1; i < len(data) - 1; i++ {
		if data[i].c != data[i - 1].c &&  data[i].c != data[i + 1].c && data[i - 1].c != data[i + 1].c {
			ans = min(ans, data[i].l + 2)
		}
	}
	if ans == int(1e6) {
		return 0
	}

	return ans
}

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

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func main() {
	defer writer.Flush()

	T := reader.NextInt()
	for t:=0;t<T;t++ {
		n:=reader.NextString()
		solve(n)
	}
}

func solve(s string){
	t:="123"
	requirements := make(map[byte]int)
	for i := range t {
		ch := t[i]
		if cnt, ok := requirements[ch]; !ok {
			requirements[ch] = 1
		} else {
			requirements[ch] = cnt + 1
		}
	}

	apperances := make(map[byte]int)
	counter := len(t)
	minLen := len(s) + 1
	resLeft, resRight := 0, 0
	for left, right := 0, 0; right < len(s); {
		rch, lch := s[right], s[left]

		if _, ok := requirements[rch]; ok {
			if cnt, ok := apperances[rch]; !ok {
				apperances[rch] = 1
			} else {
				apperances[rch] = cnt + 1
			}

			if apperances[rch] <= requirements[rch] && counter != 0 {
				counter--
			}
		}

		if counter == 0 {
			for {
				_, ok := requirements[lch]

				if !ok || apperances[lch] > requirements[lch] {
					if apperances[lch] > requirements[lch] {
						apperances[lch]--
					}

					left++
					lch = s[left]
				} else {
					break
				}
			}

			if right-left+1 < minLen {
				resLeft, resRight = left, right+1
				minLen = right - left + 1
			}
		}
		right++
	}

	writer.Printf("%d \n",resRight-resLeft)
}

/*
URL:
https://codeforces.com/problemset/problem/1354/B
*/

package main

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

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

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

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

var (
	t int
	S []rune
	n int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		S = ReadRuneSlice()
		n = len(S)

		solve()
	}
	stdout.Flush()
}

func solve() {
	memo := make(map[rune]int)
	memo['1'], memo['2'], memo['3'] = 0, 0, 0

	ans := INF_BIT30

	right := 0
	for left := 0; left < n; left++ {
		for right < n && (memo['1'] == 0 || memo['2'] == 0 || memo['3'] == 0) {
			// change condition(right)
			memo[S[right]]++

			right++
		}

		// query processing
		if memo['1'] > 0 && memo['2'] > 0 && memo['3'] > 0 {
			ChMin(&ans, right-left)
		}

		// preprocessing before preceding LEFT
		if right == left {
			right++
		} else {
			// change condition(left)
			memo[S[left]]--
		}
	}

	if ans < INF_BIT30 {
		PrintfBufStdout("%d\n", ans)
	} else {
		PrintfBufStdout("%d\n", 0)
	}
}

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

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

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

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

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

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

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

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

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

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	var answers = make([]int, t)

	for i := 0; i < t; i++ {
		var input string
		fmt.Scan(&input)
		answers[i] = findShortestContigSubString(input)
	}

	for _, ans := range answers {
		fmt.Println(ans)
	}
}

func findShortestContigSubString(input string) int {
	var count, len_window int
	var start, start_index, min_len, dist_count = 0, -1, 200001, 3
	var curr_count = make(map[string]int)

	if !strings.Contains(input, "1") || !strings.Contains(input, "2") || !strings.Contains(input, "3") {
		return 0
	}

	for j := 0; j < len(input); j++ {
		if _, ok := curr_count[string(input[j])]; ok {
			curr_count[string(input[j])]++
		} else {
			curr_count[string(input[j])] = 1
		}

		if curr_count[string(input[j])] == 1 {
			count++
		}

		if count == dist_count {
			for curr_count[string(input[start])] > 1 {
				if curr_count[string(input[start])] > 1 {
					curr_count[string(input[start])]--
				}
				start++
			}
			len_window = j - start + 1
			if min_len > len_window {
				min_len = len_window
				start_index = start
			}
		}
	}
	return len(input[start_index:(start_index + min_len)])
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		s := ScanWord()
		P(solve(s))
	}

	out.Flush()
}

func solve(s string) int {
	l := math.MaxInt32
	a1, a2, a3 := -1, -1, -1

	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			a1 = i
		} else if s[i] == '2' {
			a2 = i
		} else if s[i] == '3' {
			a3 = i
		}
		if d := minDis(a1, a2, a3); d < l {
			l = d
		}
	}

	if l == math.MaxInt32 {
		l = 0
	}
	return l
}

func minDis(a, b, c int) int {
	if a == -1 || b == -1 || c == -1 {
		return math.MaxInt32
	}
	mn, mx := MnMx(a, b, c)
	return mx - mn + 1
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case int64:
			str = strconv.FormatInt(v, 10)
		case string:
			str = v
		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var nt int
var s string

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		var last[3] int
		for i := 0; i < 3; i++ {
			last[i] = -1
		}

		fmt.Fscanf(reader, "%s\n", &s)
		var ret = int(1e9)

		for index, ch := range s {
			var val = int(ch - '0') - 1
			last[val] = index

			var pick = true
			var minPos = len(s) + 1

			for i := 0; i < 3; i++ {
				if last[i] == -1 {
					pick = false
					break
				}
				minPos = min(minPos, last[i])
			}

			if !pick {
				continue
			}

			ret = min(ret, index - minPos + 1)
		}
		if ret == int(1e9) {
			ret = 0
		}
		fmt.Fprintf(writer, "%d\n", ret)
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int64 {
	m := map[byte]int64{}
	l := 0
	r := 0
	ret := int64(len(s))
	valid := false
	for r < len(s) {
		for r < len(s) && len(m) != 3 {
			m[s[r]]++
			r++
		}
		if len(m) == 3 {
			valid = true
			ret = min(ret, int64(r-l))
		}
		for l < len(s) && len(m) != 2 {
			m[s[l]]--
			if m[s[l]] == 0 {
				delete(m, s[l])
			}
			l++
			if len(m) == 3 {
				valid = true
				ret = min(ret, int64(r-l))
			}
		}
	}
	if !valid {
		return 0
	}
	return ret
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	var answers = make([]string, t)

	for i := 0; i < t; i++ {
		var input string
		fmt.Scan(&input)
		answers[i] = findShortestContigSubString(input)
	}

	for _, ans := range answers {
		fmt.Println(ans)
	}
}

func findShortestContigSubString(input string) string {
	var count, len_window int
	var start, start_index, min_len, dist_count = 0, -1, 200000, 3
	var curr_count = make(map[string]int)

	if !strings.Contains(input, "1") || !strings.Contains(input, "2") || !strings.Contains(input, "3") {
		return "0"
	}

	for j := 0; j < len(input); j++ {
		if _, ok := curr_count[string(input[j])]; ok {
			curr_count[string(input[j])]++
		} else {
			curr_count[string(input[j])] = 1
		}

		if curr_count[string(input[j])] == 1 {
			count++
		}

		if count == dist_count {
			for curr_count[string(input[start])] > 1 {
				if curr_count[string(input[start])] > 1 {
					curr_count[string(input[start])]--
				}
				start++
			}
			len_window = j - start + 1
			if min_len > len_window {
				min_len = len_window
				start_index = start
			}
		}
	}
	return input[start_index:(start_index + min_len)]
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int64 {
	m := map[byte]int64{}
	l := 0
	r := 0
	ret := int64(len(s))+1
	for {
		for r < len(s) && len(m) != 3 {
			m[s[r]]++
			r++
		}
		if len(m) == 3 {
			ret = min(ret, int64(r-l))
		}
		if r == len(s) {
			break
		}
		//writer.Printf("%d %d\n", l, r)
		for l < len(s) && len(m) != 2 {
			m[s[l]]--
			if m[s[l]] == 0 {
				delete(m, s[l])
			}
			l++
			if len(m) == 3 {
				ret = min(ret, int64(r-l))
			}
		}
		//writer.Printf("%d %d\n", l, r)
	}
	if ret == int64(len(s))+1 {
		return 0
	}
	return ret
}