package main

import "fmt"

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	//fmt.Println(t, err)
	if err != nil {
		return
	}
	for t > 0 {
		solve1692a()
		t--
	}
}

func solve1692a() {
	var a, b, c, d int
	_, err := fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	if err != nil {
		return
	}
	cnt := 0
	if b > a {
		cnt = cnt + 1
	}
	if c > a {
		cnt = cnt + 1
	}
	if d > a {
		cnt = cnt + 1
	}
	fmt.Println(cnt)
}

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)

	for i:=0;i<t;i++{
	    fmt.Scan(&a)
    	fmt.Scan(&b)
    	fmt.Scan(&c)
    	fmt.Scan(&d)
	    x:=0
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
		fmt.Println(x)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	// reader := bufio.NewReader(os.Stdin)
	for i < t {
		guys := make([]int, 4)
		fmt.Scan(&guys[0])
		fmt.Scan(&guys[1])
		fmt.Scan(&guys[2])
		fmt.Scan(&guys[3])
		ans := 0
		// timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			// otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if guys[j] > guys[0] {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

import "fmt"

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

	for i := 0; i < n; i++ {
		var a, b, c, d int
		count := 0
		fmt.Scanf("%d %d %d %d ", &a, &b, &c, &d)

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

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

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

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

}

func solve() {
	//in := bufio.NewReader(os.Stdin)
	//out := bufio.NewWriter(os.Stdout)
	var a, b int
	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

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

	for t, _ := strconv.Atoi(getString(reader)); t > 0; t-- {
		var a = getIntln(reader)
		var result int

		for i := 1; i < 4; i++ {
			if a[0] < a[i] {
				result++
			}
		}

		writer.WriteString(strconv.Itoa(result) + "\n")
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

package main

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

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

func solve() string {
	var a, b, c, d int
	fmt.Fscan(in, &a, &b, &c, &d)
	var res int64

	if b > a {
		res++
	}
	if c > a {
		res++
	}
	if d > a {
		res++
	}

	return strconv.FormatInt(res, 10)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

import (
	"fmt"
)

func main() {
	var (
		t int
		a int
		b int
		c int
		d int
		n int
	)
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		n = 0
		fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
		if b > a {
			n++
		}
		if c > a {
			n++
		}
		if d > a {
			n++
		}
		fmt.Println(n)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

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

func solve() {
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()

	ans := 0
	if b > a {
		ans++
	}
	if c > a {
		ans++
	}
	if d > a {
		ans++
	}

	out(ans, "\n")
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	for i:=0;i<n;i++{
		var a,tally int
		fmt.Scan(&a)
		for j:=0;j<3;j++{
			var x int
			fmt.Scan(&x)
			if x > a {
				tally++
			}
		}
		fmt.Println(tally)
	}
}

package main

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

func solve(r *bufio.Reader) {
	var a, b, c, d int
	fmt.Fscan(r, &a, &b, &c, &d)
	xd := 0
	if b > a {
		xd++
	}
	if c > a {
		xd++
	}
	if d > a {
		xd++
	}
	fmt.Println(xd)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

	var t int
	var a [4]int

	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a[0], &a[1], &a[2], &a[3])
		cnt := 0

		for _, v := range a {
			if v > a[0] {
				cnt++
			}
		}

		fmt.Fprintln(out, cnt)
	}

}

package main

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

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

func solve(a []int) int {
	var f int
	for i := 1; i < 4; i++ {
		if a[i] > a[0] {
			f++
		}
	}
	return f
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		a = make([]int, 4)
		for i := range a {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(a))
	}
}

package main

import "fmt"

func test() {
	var a, b, c, d int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	ans := 0
	if a < b {
		ans += 1
	}

	if a < c {
		ans += 1
	}

	if a < d {
		ans += 1
	}

	fmt.Println(ans)
}

func main() {
	test_case := 0

	fmt.Scan(&test_case)

	for i := 0; i < test_case; i++ {
		test()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func readLine() []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	values := strings.Split(line, " ")
	return values
}

func readArrInt() []int {
	line := readLine()
	res := make([]int, 0, 0)
	for i := range line {
		var x, _ = strconv.Atoi(line[i])
		res = append(res, x)
	}
	return res
}

func main() {
	test := readInt()
	for ; 0 < test; test-- {
		var a = readArrInt()
		res := 0
		for i := 0; i < 4; i++ {
			if a[0] < a[i] {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	var Q int
	fmt.Fscan(reader, &Q)

	cmp := func(u, v int) int {
		if u < v {
			return 1
		}
		return 0
	}

	for ; Q > 0; Q-- {
		var a, b, c, d int
		fmt.Fscan(reader, &a, &b, &c, &d)
		var ans int = 0
		ans += cmp(a, b) + cmp(a, c) + cmp(a, d)
		fmt.Fprintf(writer, "%d\n", ans)
	}
}

package main

import "fmt"

func main() {
	var t, a, b, c, d, ans int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a, &b, &c, &d)
		ans = 0
		if a < b {
			ans++
		}
		if a < c {
			ans++
		}
		if a < d {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

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

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

func solve() {
	var a, b, c, d int
	scanf("%d %d %d %d\n", &a, &b, &c, &d)
	place := 0

	if b > a {
		place++
	}
	if c > a {
		place++
	}
	if d > a {
		place++
	}
	printf("%v\n", place)
}

func main() {
	defer writer.Flush()
	var cases int

	scanf("%d\n", &cases)
	// cases = 1

	for c := 0; c < cases; c++ {
		solve()
	}
}

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

func IntArray(size int) []int {
	arr := make([]int, size)
	for i := 0; i < size; i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}

func Max(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] > m {
			m = args[i]
		}
	}
	return m
}

func Min(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] < m {
			m = args[i]
		}
	}
	return m
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	distances := make([]int, 4)
	for i := 0; i < t; i++ {
		fmt.Fscan(cin, &distances[0], &distances[1], &distances[2], &distances[3])
		ans := 0
		for j := 1; j <= 3; j++ {
			if distances[j] > distances[0] {
				ans += 1
			}
		}
		fmt.Printf("%d\n", ans)
	}
}

package main

import "fmt"

func main(){
    var t int
    fmt.Scan(&t)
    for i:=0;i<t;i++{
        var a,b,c,d int
        fmt.Scan(&a,&b,&c,&d)
        var cnt int
        if b > a {
            cnt++
        }
        if c > a {
            cnt++
        }
        if d > a{
            cnt++
        }
        fmt.Println(cnt)
    }
}

package main

import "fmt"

func main() {
	var n, a, b, c, d int
	var ans [10005]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b, &c, &d)
		if a < b {
			ans[i]++
		}
		if a < c {
			ans[i]++
		}
		if a < d {
			ans[i]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(ans[i])
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1692A
Date: 17/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1692/A
Problem: CF1692A
**/
func (in *CF1692A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b, c, d := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()

		ans := 0
		if a < b {
			ans++
		}
		if a < c {
			ans++
		}
		if a < d {
			ans++
		}
		fmt.Println(ans)

	}
}

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

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

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)

	for t != 0 {

		var arr [4]int

		for i := 0; i < 4; i++ {
			fmt.Scan(&arr[i])
		}

		trumpCard := arr[0]
		count := 0

		for i := 1; i < 4; i++ {
			if arr[i] > trumpCard {
				count++
				continue
			}
		}
		fmt.Println(count)
		count = 0
		t-- // updater
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func slove() {
	var a,b,c,d int
	fmt.Fscan(r,&a,&b)
	fmt.Fscan(r,&c,&d)
	an := 0
	if b > a {
		an++
	}
	if c > a {
		an++
	}
	if d > a {
		an++
	}
	fmt.Fprintln(w,an)

}

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

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		ans := 0
		n, _ := fmt.Scan(&a, &b, &c, &d)
		if n == 0 {
			break
		}
		if c > a {
			ans++
		}
		if b > a {
			ans++
		}
		if d > a {
			ans++
		}
		fmt.Println(ans)
	}
}

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
	var n int
	n = 4
	var a = make([]int, n)
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(a)
		fmt.Fprintln(w, w1)
	}
}

