package main

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

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	A := sc.NextIntArray()

	for i := 0; i < n / 2; i++ {
		if i % 2 == 0 {
			A[i], A[n - i - 1] = A[n - i - 1], A[i]
		}
	}
	PrintI(A...)

}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

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

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

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

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

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

	return mp
}

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

package main

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

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

	fmt.Fscanln(reader, &n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	for i := 0; i < n/2; i += 2 {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}

	for i := 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
}

package main

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

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

	fmt.Fscanln(reader, &n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	for i := 0; i < n; i++ {
		if n%2 == 0 && i >= n/2 {
			if i%2 == 1 {
				fmt.Print(a[n-i-1], " ")
			} else {
				fmt.Print(a[i], " ")
			}
		} else {
			if i%2 == 0 {
				fmt.Print(a[n-i-1], " ")
			} else {
				fmt.Print(a[i], " ")
			}
		}
	}
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

type Int int64

func main() {
	defer w.Flush()
	var n Int
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n Int) {
	in := make([]Int, n+1)
	for i := Int(1); i <= n; i++ {
		I(&in[i])
	}
	for i := Int(1); i <= n; i++ {
		if i > n-i+1 {
			break
		}
		if i%2 == 1 {
			in[i], in[n-i+1] = in[n-i+1], in[i]
		}
	}
	for i := Int(1); i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		O(in[i], o)
	}
}

package main

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

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

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	for i := 0; i < n/2; i++ {
		if i%2 == 0 {
			j := n - i - 1
			array[i], array[j] = array[j], array[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", array[i])
	}
	fmt.Println()
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	for i := 0; i < n/2; i++ {
		if i%2 == 0 {
			a[i], a[n-i-1] = a[n-i-1], a[i]
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Printf(" %d", a[i])
		} else {
			fmt.Printf("%d", a[i])
		}
	}
	fmt.Println()
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	for i := 0; i < n/2; i++ {
		if i%2 == 0 {
			a[i], a[n-i-1] = a[n-i-1], a[i]
		}
	}

	var buffer bytes.Buffer
	for i := 0; i < n; i++ {
		if i > 0 {
			buffer.WriteString(" ")
		}
		buffer.WriteString(strconv.Itoa(a[i]))
	}
	fmt.Println(buffer.String())
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	for i := 0; i < N / 2; i++ {
		if (i % 2 == 0) {
			A[i], A[N - i - 1] = A[N - i - 1], A[i]
		}
	}

	for i := 0; i < N; i++ {
		io.Printf("%d ", A[i]);
	}
	io.Println("");
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Solve(&io)
	io.FlushOutput()
}


package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		judge := func(skip int, limit int64) bool {
			last := a[0]
			find := false
			for i := 1; i < n+1; i++ {
				if i == skip {
					continue
				}
				if a[i]-last <= limit {
					return false
				}
				if a[i]-last > limit*2+1 {
					find = true
				}
				last = a[i]
			}
			if skip == n {
				return find || d-a[n-1] > limit
			}
			return find || d-a[n] > limit
		}
		check := func(limit int64) bool {
			last := a[0]
			for i := 1; i < n+1; i++ {
				if a[i]-last <= limit {
					return judge(i, limit) || (i > 1 && judge(i-1, limit))
				}
				last = a[i]
			}
			return true
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

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

func CF1650E(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n, d := 0, 0
		fmt.Fscan(in, &n, &d)
		min_gap, min_pos := d, 0
		arr := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]-arr[i-1]-1 < min_gap {
				min_gap, min_pos = arr[i]-arr[i-1]-1, i
			}
		}
		b := []int{}
		for i := 0; i <= n; i++ {
			if i != min_pos {
				b = append(b, arr[i])
			}
		}
		ans := help(b, d)
		if min_pos > 1 {
			b[min_pos-1] = arr[min_pos]
		}
		ans = max(ans, help(b, d))
		fmt.Fprintln(out, ans)
	}
}

func help(b []int, d int) int {
	mx, mm := math.MinInt32, math.MaxInt32
	for i := 1; i < len(b); i++ {
		mx = max(mx, b[i]-b[i-1]-1)
		mm = min(mm, b[i]-b[i-1]-1)
	}
	return min(mm, max(d-b[len(b)-1]-1, (mx-1)/2))
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, d := cin.NextInt(), cin.NextInt()
	a := cin.NextInts(n)
	r := make([]int, n)
	lst := 0
	for i := 0; i < n; i++ {
		r[i] = a[i] - lst - 1
		lst = a[i]
	}
	var largestHole, largestHoleIdx int
	for i := 0; i < n; i++ {
		if r[i] > largestHole {
			largestHole = r[i]
			largestHoleIdx = i
		}
	}
	prefixMinR, suffixMinR := make([]int, n), make([]int, n)
	prefixMinR[0] = r[0]
	for i := 1; i < n; i++ {
		prefixMinR[i] = prefixMinR[i-1]
		if prefixMinR[i] > r[i] {
			prefixMinR[i] = r[i]
		}
	}
	suffixMinR[n-1] = r[n-1]
	for i := n - 2; i >= 0; i-- {
		suffixMinR[i] = suffixMinR[i+1]
		if suffixMinR[i] > r[i] {
			suffixMinR[i] = r[i]
		}
	}
	ans := prefixMinR[n-1]
	// cerr.Println("initAns", ans)
	// cerr.Println("r", r, "prefixMinR", prefixMinR, "suffixMinR", suffixMinR)
	for i := range r {
		// try move the i-th exam yo
		if i+1 < n {
			lo := 0
			if i > 0 {
				lo = a[i-1]
			}
			hi := a[i+1]
			{
				// self hi
				mi := lo + (hi-lo)/2
				cans := mi - lo - 1
				if rio := hi - mi - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Printf("i=%d, lo=%d, hi=%d, mi=%d, cans=%d, ans=%d\n", i, lo, hi, mi, cans, ans)
			}
			if a[n-1] < d {
				// last hi
				cans := d - a[n-1] - 1
				if rio := hi - lo - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Printf("i=%d, lo=%d, hi=%d, cans=%d, ans=%d\n", i, lo, hi, cans, ans)
			}
			if (largestHoleIdx < i || largestHoleIdx > i+1) && largestHole >= 1 {
				// other hi
				lohole := 0
				if largestHoleIdx > 0 {
					lohole = a[largestHoleIdx-1]
				}
				hihole := a[largestHoleIdx]
				mihole := lohole + (hihole-lohole)/2
				cans := mihole - lohole - 1
				if rio := hihole - mihole - 1; rio < cans {
					cans = rio
				}
				if rio := hi - lo - 1; rio < cans {
					cans = rio
				}
				if i > 0 && prefixMinR[i-1] < cans {
					cans = prefixMinR[i-1]
				}
				if i+2 < n && suffixMinR[i+2] < cans {
					cans = suffixMinR[i+2]
				}
				if cans > ans {
					ans = cans
				}
				// cerr.Println("i=", i, "lohole=", lohole, "hihole=", hihole, "mihole=", mihole, "cans=", cans, "ans=", ans)
			}
		} else {
			cans := d - a[i-1] - 1
			if prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Println("i=", i, "cans=", cans, "ans=", ans)
		}

	}
	// cerr.Println("===================")
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		judge := func(skip int, limit int64) bool {
			last := a[0]
			find := false
			for i := 1; i < n+1; i++ {
				if i == skip {
					continue
				}
				if a[i]-last <= limit {
					return false
				}
				if a[i]-last > limit*2+1 {
					find = true
				}
				last = a[i]
			}
			return find || d-a[n] > limit
		}
		check := func(limit int64) bool {
			last := a[0]
			for i := 1; i < n+1; i++ {
				if a[i]-last <= limit {
					return judge(i, limit) || (i > 1 && judge(i-1, limit))
				}
				last = a[i]
			}
			return true
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			last := a[0]
			meet := false
			solved := d-a[n] > limit
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if a[i]-last > limit*2+1 {
						solved = true
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					if i > 1 && !solved {
						solved = a[i]-a[i-2] > limit*2+1
						if solved {
							last = a[i]
						}
					}
				}
			}

			return !meet || solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := false
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if a[i]-last > limit*2+1 {
						solved = true
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return !meet || solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		check := func(limit int64) bool {
			end := d-a[n] > limit
			last := a[0]
			meet := false
			solved := true
			if limit == 3 {
				fmt.Println(end)
			}
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		if n == 1 {
			fmt.Fprintln(out, d-1)
			continue
		}
		a[0] = 0
		check := func(limit int64) bool {
			end := d-a[n] > limit+1
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		a[0] = 0
		check := func(limit int64) bool {
			end := d-a[n] > limit+1
			last := a[0]
			meet := false
			solved := true
			for i := 1; i < n+1; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	_, _ = fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var d int64
		n := 0
		_, _ = fmt.Fscan(in, &n, &d)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		check := func(limit int64) bool {
			first, end := a[0] > limit*2+1, d-a[len(a)-1] > limit+1
			last := int64(0)
			meet := false
			solved := true
			for i := 0; i < n; i++ {
				if a[i]-last > limit {
					if meet && !solved {
						if a[i]-last > limit*2+1 {
							solved = true
						}
					}
					last = a[i]
				} else {
					if meet {
						return false
					}
					meet = true
					var ll int64
					if i < 2 {
						ll = 0
					} else {
						ll = a[i-2]
					}
					solved = first || end || a[i]-ll > limit*2+1
				}
			}
			return solved
		}
		l, h := int64(1), d
		for l < h {
			m := (l + h) / 2
			if check(m) {
				l = m + 1
			} else {
				h = m
			}
		}
		fmt.Fprintln(out, l-1)
	}
}

//  1 2 3 4 5 6
//0 1 1 2 0 4
//1 2 3 4 5 6

package main

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

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

func CF1650E(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		n, d := 0, 0
		fmt.Fscan(in, &n, &d)
		min_gap, min_pos := d, 0
		arr := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]-arr[i-1]-1 < min_gap {
				min_gap, min_pos = arr[i]-arr[i-1]-1, i
			}
		}
		b := []int{}
		for i := 0; i <= n; i++ {
			if i != min_pos {
				b = append(b, arr[i])
			}
		}
		ans := help(b, d)
		if min_pos > 1 {
			b[min_pos-1] = arr[min_pos]
		}
		ans = max(ans, help(b, d))
		fmt.Fprintln(out, ans)
	}
}