func do(a []int) int {
	c := 0
	for i := 1; i < 4; i++ {
		if a[i] > a[0] {
			c++
		}
	}
	return c
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n,a,b,c,d int
	ans := 0

	fmt.Fscan(in, &n)

	// bitsがn個の要素の各パターンを表す
	for i := 0;i < n;i++ {
		fmt.Fscan(in, &a,&b,&c,&d)
		if a < b{
			ans++
		}
		if a < c{
			ans++
		}
		if a < d{
			ans++
		}
		fmt.Println(ans)
		ans = 0
	}
}

package main

import (
	"fmt"
)

func solve() {
	var a int
	fmt.Scan(&a)
	counter := 0
	for i := 0; i < 3; i++ {
		var x int
		fmt.Scan(&x)
		if x > a {
			counter++
		}
	}

	fmt.Println(counter)
}

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

package main

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

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

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

		var ans int
		if a < b {
			ans++
		}
		if a < c {
			ans++
		}
		if a < d {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	n := 4
	d := make([]int, n)

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

	a := d[0]
	d = d[1:]

	cnt := 0

	for _, dist := range d {
		if dist > a {
			cnt++
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var a, b, c, d int
		Fscan(in, &a, &b, &c, &d)
		cnt := 0
		if b > a {
			cnt++
		}
		if c > a {
			cnt++
		}
		if d > a {
			cnt++
		}

		Fprintln(out, cnt)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	r := 0
	a, b, c, d := ri(), ri(), ri(), ri()
	if a < b {
		r += 1
	}
	if a < c {
		r += 1
	}
	if a < d {
		r += 1
	}
	myio.Println(r)
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

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

func slove() {
	var a, b, c ,d int
	fmt.Fscan(r, &a, &b)
	fmt.Fscan(r, &c, &d)
	cnt := 0
	if b > a {
		cnt++
	}
	if c > a {
		cnt++
	}
	if d > a {
		cnt++
	}
	fmt.Fprintln(w, cnt)
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {

		a := make([]int, 4)
		for i := range a {
			Fscan(in, &a[i])
		}
		c:=0
		for i := 1; i < 4; i++ {
			if a[i]>a[0] {
				c++
			}
		}
		Fprintln(out, c)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	for i:=0;i<t;i++{
	    x:=0
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
		fmt.Println(x)
	}
}

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	x := 0
	for i:=0;i<t;i++{
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
	}
	fmt.Println(x)
}

package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	x := 0

	if b > a {
		x++
	}

	if c > a {
		x++
	}

	if d > a {
		x++
	}

	fmt.Println(x)
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	reader.ReadString('\n')
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(strings.Trim(text, "\n"), " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(strings.Trim(text, "\n"), " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(text, " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

import "fmt"

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

	for i := 0; i < n; i++ {
		var a, b, c, d int
		count := 0
		fmt.Scanf("%d %d %d %d ", &a, &b, &c, &d)

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

import "fmt"

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

	for i := 0; i < n; i++ {
		var a, b, c, d int
		count := 0
		fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

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

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

func solve() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var a, b int

	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

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

func solve() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var a, b int

	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

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

	for t, _ := strconv.Atoi(getString(reader)); t > 0; t-- {
		var a = getIntln(reader)
		var result int

		for i := 1; i < 4; i++ {
			if a[0] < a[i] {
				result++
			}
		}

		writer.WriteString(strconv.Itoa(result))
	}

	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}


package main

import (
	"fmt"
	"strings"
)

type pair struct {
	n int
	m int
}

// https://codeforces.com/problemset/problem/1353/A
// комментарий к решению
func taskSolution(in []pair) string {
	ans := make([]int, len(in))
	for i := 0; i < len(in); i += 1 {
		n, m := in[i].n, in[i].m
		switch n {
		case 1:
			ans[i] = 0
		case 2:
			ans[i] = m
		default:
			ans[i] = 2 * m
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	in := make([]pair, 0, t)
	for i := 0; i < t; i += 1 {
		var n, m int
		if _, err := fmt.Scan(&n, &m); err != nil {
			panic(err)
		}
		in = append(in, pair{n: n, m: m})
	}

	fmt.Println(taskSolution(in))
}

package main

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

func main() {
	for t := readInt(); t > 0; t-- {
		n, m := readInt2()
		switch n {
		case 1:
			fmt.Println(0)
		case 2:
			fmt.Println(m)
		default:
			fmt.Println(2 * m)
		}
	}
}

var (
	stdin = bufio.NewReader(os.Stdin)
)

func readLine() string {
	s, _ := stdin.ReadString('\n')
	return s
}

func readInts() (r []int) {
	reader := strings.NewReader(readLine())
	for {
		var x int
		_, err := fmt.Fscan(reader, &x)
		if err != nil {
			break
		}
		r = append(r, x)
	}
	return
}

func readInt() (int) {
	a := readInts()
	return a[0]
}

func readInt2() (int, int) {
	a := readInts()
	return a[0], a[1]
}

package main

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

func main() {
	var n, m, t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		if n > 2 {
			fmt.Println(m * 2)
		} else if n == 1 {
			fmt.Println(0)
		} else {
			fmt.Println(m)
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n, m int

	fmt.Scan(&n, &m)
	if n == 1 {
		fmt.Println(0)
	} else if n == 2 {
		fmt.Println(m)
	} else {
		fmt.Println(2 * m)
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, m int64
		fmt.Fscan(in, &n, &m)
		if n == 1 {
			fmt.Fprintln(out, 0)
		} else if n == 2 {
			fmt.Fprintln(out, m)
		} else {
			fmt.Fprintln(out, m*2)
		}
	}
}

// https://codeforces.com/contest/1350/problem/A
package main

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

// (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++ {
		solver()
	}
}

func solver() {
	var n, m int
	fmt.Fscan(input, &n, &m)
	if n == 1 {
		fmt.Println(0)
	} else if n == 2 {
		fmt.Println(m)
	} else {
		fmt.Println(m * 2)
	}
}

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 main() {
    defer writer.Flush()
    var t, n, m int
    scanf("%d\n", &t)
    for i := 0; i < t; i++ {
        defer writer.Flush()
        scanf("%d %d\n", &n, &m)
        if n > 2 {
            printf("%d\n", m * 2)
        } else if n == 1 {
            printf("%d\n", 0)
        } else {
            printf("%d\n", m)
        }
    }
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"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()

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		res := solve(n, m)

		fmt.Println(res)
	}
}

func solve(n, m int) int  {
	if n == 1 {
		return 0
	}
	if n == 2 {
		return m
	}
	return 2 * m
}

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

package main

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

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

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		if n == 1 {
			Fprintln(out, 0)
		} else if n == 2 {
			Fprintln(out, m)
		} else {
			Fprintln(out, 2*m)
		}
	}
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		if n >= 3 {
			P(m << 1)
		} else if n == 2 {
			P(m)
		} else {
			P(0)
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** 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 (
	"fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,m int
		fmt.Scan(&n);
		fmt.Scan(&m);
		if n == 1{
			fmt.Println(0)
		}else if n==2{
			fmt.Println(m)
		}else{
			fmt.Println(m*2)
		}
	}

}

// https://serhatgiydiren.github.io

package main

import "fmt"

func solve(test_id int) {
 var n,m,res int
	fmt.Scan(&n,&m)
 if n == 1 {
  res = 0
 } else if n == 2 {
  res = m
 } else {
  res = 2 * m
 }
 fmt.Println(res)
}

func solve_cases() {
 t := 1
 fmt.Scan(&t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &m)
		if n == 1 {
			fmt.Println(0)
		} else if n == 2 {
			fmt.Println(m)
		} else {
			fmt.Println(2 * m)
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(r, &n, &m)

		if n == 1 {
			fmt.Fprintln(w, 0)
		} else if n == 2 {
			fmt.Fprintln(w, m)
		} else {
			fmt.Fprintln(w, m*2)
		}
	}
}

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, m int
		fmt.Fscan(reader, &n, &m)
		if n == 1 {
			fmt.Fprintln(writer, 0)
		} else if n == 2 {
			fmt.Fprintln(writer, m)
		} else {
			fmt.Fprintln(writer, m*2)
		}
	}
}

package main

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

func main() {
	var t int
	var n, k int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &b[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		sort.Slice(b, func(i, j int) bool {
			return b[i] > b[j]
		})
		sum := 0
		ai := 0
		bi := 0
		for j := 0; j < n; j++ {
			if a[ai] >= b[bi] || k == 0 {
				sum += a[ai]
				ai++
			} else {
				sum += b[bi]
				bi++
				k--
			}
		}
		fmt.Println(sum)
	}
}

package main

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

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

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		solve(n, m)
	}
}

func solve(n, m int) int  {
	if n <= 2 {
		return m
	}
	return 2 * m
}

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

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"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()

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		res := solve(n, m)

		fmt.Println(res)
	}
}