func help(b []int, d int) int {
	mx, mm := math.MinInt32, math.MaxInt32
	for i := 1; i < len(b); i++ {
		mx = max(mx, b[i]-b[i-1]-1)
		mm = min(mm, b[i]-b[i-1]-1)
	}
	return min(mm, max(d-b[len(b)-1], (mx-1)/2))
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, d := cin.NextInt(), cin.NextInt()
	a := cin.NextInts(n)
	r := make([]int, n)
	lst := 0
	for i := 0; i < n; i++ {
		r[i] = a[i] - lst - 1
		lst = a[i]
	}
	prefixMinR, suffixMinR := make([]int, n), make([]int, n)
	prefixMinR[0] = r[0]
	for i := 1; i < n; i++ {
		prefixMinR[i] = prefixMinR[i-1]
		if prefixMinR[i] > r[i] {
			prefixMinR[i] = r[i]
		}
	}
	suffixMinR[n-1] = r[n-1]
	for i := n - 2; i >= 0; i-- {
		suffixMinR[i] = suffixMinR[i+1]
		if suffixMinR[i] > r[i] {
			suffixMinR[i] = r[i]
		}
	}
	ans := prefixMinR[n-1]
	// cerr.Println("initAns", ans)
	// cerr.Println("r", r, "prefixMinR", prefixMinR, "suffixMinR", suffixMinR)
	for i := range r {
		// try move the i-th exam yo
		if i+1 < n {
			lo := 0
			if i > 0 {
				lo = a[i-1]
			}
			hi := a[i+1]
			mi := lo + (hi-lo)/2
			cans := mi - lo - 1
			if rio := hi - mi - 1; rio < cans {
				cans = rio
			}
			if i > 0 && prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if i+2 < n && suffixMinR[i+2] < cans {
				cans = suffixMinR[i+2]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Printf("i=%d, lo=%d, hi=%d, mi=%d, cans=%d, ans=%d\n", i, lo, hi, mi, cans, ans)
			// cerr.Printf("move %d: %d\n", i, cans)
		} else {
			cans := d - a[i-1] - 1
			if prefixMinR[i-1] < cans {
				cans = prefixMinR[i-1]
			}
			if cans > ans {
				ans = cans
			}
			// cerr.Printf("move %d: %d\n", i, cans)
		}

	}
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker


package main

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

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

func solve(s int) int {
	var (
		c int
		i = 1
	)
	for ; s >= i; i += 2 {
		c++
		s -= i
	}
	if s > 0 {
		c++
	}
	return c
}

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

package main
import(
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		var ret int = int(math.Sqrt(float64(n)))
		for ret * ret < n {
			ret++
		}
		fmt.Println(ret)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if math.Mod(float64(x),(math.Sqrt(float64(x)))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scan(&t)
	sumOfSize := make([]int, 72, 72)
	for i := 1; i <= 71; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scan(&s)
		fmt.Println(getSize(s))
	}
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
import "math"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()
    t := sint64();
    for i := int64(0); i < t; i++ {
        n := float64(sint64());
        printf("%.0f\n", math.Ceil(math.Sqrt(n)));
    }

}
func resh(n int64) []int64 {
    p := make([]bool, n + 1)
    for i := int64(2); i <= n; i++ {
        p[i] = true
    }
    for i := int64(0); i <= n; i++ {
		if p[i] {
			for j := i * i; j <= n; j += i {
				p[j] = false
				//Print(j, " ")
			}
		}
	}
	ans := make([]int64, 0)
	for i := int64(0); i < n; i++ {
	    if p[i] {
	        ans = append(ans, i)
	    }
	}
	return ans
}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}
func ceil(a, b int64) int64{
    s := a / b
    if a % b >= 0 {
        s++
    }
    if s == 0 {
        s = 1
    }
    return s
}
func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

package main

import ."fmt"
//import "sort"
import "bufio"
import "os"
import "math"
//import "string"
//import "time"
//import ."math"

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

func main() {
    defer writer.Flush()
    t := sint64();
    for i := int64(0); i < t; i++ {
        n := float64(sint64());
        printf("%.0f ", math.Ceil(math.Sqrt(n)));
    }

}
func resh(n int64) []int64 {
    p := make([]bool, n + 1)
    for i := int64(2); i <= n; i++ {
        p[i] = true
    }
    for i := int64(0); i <= n; i++ {
		if p[i] {
			for j := i * i; j <= n; j += i {
				p[j] = false
				//Print(j, " ")
			}
		}
	}
	ans := make([]int64, 0)
	for i := int64(0); i < n; i++ {
	    if p[i] {
	        ans = append(ans, i)
	    }
	}
	return ans
}
func printf(f string, a ...interface{}) {
	Fprintf(writer, f, a...)
}
func sstring() string {
	scanner.Scan()
	return scanner.Text()
}
func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sum(a []int64) int64{
    ans := int64(0)
    for _, i := range a {
        ans += i
    }
    return ans
}
func abs(x int64) int64 {
    if x < 0 {
        return 0 - x
    }
    return x
}
func min(x, y int64) int64 {
    if x < y {
        return x
    }
    return y
}
func ceil(a, b int64) int64{
    s := a / b
    if a % b >= 0 {
        s++
    }
    if s == 0 {
        s = 1
    }
    return s
}
func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1550A
Date: 19/10/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1550/A
Problem: CF1550A
**/
var n = 0

func (in *CF1550A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n = in.NextInt()

		if n < 2 {
			fmt.Println(n)
		} else{
			sol := 2
			aux := 3
			for i := 4; i < n; i+=aux{
				sol++
				aux+=2
			}
			fmt.Println(sol)
		}

	}
}

func f(sum, m int) int {
	if n-sum == 0 {
		return 0
	}
	if n-sum < 0 {
		return -1
	}

	a := f(sum+m+1, m+1)
	b := f(sum+m+2, m+1)
	c := f(sum+m+1, m+2)
	d := f(sum+m+2, m+2)
	e := f(sum+1, m)

	arr := []int{a, b, c, d, e}
	sort.Ints(arr)
	for i := 0; i < len(arr); i++ {
		if arr[i] >= 0 {
			//memo[sum][n] =
			return arr[i] + 1
		}
	}

	return -1
}

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

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

package main

import "fmt"

func main() {
	var tc, s, cnt, i int
	fmt.Scan(&tc)
	for tc > 0 {
		tc = tc - 1
		fmt.Scan(&s)
		var add int
		add = 1
		cnt = 0
		i = 0
		for cnt < s {
			cnt = cnt + add
			add = add + 2
			i = i + 1
		}
		fmt.Println(i)
	}
}

package main

import (
	"fmt"
)

func main() {
	var ans [5050]int
	for i := 1; i < 72; i++ {
		for j := i * i; j > (i-1)*(i-1); j-- {
			ans[j] = i
		}
	}

	var q int
	fmt.Scanln(&q)

	for q > 0 {
		q--

		var x int
		fmt.Scanln(&x)
		fmt.Println(ans[x])
	}
}

package main

import (
	"fmt"
	"math"
)

func beauty(n int) int {
	sqrt := math.Sqrt(float64(n))
	sqrt = math.Ceil(sqrt)
	return int(sqrt)
}

func main() {
	var t int

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var v int
		fmt.Scan(&v)
		fmt.Println(beauty(v))
	}
}

package main

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

var (
	scn  = bufio.NewReader(os.Stdin)
	prnt = bufio.NewWriter(os.Stdout)
)

func solve() {
	var a int
	fmt.Fscan(scn, &a)
	sz := 0
	current := 1
	for a > 0 {
		a -= current
		sz += 1
		current += 2
	}
	fmt.Fprintln(prnt, sz)
}

func main() {
	defer prnt.Flush()
	var t int
	fmt.Fscan(scn, &t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func min(a ...int) int {
	mn := a[0]
	length := len(a)
	for i := 0; i < length; i++ {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}

func max(a ...int) int {
	mx := a[0]
	length := len(a)
	for i := 0; i < length; i++ {
		if a[i] > mx {
			mx = a[i]
		}
	}
	return mx
}

func queue(queue []int, element int) []int {
	queue = append(queue, element)
	return queue
}

func dequeue(queue []int) []int {
	return queue[1:]
}

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

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		pcur,_ := Readln(reader)
		cur,_ := strconv.Atoi(pcur)
		i:=1
		for ((i + 1) *((1+i)/2)) /  2 < cur{
			i+=2
		}

		fmt.Println( (i+1)/2)
	}

}

package main

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

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

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

func factorial(n int64) int64 {
	if n <= 1{
		return 1
	}
	return n * factorial(n - 1)
}

func fibanaci(n int64) int64 {
	if n == 0 {
		return 0
	}
	if n == 1 {
		return 1
	}
	return fibanaci(n - 1) + fibanaci(n - 2)
}

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

func gcd(x, y int64) int64 {
	var l, q int64
	l = max(x, y)
	q = min(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = max(remain, q)
		q = min(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

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

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

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

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

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

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

	return
}

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

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

	return num
}

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

var p int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &p)
	for o := 0; o < p; o++ {
		var s float64
		fmt.Fscan(input,&s)
		if int64(math.Sqrt(s)) * 1000000000 - int64(math.Sqrt(s) * 1000000000) == 0.0{
			fmt.Println(int64(math.Sqrt(s)))
		}else{
			fmt.Println(int64(math.Sqrt(s)) + 1)
		}
	}
}

package main

import "fmt"

func main() {
	arr := []int{}
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var s int
		fmt.Scan(&s)
		x := 1
		for {

			if x*x >= s {
				arr = append(arr, x)
				break
			}
			x++
		}
	}
	for i := 0; i < len(arr); i++ {
		fmt.Println(arr[i])
	}
}

package main
import "fmt"

func main() {
   var t int
   var a int
   fmt.Scanln(&t)
   for t > 0 {
       fmt.Scanln(&a)
       i := 0
       odd := 1
       for a > 0 {
           a -= odd
           i++
           odd += 2
       }
       fmt.Println(i)
       t--
   }
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		n := 0
		fmt.Scanf("%d\n", &n)
		fmt.Println(solve(n))
		t--
	}
}

func solve(n int) int {
	if n == 1 {
		return 1
	}
	s := []int{1, 2}
	for {
		if n-sum(s) < len(s) {
			return len(s)
		}
		s = append(s, s[len(s)-1]+2)
	}

}

func sum(n []int) int {
	sum := 0
	for _, v := range n {
		sum += v
	}
	return sum
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if x==3 || x==5 {
			fmt.Fprintln(out,0)
		} else if math.Mod(float64(x),(math.Sqrt(float64(x)))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
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 x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,1)
		} else if x==3 || x==5 {
			fmt.Fprintln(out,0)
		} else if float64(x)/(math.Sqrt(float64(x))) == 0.0 {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))))
		} else {
			fmt.Fprintln(out,int(math.Sqrt(float64(x)))+1)
		}
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scanf("%d", &t)
	sumOfSize := make([]int, 72, 72)
	for i := 1; i <= 71; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &s)
		fmt.Println(getSize(s))
	}
}

package main

import "fmt"

func main() {
	var t, s int
	fmt.Scanf("%d", &t)
	sumOfSize := make([]int, 5001, 5001)
	for i := 1; i <= 5000; i++ {
		sumOfSize[i] = i*i
	}
	getSize := func(s int) (size int) {
		i := 1
		for sumOfSize[i] < s {
			i++
		}
		return i
	}
	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &s)
		fmt.Println(getSize(s))
	}
}


package main
import (
    "io"
    "os"
    "fmt"
    "bufio"
)
const N int = 1e5+10
const mod int = 998244353
var n, m int
var l, r [55]int
var g, f, dp [N]int

func get(x int) int {
    if x < 0 {
        return 0
    } else {
        return dp[x]
    }
}

func main() {
    var input io.Reader = bufio.NewReader(os.Stdin)
    fmt.Fscan(input, &n)
    fmt.Fscan(input, &m)
    for i := 1; i <= n; i++ {
        fmt.Fscan(input, &l[i])
        fmt.Fscan(input, &r[i])
    }

    for d := m; d >= 1; d-- {
        t := m / d
        for i := 0; i <= t; i++ {
            dp[i] = 1
        }
        for i := 1; i <= n; i++ {
            L := (l[i] + d - 1) / d
            R := r[i] / d + 1
            for j := 1; j <= t; j++ {
                f[j] = ((f[j-1] + get(j-L)) % mod - get(j-R) + mod) % mod
            }
            for j := 0; j <= t; j++ {
                dp[j] = f[j]
            }
        }
        g[d] = dp[t]
    }

    for d := m; d >= 1; d-- {
        for i := 2; i * d <= m; i++ {
            g[d] = (g[d] - g[i*d] + mod) % mod
        }
    }
    fmt.Print(g[1])
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	minR := m
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
		if a[i].r < minR {
			minR = a[i].r
		}
	}
	mu := make([]int8, minR+1)
	mu[1] = 1
	for i := 1; i <= minR; i++ {
		for j := i * 2; j <= minR; j += i {
			mu[j] -= mu[i]
		}
	}

	ans := int64(0)
	sum := make([]int, m+2)
	for mul, mu := range mu {
		if mu == 0 {
			continue
		}
		mm := m / mul
		dp := make([]int, mm+1)
		dp[0] = 1
		for _, p := range a {
			for j := 0; j <= mm; j++ {
				sum[j+1] = (sum[j] + dp[j]) % mod
			}
			l, r := (p.l-1)/mul+1, p.r/mul
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j < r; j++ {
				dp[j] = sum[j-l+1]
			}
			for j := r; j <= mm; j++ {
				dp[j] = (sum[j-l+1] - sum[j-r]) % mod
			}
		}
		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		ans += int64(mu) * res % mod
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	minR := m
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
		if a[i].r < minR {
			minR = a[i].r
		}
	}
	mu := make([]int8, m+1)
	mu[1] = 1
	for i := 1; i <= m; i++ {
		for j := i * 2; j <= m; j += i {
			mu[j] -= mu[i]
		}
	}

	ans := int64(0)
	sum := make([]int, m+2)
	for mul, mu := range mu[:minR+1] {
		if mu == 0 {
			continue
		}
		mm := m / mul
		dp := make([]int, mm+1)
		dp[0] = 1
		for _, p := range a {
			for j := 0; j <= mm; j++ {
				sum[j+1] = (sum[j] + dp[j]) % mod
			}
			l, r := (p.l-1)/mul+1, p.r/mul
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j < r; j++ {
				dp[j] = sum[j-l+1]
			}
			for j := r; j <= mm; j++ {
				dp[j] = (sum[j-l+1] - sum[j-r]) % mod
			}
		}
		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		ans += int64(mu) * res % mod
	}
	Fprint(out, (ans%mod+mod)%mod)
}

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