func solve(n, m int) int  {
	if n <= 2 {
		return m
	}
	return 2 * m
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		if n >= 3 {
			P(m << 1)
		} else {
			P(m)
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** 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"
	//"bytes"
	"fmt"
	"math"
	"os"
	//"strconv"
)

func main() {
	var n int
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	for _, err := fmt.Fscan(stdin, &n); err == nil; _, err = fmt.Fscan(stdin, &n) {
		b := make([]int64, n/2)
		for i := 0; i < n/2; i++ {
			fmt.Fscan(stdin, &b[i])
		}
		var start int64 = 0
		var end int64 = math.MaxInt64
		a := make([]int64, n)
		for i := 0; i < n/2; i++ {
			if start + end > b[i] {
				end = b[i] - start
			} else {
				start = b[i] - end
			}
			a[i] = start
			a[n - 1 - i] = end
		}
		for i, val := range a {
			if i > 0 {
				stdout.WriteByte(' ')
			}
			fmt.Fprintf(stdout, "%d", val)
		}
		stdout.WriteByte('\n')
		stdout.Flush()
		/*
		var buffer bytes.Buffer
		for i, val := range a {
			if i > 0 {
				buffer.WriteByte(' ')
			}
			buffer.WriteString(strconv.FormatInt(val, 10))
		}
		buffer.WriteByte('\n')
		os.Stdout.Write(buffer.Bytes())
		*/
	}
}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var B = make([]int64, n / 2)
    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &B[i])
        A[j] = B[i]

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &A[j])

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

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