package main

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

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

	const mx int = 1e5
	mu := [mx + 1]int{1: 1}
	for i := 1; i <= mx; i++ {
		for j := i * 2; j <= mx; j += i {
			mu[j] -= mu[i]
		}
	}

	var n, m int
	Fscan(in, &n, &m)
	a := make([]struct{ l, r int }, n)
	for i := range a {
		Fscan(in, &a[i].l, &a[i].r)
	}

	//n = 50
	//m = 1e5
	//a =   make([]struct{ l, r int }, n)
	//for i := range a {
	//	a[i].l = 1
	//	a[i].r = 1e5
	//}

	ans := int64(0)

	for i := 1; i <= m; i++ {
		if mu[i] == 0 {
			continue
		}
		mul := i

		mm := m / mul

		dp := make([]int, mm+1)
		dp[0] = 1

		sum := make([]int, mm+1)

		for _, p := range a {
			sum[0] = dp[0]
			for j := 1; j <= mm; j++ {
				sum[j] = (sum[j-1] + dp[j]) % mod
			}
			l, r := p.l/mul, p.r/mul
			if p.l%mul > 0 {
				l++
			}
			for j := 0; j < l; j++ {
				dp[j] = 0
			}
			for j := l; j <= mm; j++ {
				dp[j] = sum[j-l]
				if j > r {
					dp[j] = (sum[j-l] - sum[j-r]) % mod
				}
			}
		}

		res := int64(0)
		for _, v := range dp {
			res += int64(v)
		}
		res %= mod

		//Println(i, res)

		ans += int64(mu[i]) * res
	}

	ans = (ans%mod + mod) % mod
	Fprintln(out, ans)
}

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


package main

import (
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, d, m, l int64
	fmt.Fscanf(reader, "%d %d %d %d", &n, &d, &m, &l)
	var pos int64

	step := d
	for ;; pos += step {
		r := pos % m
		if r > l || pos > (n - 1) * m + l {
			fmt.Printf("%d", pos)
			return
		}

		if r == 0 && pos != 0 {
			pos = n * m / pos * pos
			if pos > (n - 1) * m + l {
				fmt.Printf("%d", pos)
				return
			}
		}
	}
}

package main

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

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

const MAX = (10000000 - 1)*(10000000) + (10000000 - 1)

func solve(n, d, m, l int64) int64 {
	ans := d
	for i := int64(0); i < n; i++ {
		l, r := i*m, i*m + l
		if ans < l {
			break
		} else if ans <= r {
			ans += d*((r - ans)/d + 1)
		}
	}

	return ans
}

func main() {
	defer w.Flush()

	var n, d, m, l int64
	fmt.Fscanf(r, "%d %d %d %d", &n, &d, &m, &l)

	fmt.Fprintf(w, "%v", solve(n, d, m, l))
}

package main

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

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

const MAX = (10000000 - 1)*(10000000) + (10000000 - 1)

func solve(n, d, m, l int) int {
	ans := d
	for i := 0; i < n; i++ {
		l, r := i*m, i*m + l
		if ans < l {
			break
		} else if ans <= r {
			ans += d*((r - ans)/d + 1)
		}
	}

	return ans
}

func main() {
	defer w.Flush()

	var n, d, m, l int
	fmt.Fscanf(r, "%d %d %d %d", &n, &d, &m, &l)

	fmt.Fprintf(w, "%v", solve(n, d, m, l))
}

package main

import (
	"bytes"
	"os"
	"io/ioutil"
	"fmt"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, d, m, l int64
	fmt.Fscanf(reader, "%d %d %d %d", &n, &d, &m, &l)
	var pos int64

	step := d
	for ;; pos += step {
		r := pos % m
		if r > l || pos > (n - 1) * m + l {
			fmt.Printf("%d", pos)
			return
		}

		if r == 0 && pos != 0 {
			pos = n * m / pos * pos
		}
	}
}


//http://codeforces.com/problemset/problem/250/C
//C. Movie Critics
// elemzes

package main

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

func Readint(r *bufio.Reader) int32 {
	var c byte = 0
	for {
		c, _ = r.ReadByte()
		if c >= '0' && c <= '9' {
			break
		}
	}
	var ret int32 = 0
	for {
		ret = 10*ret + int32(c-'0')
		c, _ = r.ReadByte()
		if c < '0' || c > '9' {
			break
		}
	}
	return ret
}

func main() {
	var (
		n, k, i, all, p, pp, akt, max, loc int32
		dec                                []int32
		in                                 *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	n = Readint(in)
	k = Readint(in)

	dec = make([]int32, k+1, k+1)
	pp, p = -1, 0 // prevprev and prev block
	all = 0       // all stress (change)
	for i = 0; i < n; i++ {
		akt = Readint(in)
		if akt != p {
			all++
			if akt == pp {
				dec[p] += 2
			} else {
				dec[p] += 1
			}
			pp = p
			p = akt
		}
	}
	dec[akt]++

	max, loc = -1, -1
	for i = 1; i <= k; i++ {
		if dec[i] > max {
			max, loc = dec[i], i
		}
	}
	fmt.Println(loc)
}

//http://codeforces.com/problemset/problem/250/C
//C. Movie Critics
// elemzes

package main

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

func main() {
	var (
		n, k, i, all, p, pp, akt, max, loc int32
		dec                                []int32
		in                                 *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)
	fmt.Fscan(in, &k)
	dec = make([]int32, k+1, k+1)
	pp, p = -1, 0 // prevprev and prev block
	all = 0       // all stress (change)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &akt)
		if akt != p {
			all++
			if akt == pp {
				dec[p] += 2
			} else {
				dec[p] += 1
			}
			pp = p
			p = akt
		}
	}
	dec[akt]++

	max, loc = -1, -1
	for i = 1; i <= k; i++ {
		if dec[i] > max {
			max, loc = dec[i], i
		}
	}
	fmt.Println(loc)
}


package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)
var c, m, p, v float64

func main() {
	defer writer.Flush()
	var t int
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
	fmt.Fscan(reader, &c, &m, &p, &v)
	fmt.Fprintln(writer,  solve(c, m, p))
	}
}

func solve(c, m, p float64) float64 {

	ans := float64(1)
	var mn float64
	if fabs(c) > .00005 {
		mn = fmin(v, c)
	 	if (fabs(m) > .00005) {
			 ans += c * solve(c -mn, m + mn / 2, p + mn / 2)
		 } else {
			 ans += c * solve(c - mn, m, p + mn)
		 }
	}

	if fabs(m) > .00005 {
		mn = fmin(v, m)
		if fabs(c) > .00005 {
			ans += m * solve(c + mn / 2, m - mn, p + mn / 2)

		} else {
			ans += m * solve(c, m - mn, p + mn)
		}
	}
	return ans
}

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

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

func min(nums ...int64) int64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