func main(){
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make([]int64,n)
	var st int = 0
	var end int = n-1
	for i:=1;i <= n/2;i++{
		var v int64
		fmt.Fscanf(buf, "%d", &v)
		if i == 1{
			mat[st] = 0
			mat[end] = v
			st++
			end--
			continue
		}
		//fmt.Printf("%d %d %d\n",v,mat[st-1],mat[end+1])
		if v <=mat[st-1]+mat[end+1]{
			mat[st] = mat[st-1]
			mat[end]=v-mat[st]

		}else{
			mat[end] = mat[end+1]
			mat[st] = v-mat[end]
		}
		st++
		end--
	}
	for i:=0;i < n;i++{
		if i > 0{
			fmt.Printf(" ")
		}
		fmt.Printf("%d",mat[i])

	}
	fmt.Printf("\n")

}

package main

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

func main() {
	buffer := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buffer, "%d\n", &n)
	a := make([]int64, n + 1)
	b := make([]int64, n / 2 + 1)
	for i := 1; i <= n / 2; i++ {
		fmt.Fscanf(buffer, "%d", &b[i])
	}
	var t int64
	a[1] = 0
	a[n] = b[1] - a[1]
	for i := 2; i <= n/ 2; i++ {
		a[i] = a[i - 1]
		a[n + 1 - i] = b[i] - a[i]
		t = a[n + 1 - i] - a[n + 2 - i]
		if t > 0 {
			a[i] += t
			a[n + 1 - i] -= t
		}
	}
	for i:= 1; i <= n; i++ { fmt.Printf("%d ", a[i])}
}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &A[j])

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    stdout := bufio.NewWriter(os.Stdout)

    for _, num := range(A) {
        fmt.Fprint(stdout, num)
        stdout.WriteByte(' ')
    }
    stdout.WriteByte('\n')
    stdout.Flush()

}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int, int) int
    mx = func (i, j int) int {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var B = make([]int, n / 2)
    var A = make([]int, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &B[i])
        A[j] = B[i]

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

import "fmt"

func min(x int, y int) int {
    if x > y { return y }
    return x
}
func max(x int, y int) int {
    if x > y { return x }
    return y
}

func main() {
	var n int

	fmt.Scanf("%d\n", &n)
	var a []int = make([]int, n)
	var b []int = make([]int, n/2)

	for i := 0; i < n/2; i++ {
		fmt.Scanf("%d", &b[i])
	}

	var x, y = 0, b[0]
	for i, num := range(b) {
	    y = min(y, num)
	    x = num - y

	    a[n-i-1] = y
	    a[i] = x
	}

	for _, num := range(a) {
	    fmt.Print(num, " ")
	}
	fmt.Println()
}

package main

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

func main() {
	var n int
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	for _, err := fmt.Fscan(stdin, &n); err == nil; _, err = fmt.Fscan(stdin, &n) {
		b := make([]int64, n/2)
		for i := 0; i < n/2; i++ {
			fmt.Fscan(stdin, &b[i])
		}
		var start int64 = 0
		var end int64 = math.MaxInt64
		a := make([]int64, n)
		for i := 0; i < n/2; i++ {
			if start + end > b[i] {
				end = b[i] - start
			} else {
				start = b[i] - end
			}
			a[i] = start
			a[n - 1 - i] = end
		}
		for i, val := range a {
			if i > 0 {
				fmt.Fprint(stdout, ' ')
			}
			fmt.Fprint(stdout, val)
		}
		fmt.Fprint(stdout, '\n')
		/*
		var buffer bytes.Buffer
		for i, val := range a {
			if i > 0 {
				buffer.WriteByte(' ')
			}
			buffer.WriteString(strconv.FormatInt(val, 10))
		}
		buffer.WriteByte('\n')
		os.Stdout.Write(buffer.Bytes())
		*/
	}
}

package main

import "fmt"

func min(x int, y int) int {
    if x > y { return y }
    return x
}
func max(x int, y int) int {
    if x > y { return x }
    return y
}

func main() {
	var n int

	fmt.Scanf("%d\n", &n)
	var a []int = make([]int, n)
	var b []int = make([]int, n/2)

	for i := 0; i < n/2; i++ {
		fmt.Scanf("%d", &b[i])
	}

	var x, y = 0, b[0]
	for i, num := range(b) {
	    y = min(y, num)

	    if num - y < x {
	        y = num - x
	    } else {
	        x = num - y
	    }

	    a[n-i-1] = y
	    a[i] = x
	}

	for _, num := range(a) {
	    fmt.Print(num, " ")
	}
	fmt.Println()
}


package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		keys := map[byte]int{}
		buy_key := 0
		for i := 0; i < n-1; i++ {
			key := s[i*2]
			lock := s[i*2+1] + ('a' - 'A')
			if key == lock {
				continue
			} else {
				if _, exist := keys[lock]; exist && keys[lock] > 0 {
					keys[lock] = keys[lock] - 1
				} else {
					buy_key++
				}
				if _, exist := keys[key]; exist {
					keys[key] = keys[key] + 1
				} else {
					keys[key] = 1
				}
			}
		}

		fmt.Println(buy_key)
	}
}