func fmin(nums ...float64) float64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	*expected += float64(counter) * p * cum

	if c > 1e-9 {
		if c - v > 1e-9 {

			if m > 1e-9 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 1e-9 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 1e-9 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 1e-9 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	if cum < 1e-9 {
		cum = 0
	}

	*expected += float64(counter) * p * cum

	if c > 1e-9 {
		if c - v > 1e-9 {

			if m > 1e-9 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 1e-9 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 1e-9 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 1e-9 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int64, expected *float64, cum float64)  {

	if cum < 1e-9 {
		cum = 0
	}

	*expected += float64(counter) * p * cum

	if c > 0 {
		if c - v > 1e-9 {

			if m > 0 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 0 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m - v > 1e-9 {

			if c > 0 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 0 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}

package main

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

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

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

	for i := 0; i < t; i++ {
		var c, m, p, v float64
		fmt.Fscan(r, &c, &m, &p, &v)

		solve(c, m, p, v)
	}
}

//c + m + p == 1
// 0.1 <= v <= 0.9
func solve(c, m, p, v float64) {

	//(0.2, 0.1, 0.7)  and v= 0.1

	//0.7 + 0.2 * (0.1 , 0.15, 0.75) + 0.1 * (0.25, invalid, 0.75)

	//0.2 * 0.75
	cache := make(map[[3]float64]float64)

	var ans float64 = 0

	state(c, m, p, v , cache, 1, &ans, 1)

	fmt.Printf("%.7f", ans)
	fmt.Println()
}

func state(c, m, p, v float64, cache map[[3]float64]float64, counter int, expected *float64, cum float64)  {

	*expected += float64(counter) * p * cum

	if c > 0 {
		if c > v {

			if m > 0 {
				state(c - v, m + v/2, p + v/2, v, cache, counter + 1, expected,  c * cum)
			} else {
				state(c - v, 0, p + v, v, cache, counter + 1, expected, c * cum)
			}

		} else {

			if m > 0 {
				state(0, m + (c)/2, p + (c)/2, v, cache, counter + 1, expected, c * cum)

			} else {
				state(0, 0, p + (c), v, cache, counter + 1, expected, c * cum)
			}
		}
	}

	if m > 0 {

		if m > v {

			if c > 0 {
				state(c +  v/2, m - v, p + v/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, m - v, p + v, v, cache, counter + 1, expected, m * cum)
			}

		} else {

			if c > 0 {
				state(c + (m)/2, 0, p + (m)/2, v, cache, counter + 1, expected, m * cum)

			} else {
				state(0, 0, p + (m), v, cache, counter + 1, expected, m * cum)
			}
		}
	}
}


package main

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

func main() {
	defer writer.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := ReadInts(n)
		c := ReadInts(n)
		ans := solve(n, a, b, c)
		for i := 0; i < n; i++ {
			if i > 0 {
				Printf(" ")
			}
			Printf("%d", ans[i])
		}
		Println()
	}
}

func solve(n int, a, b, c []int) []int {
	ret := make([]int, n)
	dfs(0, n, a, b, c, ret)
	return ret
}

func dfs(depth int, n int, a, b, c []int, prefix []int) bool {
	if depth == n {
		return prefix[0] != prefix[n-1]
	}
	for i := 0; i < 3; i++ {
		v := a[depth]
		if i == 1 {
			v = b[depth]
		} else if i == 2 {
			v = c[depth]
		}
		if depth > 0 && prefix[depth-1] == v {
			continue
		}
		prefix[depth] = v
		if dfs(depth+1, n, a, b, c, prefix) {
			return true
		}
	}
	return false
}

var reader = bufio.NewReader(os.Stdin)

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

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

package main

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

func ReadInt(scanner *bufio.Scanner) int {
	if !scanner.Scan() {
		panic("cant scan")
	}
	str := scanner.Text()
	n, _ := strconv.Atoi(str)
	return n
}

func ReadIntArray(scanner *bufio.Scanner) []int {
	if !scanner.Scan() {
		panic("cant scan")
	}
	str := scanner.Text()
	tokens := strings.Split(str, " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int, writer *bufio.Writer) {
	strArray := fmt.Sprint(arr)
	_, _ = writer.WriteString(strArray[1:len(strArray)-1])
	_, _ =writer.Write([]byte{'\n'})
	_ = writer.Flush()
}

func Solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer, writer)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner, writer)
	}
}

package main

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

func main() {
	defer writer.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := ReadInts(n)
		c := ReadInts(n)
		ans := solve(n, a, b, c)
		for i := 0; i < n; i++ {
			if i > 0 {
				Printf(" ")
			}
			Printf("%d", ans[i])
		}
		Println()
	}
}

func solve(n int, a_, b_, c_ []int) []int {
	var a [3][]int
	a[0] = a_
	a[1] = b_
	a[2] = c_
	ret := make([]int, n)
	ret[0] = a[0][0]
	for i := 1; i < n-1; i++ {
		for j := 0; j < 3; j++ {
			if ret[i-1] != a[j][i] {
				ret[i] = a[j][i]
				break
			}
		}
	}
	for i := 0; i < 3; i++ {
		if ret[n-2] != a[i][n-1] && ret[0] != a[i][n-1] {
			ret[n-1] = a[i][n-1]
			break
		}
	}
	return ret
}

var reader = bufio.NewReader(os.Stdin)

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