package main

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

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

const ALPHAB int = 26

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	var (
		n, key int
		s string
	)

	alph := make([]int, ALPHAB)

	scan(&n, &s)

	for i := 0; i < len(s); i += 2 {
		alph[s[i] - 'a']++

		if alph[s[i+1] - 'A'] == 0 {
			key++
		} else {
			alph[s[i+1] - 'A']--
		}
	}

	println(key)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

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

package main

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

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

  line, _ := reader.ReadString('\n')
  n, _ := strconv.Atoi(strings.TrimSpace(line))
  m := 2*n-2
  line, _ = reader.ReadString('\n')
  line = strings.ToLower(strings.TrimSpace(line))
  result := 0
  keys := map[byte]int{}
  for i := 0; i < m; i += 2 {
    key, door := line[i], line[i+1]
    keys[key]++
    if keys[door] == 0 {
      result++
    } else {
      keys[door]--
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer([]byte(nil), 1e6)
	s.Split(bufio.ScanWords)
	_ = nextInt(s)
	s.Scan()
	str := s.Text()

	keys := make([]int, 26)
	doors := make([]int, 26)

	for i := 0; i < len(str); i++ {
		if isUpper(str[i]) && keys[toLower(str[i])-'a'] > 0 {
			keys[toLower(str[i])-'a']--
		} else if isUpper(str[i]) {
			doors[str[i]-'A']++
		} else {
			keys[str[i]-'a']++
		}
	}
	c := 0
	for i := 0; i < 26; i++ {
		if doors[i] > 0 {
			c += doors[i]
		}
	}
	fmt.Println(c)
}

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

func toLower(x byte) byte {
	return x + ('a' - 'A')
}

func isUpper(x byte) bool {
	return x >= 'A' && x <= 'Z'
}

func initArray(n, x int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = x
	}
	return xs
}

func nextInt(s *bufio.Scanner) (n int) {
	s.Scan()
	n, _ = strconv.Atoi(s.Text())
	return
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var keys [26]int
	rooms := ""
	fmt.Scan(&rooms)

	ans := 0
	for i := 0; i < len(rooms); i += 2 {
		keys[rooms[i]-'a']++
		if keys[rooms[i+1]-'A'] == 0 {
			ans++
		} else {
			keys[rooms[i+1]-'A']--
		}
	}

	fmt.Println(ans)
}

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		keys := map[byte]int{}
		buy_key := 0
		for i := 0; i < n-1; i++ {
			key := s[i*2]
			lock := s[i*2+1] + ('a' - 'A')
			if key == lock {
				continue
			} else {
				if _, exist := keys[lock]; exist {
					keys[lock] = keys[lock] - 1
				} else {
					buy_key++
				}
				if _, exist := keys[key]; exist {
					keys[key] = keys[key] + 1
				} else {
					keys[key] = 1
				}
			}
		}

		fmt.Println(buy_key)
	}
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	_ = nextInt(s)
	s.Scan()
	str := s.Text()

	keys := make([]int, 26)
	doors := make([]int, 26)

	for i := 0; i < len(str); i++ {
		if isUpper(str[i]) && keys[toLower(str[i])-'a'] > 0 {
			keys[toLower(str[i])-'a']--
		} else if isUpper(str[i]) {
			doors[str[i]-'A']++
		} else {
			keys[str[i]-'a']++
		}
	}
	c := 0
	for i := 0; i < 26; i++ {
		if doors[i] > 0 {
			c += doors[i]
		}
	}
	fmt.Println(c)
}

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

func toLower(x byte) byte {
	return x + ('a' - 'A')
}

func isUpper(x byte) bool {
	return x >= 'A' && x <= 'Z'
}

func initArray(n, x int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = x
	}
	return xs
}