var writer = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := readIntArray(n)
		res := make([]int, n)
		res[0] = a[0]
		for j := 1; j < n; j++ {
			prev := res[j-1]
			cur := 0
			if j == n - 1 {
				if prev != a[j] && res[0] != a[j]{
					cur = a[j]
				} else if prev != b[j] && res[0] != b[j]{
					cur = b[j]
				} else if prev != c[j] && res[0] != c[j]{
					cur = c[j]
				}
			} else {
				if prev != a[j] {
					cur = a[j]
				} else if prev != b[j] {
					cur = b[j]
				} else if prev != c[j] {
					cur = c[j]
				}
			}
			res[j] = cur
		}
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(res[j])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 1; kk <= nt; kk++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		var a = make([]int, n)
		var b = make([]int, n)
		var c = make([]int, n)

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

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

		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &c[i])
		}
		fmt.Fscanf(reader, "\n")

		for i := 0; i < n; i++ {
			var tmp = make([]int, 0)
			tmp = append(tmp, a[i])
			tmp = append(tmp, b[i])
			tmp = append(tmp, c[i])
			sort.Ints(tmp)
			a[i] = tmp[0]
			b[i] = tmp[1]
			c[i] = tmp[2]
		}

		var first = a[0]
		var current = a[0]
		fmt.Fprintf(writer, "%d ", first)
		for i := 1; i < n; i++ {
			if i < n - 1 {
				if a[i] != current {
					current = a[i]
				} else if b[i] != current {
					current = b[i]
				} else {
					current = c[i]
				}
			} else {
				if a[i] != current && first != a[i] {
					current = a[i]
				} else if b[i] != current && first != b[i] {
					current = b[i]
				} else {
					current = c[i]
				}
			}
			fmt.Fprintf(writer, "%d ", current)
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	n := nextInt()
	arr := [3][]int{make([]int, n), make([]int, n), make([]int, n)}
	for _, v := range arr {
		for j := range v {
			v[j] = nextInt()
		}
	}
	first := -1
	prev := -1
	for i := range arr[0] {
		for j := range arr {
			if arr[j][i] != prev && (i != n-1 || arr[j][i] != first) {
				printf("%d ", arr[j][i])
				prev = arr[j][i]
				if first == -1 {
					first = arr[j][i]
				}
				break
			}
		}
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != n {
				if arr[i] == arr[i+1] {
					arr[i] = x
				}
			} else {
				if arr[1] == arr[n] {
					arr[n] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	n := nextInt()
	arr := [3][]int{make([]int, n), make([]int, n), make([]int, n)}
	for _, v := range arr {
		for j := range v {
			v[j] = nextInt()
		}
	}
	prev := -1
	for i := range arr[0] {
		for j := range arr {
			if arr[j][i] != prev {
				printf("%d ", arr[j][i])
				prev = arr[j][i]
				break
			}
		}
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for _, x := range arr[1:] {
			fmt.Print(x, ' ')
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != n {
				if arr[i] == arr[i+1] {
					arr[i] = x
				}
			} else {
				if arr[1] == arr[n] {
					arr[n] = x
				}
			}
		}
		for _, i := range arr[1:] {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		t--
	}
}

package main

import "fmt"

func main() {
	t := 0
	fmt.Scan(&t)
	for t > 0 {
		n := 0
		fmt.Scan(&n)
		arr := []int{}
		arr = append(arr, 0)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			if i != 1 {
				if arr[i] == arr[i-1] {
					arr[i] = x
				}
			} else {
				if arr[i] == arr[n] {
					arr[i] = x
				}
			}
		}
		fmt.Println(arr[1:])
		t--
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, _ := scanner.ReadString('\n')
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, _ := scanner.ReadString('\n')
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int) {
	strArray := fmt.Sprint(arr)
	fmt.Println(strArray[1:len(strArray)-1])
}

func Solve(scanner *bufio.Reader) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner)
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int) {
	strArray := fmt.Sprint(arr)
	fmt.Println(strArray[1:len(strArray)-1])
}

func Solve(scanner *bufio.Reader) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner)
	}
}

package main

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

func ReadInt(scanner *bufio.Reader) int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	n, _ := strconv.Atoi(str[:len(str)-1])
	return n
}

func ReadIntArray(scanner *bufio.Reader) []int {
	str, err := scanner.ReadString('\n')
	if err != nil {
		panic(err)
	}
	tokens := strings.Split(str[:len(str)-1], " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int, writer *bufio.Writer) {
	strArray := fmt.Sprint(arr)
	_, _ = writer.WriteString(strArray[1:len(strArray)-1])
	_, _ =writer.Write([]byte{'\n'})
	_ = writer.Flush()
}

func Solve(scanner *bufio.Reader, writer *bufio.Writer) {
	n := ReadInt(scanner)
	a := ReadIntArray(scanner)
	b := ReadIntArray(scanner)
	c := ReadIntArray(scanner)
	answer := make([]int, n)
	for i := 0; i < n; i++ {
		next := (i + 1) % n
		prev := (i - 1 + n) % n
		if a[i] != answer[next] && a[i] != answer[prev] {
			answer[i] = a[i]
		} else if b[i] != answer[next] && b[i] != answer[prev] {
			answer[i] = b[i]
		} else {
			answer[i] = c[i]
		}
	}
	PrintIntArray(answer, writer)
}

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner, writer)
	}
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := readIntArray(n)
		res := make([]int, n)
		res[0] = a[0]
		for j := 1; j < n; j++ {
			prev := res[j-1]
			cur := 0
			if j == n - 1 {
				if prev != a[j] && a[0] != a[j]{
					cur = a[j]
				} else if prev != b[j] && c[0] != c[j]{
					cur = b[j]
				} else if prev != c[j] && c[0] != c[j]{
					cur = c[j]
				}
			} else {
				if prev != a[j] {
					cur = a[j]
				} else if prev != b[j] {
					cur = b[j]
				} else if prev != c[j] {
					cur = c[j]
				}
			}
			res[j] = cur
		}
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(res[j])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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


package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

const N = 100010

var closest [N]int

const INF = math.MaxInt64

func solve(A []int, k int) int {
	ps := make([]int, N)

	n := len(A)

	for i := 0; i < n; i++ {
		pv := 1 << 30
		for j := 1; j <= min2(A[i], k); j = (A[i] / (A[i] / j)) + 1 {
			nv := A[i] / j
			ps[nv+1] = max(ps[nv+1], pv)
			pv = nv
		}
		ps[0] = max(ps[0], pv)
	}

	ans := 1 << 30
	var cm int
	for i := 0; i <= A[0]; i++ {
		cm = max(cm, ps[i])
		ans = min2(ans, cm-i)
	}

	return ans
}

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

func solve1(A []int, k int) int {
	n := len(A)
	if n == 1 {
		return 0
	}

	arr := make([]int, n+1)
	copy(arr[1:], A)

	arr[0] = -1

	fill := func(s int, e int, v int) {
		for i := s; i < e; i++ {
			closest[i] = v
		}
	}

	for i := 1; i <= n; i++ {
		fill(arr[i-1]+1, arr[i]+1, arr[i])
	}

	fill(arr[n]+1, N, INF)

	v := make([]Pair, 2*k)

	var end int

	push := func(x Pair) {
		v[end] = x
		end++
	}

	back := func() Pair {
		return v[end-1]
	}

	var ans int64 = INF

	for mx := 1; mx <= 100000; mx++ {
		end = 0
		push(Pair{1, int64(mx)})
		for i := 2; i <= k; i++ {
			push(Pair{back().second + 1, int64(mx+1)*int64(i) - 1})
			if back().second > int64(arr[n]) {
				break
			}
		}
		if back().second >= int64(arr[n]) {
			var mn int64 = INF
			for i := 0; i < end; i++ {
				nxt := int64(closest[v[i].first])
				if nxt <= v[i].second {
					mn = min(mn, nxt/int64(i+1))
				}
			}
			ans = min(ans, int64(mx)-mn)
		}
	}

	return int(ans)
}