func nextInt(s *bufio.Scanner) (n int) {
	s.Scan()
	n, _ = strconv.Atoi(s.Text())
	return
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF120H(_r io.Reader, _w io.Writer) {
	var _ss []string
	var _gen func(s, sub string)
	_gen = func(s, sub string) {
		_ss = append(_ss, sub)
		if len(sub) < 4 {
			for i := range s {
				_gen(s[i+1:], sub+string(s[i]))
			}
		}
	}
	genSubStrs := func(s string) []string {
		_ss = []string{}
		_gen(s, "")
		a := _ss[1:]
		n := len(a)
		sort.Strings(a)
		res := make([]string, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return res
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	strID := map[string]int{}
	idToStr := []string{}
	g := make([][]int, n)
	for i := range g {
		var s string
		Fscan(in, &s)
		ss := genSubStrs(s)
		for _, s := range ss {
			id, ok := strID[s]
			if !ok {
				id = len(strID)
				strID[s] = id
				idToStr = append(idToStr, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(strID))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(v int) bool
	f = func(v int) bool {
		if !used[v] {
			used[v] = true
			for _, w := range g[v] {
				if matchR[w] == -1 || f(matchR[w]) {
					matchR[w] = v
					matchL[v] = w
					return true
				}
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, idToStr[id])
	}
}

func main() {
	r, _ := os.Open("input.txt")
	w, _ := os.Create("output.txt")
	CF120H(r, w)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF120H(_r io.Reader, _w io.Writer) {
	var _ss []string
	var _gen func(s, sub string)
	_gen = func(s, sub string) {
		_ss = append(_ss, sub)
		if len(sub) < 4 {
			for i := range s {
				_gen(s[i+1:], sub+string(s[i]))
			}
		}
	}
	genSubStrs := func(s string) []string {
		_ss = []string{}
		_gen(s, "")
		a := _ss[1:]
		n := len(a)
		sort.Strings(a)
		res := make([]string, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return res
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	strID := map[string]int{}
	idToStr := []string{}
	g := make([][]int, n)
	for i := range g {
		var s string
		Fscan(in, &s)
		ss := genSubStrs(s)
		for _, s := range ss {
			id, ok := strID[s]
			if !ok {
				id = len(strID)
				strID[s] = id
				idToStr = append(idToStr, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(strID))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(v int) bool
	f = func(v int) bool {
		used[v] = true
		for _, w := range g[v] {
			if lv := matchR[w]; lv == -1 || !used[lv] && f(lv) {
				matchR[w] = v
				matchL[v] = w
				return true
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, idToStr[id])
	}
}

func main() {
	r, _ := os.Open("input.txt")
	w, _ := os.Create("output.txt")
	CF120H(r, w)
}

package main

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

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

	genSubStrs := func(s string) []string {
		a := []string{}
		var f func(s, sub string)
		f = func(s, sub string) {
			a = append(a, sub)
			if len(sub) < 4 {
				for i, b := range s {
					f(s[i+1:], sub+string(b))
				}
			}
		}
		f(s, "")
		a = a[1:]
		sort.Strings(a)
		j := 0
		for i := 1; i < len(a); i++ {
			if a[j] != a[i] {
				j++
				a[j] = a[i]
			}
		}
		return a[:j+1]
	}
	var n int
	var s string
	Fscan(in, &n)
	sid := map[string]int{}
	strs := []string{}
	g := make([][]int, n)
	for i := range g {
		Fscan(in, &s)
		a := genSubStrs(s)
		for _, s := range a {
			id, ok := sid[s]
			if !ok {
				id = len(sid)
				sid[s] = id
				strs = append(strs, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(sid))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(int) bool
	f = func(v int) bool {
		used[v] = true
		for _, w := range g[v] {
			if lv := matchR[w]; lv == -1 || !used[lv] && f(lv) {
				matchR[w] = v
				matchL[v] = w
				return true
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, strs[id])
	}
}

func main() { r, _ := os.Open("input.txt"); w, _ := os.Create("output.txt"); CF120H(r, w) }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF120H(_r io.Reader, _w io.Writer) {
	var _ss []string
	var _gen func(s, sub string)
	_gen = func(s, sub string) {
		_ss = append(_ss, sub)
		if len(sub) < 4 {
			for i := range s {
				_gen(s[i+1:], sub+string(s[i]))
			}
		}
	}
	genSubStrs := func(s string) []string {
		_ss = []string{}
		_gen(s, "")
		a := _ss[1:]
		n := len(a)
		sort.Strings(a)
		res := make([]string, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return res
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	strID := map[string]int{}
	idToStr := []string{}
	g := make([][]int, n)
	for i := range g {
		var s string
		Fscan(in, &s)
		ss := genSubStrs(s)
		for _, s := range ss {
			id, ok := strID[s]
			if !ok {
				id = len(strID)
				strID[s] = id
				idToStr = append(idToStr, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(strID))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(v int) bool
	f = func(v int) bool {
		if !used[v] {
			used[v] = true
			for _, w := range g[v] {
				if matchR[w] == -1 || f(matchR[w]) {
					matchR[w] = v
					matchL[v] = w
					return true
				}
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, idToStr[id])
	}
}

func main() {
	r, _ := os.Open("input.txt")
	w, _ := os.OpenFile("output.txt", os.O_WRONLY|os.O_CREATE, 0666)
	CF120H(r, w)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF120H(_r io.Reader, _w io.Writer) {
	var _ss []string
	var _gen func(s, sub string)
	_gen = func(s, sub string) {
		_ss = append(_ss, sub)
		if len(sub) < 4 {
			for i := range s {
				_gen(s[i+1:], sub+string(s[i]))
			}
		}
	}
	genSubStrs := func(s string) []string {
		_ss = []string{}
		_gen(s, "")
		a := _ss[1:]
		n := len(a)
		sort.Strings(a)
		res := make([]string, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return res
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	strID := map[string]int{}
	idToStr := []string{}
	g := make([][]int, n)
	for i := range g {
		var s string
		Fscan(in, &s)
		ss := genSubStrs(s)
		for _, s := range ss {
			id, ok := strID[s]
			if !ok {
				id = len(strID)
				strID[s] = id
				idToStr = append(idToStr, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(strID))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(v int) bool
	f = func(v int) bool {
		if !used[v] {
			used[v] = true
			for _, w := range g[v] {
				if matchR[w] == -1 || f(matchR[w]) {
					matchR[w] = v
					matchL[v] = w
					return true
				}
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, idToStr[id])
	}
}

func main() {
	r, _ := os.Open("input.txt")
	w, _ := os.Open("output.txt")
	CF120H(r, w)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF120H(_r io.Reader, _w io.Writer) {
	var _ss []string
	var _gen func(s, sub string)
	_gen = func(s, sub string) {
		_ss = append(_ss, sub)
		if len(sub) < 4 {
			for i := range s {
				_gen(s[i+1:], sub+string(s[i]))
			}
		}
	}
	genSubStrs := func(s string) []string {
		_ss = []string{}
		_gen(s, "")
		a := _ss[1:]
		n := len(a)
		sort.Strings(a)
		res := make([]string, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return res
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	strID := map[string]int{}
	idToStr := []string{}
	g := make([][]int, n)
	for i := range g {
		var s string
		Fscan(in, &s)
		ss := genSubStrs(s)
		for _, s := range ss {
			id, ok := strID[s]
			if !ok {
				id = len(strID)
				strID[s] = id
				idToStr = append(idToStr, s)
			}
			g[i] = append(g[i], id)
		}
	}

	matchL := make([]int, n)
	matchR := make([]int, len(strID))
	for i := range matchR {
		matchR[i] = -1
	}
	var used []bool
	var f func(v int) bool
	f = func(v int) bool {
		if !used[v] {
			used[v] = true
			for _, w := range g[v] {
				if matchR[w] == -1 || f(matchR[w]) {
					matchR[w] = v
					matchL[v] = w
					return true
				}
			}
		}
		return false
	}
	cnt := 0
	for v := range g {
		used = make([]bool, n)
		if f(v) {
			cnt++
		}
	}
	if cnt < n {
		Fprint(out, -1)
		return
	}
	for _, id := range matchL {
		Fprintln(out, idToStr[id])
	}
}

func main() {
	r, _ := os.Open("input.txt")
	w, _ := os.OpenFile("output.txt", os.O_WRONLY, 0)
	CF120H(r, w)
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Print((j * n) + 1 + (i+j)%n)
			if j == (n - 1) {
				fmt.Println()
			} else {
				fmt.Print(" ")
			}
		}
	}
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func main() {
  n := ni32()
  cnt := 0
  for i := 0; i < n*n/2; i++ {
    pri32(i+1, n*n-i)
    cnt++
    if cnt == n/2 {
      cnt = 0
      endl()
    }

  }
  w.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	cur := 1
	for i := 0; i < n; i++ {
		for j := 0; j < n/2; j++ {
			fmt.Printf("%d %d ", cur, n*n-cur+1)
			cur++
		}
		fmt.Println()
	}
}

// mic-334A
package main

import (
    "fmt"
)

func main() {
    var n, k, i,s,m int
    fmt.Scan(&n)
    change := false
    k = n * n
    ans1 := make([]int, k/2)
    ans2 := make([]int, k/2)
    i = 1
    for i < k {
        if !change {
            ans1[s] = i
            ans1[s+1] = k
            change = true
            s+=2
        } else if change {
            ans2[m] = i
            ans2[m+1] = k
            change = false
            m+=2
        }
        i++
        k--
    }
    for i := range ans1 {
        fmt.Print(ans1[i])
        if i < len(ans1)-1 {
            fmt.Print(" ")
        } else {
            fmt.Println("")
        }
    }
        for i := range ans2 {
        fmt.Print(ans2[i])
        if i < len(ans2)-1 {
            fmt.Print(" ")
        } else {
            fmt.Println("")
        }
    }
}

package main
import (
    "fmt"
)
func main() {
    var masuk,t1,t2,hasil int
    fmt.Scan(&masuk)
    for a:=1; a<=masuk; a++ {
        for b:=0; b<masuk; b++ {
            t1=a+b*(masuk+1)
            t2=(b+1)*masuk
            if t1>t2 {
                hasil=a+(b-1)*(masuk +1)+1
                fmt.Printf("%d ",hasil)
            } else {
                hasil= a+b*(masuk+1)
                fmt.Printf("%d ",hasil)
            }

        }
        fmt.Println()
    }
}

// cf334q project main.go
package main

import (
	"fmt"
)

// 1 8 9  16
// 2 7 10 15
// 3 6 11 14
// 4 5 12 13
func main() {
	var n int
	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		for j := 1; j <= n; j++ {
			var u int
			if j%2 == 0 {
				u = n*j - i
			} else {
				u = n*(j-1) + i + 1
			}
			fmt.Printf("%d ", u)
		}
		fmt.Println("")
	}

}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            fmt.Print((j*n)+1+(i+j)%n)
            if j == (n-1) { fmt.Println() } else { fmt.Print(" ") }
        }
    }
}

package main

import "fmt"

func main() {
	var n int

	fmt.Scan(&n)

	for i:=1; i<=n*n/2; i++ {
		fmt.Printf("%d %d ", i, n*n-i+1)
		if i % (n/2) == 0 {
			fmt.Print("\n")
		}
	}
}

package main

import (
  "fmt"
)

var n int

func input() {
  fmt.Scanf("%d", &n)
}

func solve() {
  for i := 1; i <= n; i ++ {
    for x := 0; x < n; x ++ {
      if i + x * (n + 1) > (x + 1) * n {
        fmt.Print(i + (x - 1) * (n + 1) + 1, ` `)
      } else {
        fmt.Print(i + x * (n + 1), ` `)
      }
    }
    fmt.Print("\n")
  }
}

func main() {
  input()
  solve()
}

package main
import 	"fmt"
func main() {
	var n int
	_,_=fmt.Scanf("%d", &n)
	var tempn, k = n*n, 1
	for i :=1; i<=n;i++{
		for j:=1; j<=n/2;j++{
			fmt.Printf("%d %d ", k, tempn)
			tempn--
			k++
		}
		fmt.Println("")
	}
}

// cf334q project main.go
package main

import (
	"fmt"
)

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

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", i, 2*n+1-i)
	}

}