type Pair struct {
	first  int64
	second int64
}

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

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

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

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

const N = 100010

var closest [N]int

const INF = math.MaxInt64

func solve(A []int, k int) int {
	n := len(A)
	if n == 1 {
		return 0
	}

	arr := make([]int, n+1)
	copy(arr[1:], A)

	arr[0] = -1

	fill := func(s int, e int, v int) {
		for i := s; i < e; i++ {
			closest[i] = v
		}
	}

	for i := 1; i <= n; i++ {
		fill(arr[i-1]+1, arr[i]+1, arr[i])
	}

	fill(arr[n]+1, N, INF)

	v := make([]Pair, 2*k)

	var end int

	push := func(x Pair) {
		v[end] = x
		end++
	}

	back := func() Pair {
		return v[end-1]
	}

	var ans int64 = INF

	for mx := 1; mx <= 100000; mx++ {
		end = 0
		push(Pair{1, int64(mx)})
		for i := 2; i <= k; i++ {
			push(Pair{back().second + 1, int64(mx+1)*int64(i) - 1})
			if back().second > int64(arr[n]) {
				break
			}
		}
		if back().second >= int64(arr[n]) {
			var mn int64 = INF
			for i := 0; i < end; i++ {
				nxt := int64(closest[v[i].first])
				if nxt <= v[i].second {
					mn = min(mn, nxt/int64(i+1))
				}
			}
			ans = min(ans, int64(mx)-mn)
		}
	}

	return int(ans)
}

type Pair struct {
	first  int64
	second int64
}

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	ge := [1e5 + 1]int{}
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		up := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := up + 1; i <= v; i++ {
				ge[i] = v
			}
			up = v
		}
		if up <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := up / k; mx <= up; mx++ {
			mi := mx
			for j := 1; (j-1)*(mx+1) <= up; j++ {
				v := ge[(j-1)*(mx+1)]
				if v >= j*(mx+1) {
					j = v/(mx+1) + 1
				}
				if v/j < mi {
					mi = v / j
					if mx-mi >= ans {
						continue o
					}
				}
			}
			ans = mx - mi
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	ge := [1e5 + 1]int{}
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		up := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := up + 1; i <= v; i++ {
				ge[i] = v
			}
			up = v
		}
		if up <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := up / k; mx <= up; mx++ {
			mi := mx
			for j := 1; (j-1)*(mx+1) <= up; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= j*(mx+1) {
					j = v/(mx+1) + 1
				}
				if v/j < mi {
					mi = v / j
					if mx-mi >= ans {
						continue o
					}
				}
			}
			ans = mx - mi
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	ge := [1e5 + 1]int{}
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		up := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := up + 1; i <= v; i++ {
				ge[i] = v
			}
			up = v
		}
		if up <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := up / k; mx <= up; mx++ {
			mi := mx
			for j := 1; (j-1)*(mx+1) <= up; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= j*(mx+1) {
					continue
				}
				if v/j < mi {
					mi = v / j
					if mx-mi >= ans {
						continue o
					}
				}
			}
			ans = mx - mi
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [1e5 + 1]int{}
		up := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := up + 1; i <= v; i++ {
				ge[i] = v
			}
			up = v
		}
		if up <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := up / k; mx <= up; mx++ {
			mi := int(1e9)
			for j := 1; (j-1)*(mx+1) <= up; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= j*(mx+1) {
					continue
				}
				if v/j < mi {
					mi = v / j
					if mx-mi >= ans {
						continue o
					}
				}
			}
			ans = min(ans, mx-mi)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 1<<12)
	_i := len(buf)
	rc := func() byte {
		if _i >= len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := r(); T > 0; T-- {
		n, k := r(), r()
		ge := [1e5 + 1]int{}
		MX := -1
		for ; n > 0; n-- {
			v := r()
			for i := MX + 1; i <= v; i++ {
				ge[i] = v
			}
			MX = v
		}
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; (j-1)*(mx+1) <= MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
				if mx-mi >= ans {
					continue o
				}
			}
			ans = min(ans, mx-mi)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	const MX int = 1e5
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [MX + 1]int{}
		MX := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := MX + 1; i <= v; i++ {
				ge[i] = v
			}
			MX = v
		}
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; (j-1)*(mx+1) <= MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
				if mx-mi >= ans {
					continue o
				}
			}
			ans = min(ans, mx-mi)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	const MX int = 1e5
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [MX + 1]int{}
		MX := -1
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := MX + 1; i <= v; i++ {
				ge[i] = v
			}
			MX = v
		}
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
		ans := int(1e9)
	o:
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; j <= k && (j-1)*(mx+1) <= MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
				if mx-mi >= ans {
					continue o
				}
			}
			ans = min(ans, mx-mi)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	const MX int = 1e5
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [MX + 1]int{}
		pre := 0
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := pre; i <= v; i++ {
				ge[i] = v
			}
			pre = v + 1
		}
		ans := int(1e9)
		MX := pre - 1
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
	o:
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; j <= k && (j-1)*(mx+1) < MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
				if mx-mi >= ans {
					continue o
				}
			}
			if mi <= mx {
				ans = min(ans, mx-mi)
			}
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	const MX int = 1e5
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [MX + 1]int{}
		pre := 0
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := pre; i <= v; i++ {
				ge[i] = v
			}
			pre = v + 1
		}
		ans := int(1e9)
		MX := pre - 1
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; j <= k && (j-1)*(mx+1) < MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
			}
			if mi <= mx {
				ans = min(ans, mx-mi)
			}
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1706D2(_r io.Reader, out io.Writer) {
	const MX int = 1e5
	in := bufio.NewReader(_r)
	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ge := [MX + 1]int{}
		pre := 0
		for ; n > 0; n-- {
			Fscan(in, &v)
			for i := pre; i <= v; i++ {
				ge[i] = v
			}
			pre = v + 1
		}
		ans := int(1e9)
		MX := pre - 1
		if MX <= k {
			Fprintln(out, 0)
			continue
		}
		for mx := MX / k; mx <= MX; mx++ {
			mi := int(1e9)
			for j := 1; j <= k && (j-1)*(mx+1) < MX; j++ {
				v := ge[(j-1)*(mx+1)]
				if v == 0 {
					break
				}
				if v >= min(j*(mx+1), MX+1) {
					continue
				}
				mi = min(mi, v/j)
			}
			ans = min(ans, mx-mi)
		}
		Fprintln(out, ans)
	}
}

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

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