// https://codeforces.com/problemset/problem/1684/A

// 1684A. Digit Minimization

// There is an integer n without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.
// On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.
// You have to find the smallest integer Alice can get in the end, if she plays optimally.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤10^4) — the number of test cases. Description of the test cases follows.
// The first and the only line of each test case contains the integer n (10≤n≤10^9) — the integer for the game. n does not have zeros in its decimal representation.

// Output
// For each test case output a single integer — the smallest integer Alice can get in the end of the game.

// Example
// input
// 3
// 12
// 132
// 487456398
// output
// 2
// 1
// 3

// Note

// In the first test case Alice has to swap 1 and 2. After that Bob removes the last digit, 1, so the answer is 2.
// In the second test case Alice can swap 3 and 1: 312. After that Bob deletes the last digit: 31. Then Alice swaps 3 and 1: 13 and Bob deletes 3, so the answer is 1.

// Tutorial

// Let k be the length of n. Let ni be the i-th digit of n (1-indexation from the left).
//  • k=1
//    The game ends immediately so the answer is n itself.
//  • k=2
//    Alice should make the first move and she has to swap n1 and n2. After that Bob removes n1 and in the end there is only n2.
//  • k≥3
//    Alice can make swaps in such way that when there are only two digits left the second digit will be the maximal digit of n. Then she will make a swap and the maximal digit will be on the first position. The other one will be removed by Bob. This way she can always get the maximal digit of n in the end of the game.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, i int
	var t uint
	var n string
	var ans byte

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)

			if len(n) == 2 {
				ans = n[1]
			} else {
				ans = n[0]

				for i = 1; i < len(n); i++ {
					if ans > n[i] {
						ans = n[i]
					}
				}
			}

			fmt.Fprintln(writer, ans-'0')
		}
	}

	writer.Flush()
}

package main

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

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

func slove() {
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	ans := s[0]
	if len(s) == 2 {
		fmt.Fprintln(w, string(s[1]))
	} else {
		for i := range s {
			ans = min(ans, s[i])
		}
		fmt.Fprintln(w, string(ans))
	}
}

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

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

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		if n < 99 {
			Fprintln(out, n%10)
		} else {
			var min = 10
			for n > 0 {
				if n%10 < min {
					min = n % 10
				}
				n /= 10
			}
			Fprintln(out, min)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main
import(
    "fmt"
    "bufio"
    "os"
    "strconv"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		if len(word) == 2 {
			fmt.Fprintln(out,string(word[1]))
		} else {
			smallest:=0
			for j:=0;j<len(word);j++{
				x,_:= strconv.Atoi(string(word[j]))
				if j==0{
					smallest=x
				} else {
					if x <= smallest {
						smallest=x
					}
				}
			}
			fmt.Fprintln(out,smallest)
		}
	}
}

package main

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

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

func main() {

	var n int
	fmt.Fscan(in, &n)
	for 0 < n {
		n--
		solve()
	}
	defer out.Flush()
}

func solve() {
	var s string
	var min int64
	min = math.MaxInt64
	fmt.Fscan(in, &s)
	for i := 0; i < len(s); i++ {
		l, _ := strconv.ParseInt(string(s[i]), 0, 0)
		min = Min(min, l)
	}
	if len(s) == 2 {
		fmt.Fprintln(out, string(s[1]))
	} else {
		fmt.Fprintln(out, min)
	}
}

func Min(a int64, b int64) int64 {

	if a > b {
		return b
	}
	return a
}

package main

import "fmt"

func solve() {
	var n int64
	fmt.Scan(&n)
	if n < 100 {
		fmt.Println(n % 10)
		return
	}
	result := int64(9)
	for n > 0 {
		cur := n % 10
		n /= 10
		if cur < result {
			result = cur
		}
	}
	fmt.Println(result)
}

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1684A
Date: 21/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1684/A
Problem: CF1684A
**/
func (in *CF1684A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		ans := -1
		if len(str) == 2 {
			ans = int(str[len(str)-1]-'0')
		}else {
			for i:=0;i<len(str);i++{
				if ans == -1 {
					ans = int(str[i]-'0')
				}else if ans >  int(str[i]-'0'){
					ans = int(str[i]-'0')
				}
			}
		}
		fmt.Println(ans)
	}
}

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

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

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		sml := rune('9')
		for i := 0; i < len(s); i++ {
			if rune(s[i]) < sml {
				sml = rune(s[i])
			}
		}

		if len(s) > 2 {
			fmt.Println(string(sml))
		} else {
			fmt.Println(string(s[len(s)-1]))
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		s := io.ReadString()
		if len(s) == 2 {
			fmt.Println(int(s[1] - byte('0')))
			continue
		}
		mn := 10
		for i := 0; i < len(s); i++ {
			mn = min(mn, int(s[i]-byte('0')))
		}
		fmt.Println(mn)
		//abc := io.ReadIntSlice(3)
		//fmt.Println(abc[0], abc[1], abc[0]+abc[2])
	}
}

package main

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

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

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

		x := s[len(s)-1]
		for i := 0; i < len(s)-1; i++ {
			if s[i] < x {
				x = s[i]
			}
		}

		if len(s) <= 2 {
			fmt.Fprintln(out, s[1]-'0')
		} else {
			fmt.Fprintln(out, x-'0')
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var s string
		Fscan(in, &s)
		if len(s) == 2 {
			Fprintln(out, s[1]-'0')
		} else {
			mi := '9'
			for _, ch := range s {
				if mi > ch {
					mi = ch
				}
			}
			Fprintln(out, mi-'0')
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

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

		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		min := k[0]
		for i := 0; i < len(k); i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	// two digit number -- forced to take rightmost digit
	// three digit number -- can get left or right but not middle
	// four digit number -- can get any of the digits
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); ansarr := make([]byte,1)
		if len(s) == 2 {
			ansarr[0] = s[1]
		} else {
			ansarr[0] = s[0]
			for _,c := range s { if byte(c) < ansarr[0] { ansarr[0] = byte(c) } }
		}
		fmt.Fprintln(wrtr,string(ansarr))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

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

		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		if len(k) == 3 {
			if k[0] > k[1] {
				fmt.Println(string(k[1]))
			} else {
				fmt.Println(string(k[0]))
			}
			continue
		}
		min := k[0]
		for i := 0; i < len(k); i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()
		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		min := k[0]
		for i := 0; i < len(k)-1; i++ {
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n uint64
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := uint64(0); i < n; i++ {
		scanner.Scan()
		k := scanner.Text()
		if len(k) == 2 {
			fmt.Println(string(k[1]))
			continue
		}
		fmt.Println(">>>", k)
		min := k[0]
		for i := 0; i < len(k)-1; i++ {
			fmt.Printf("%d=%c,", i, k[i])
			if k[i] < min {
				min = k[i]
			}
		}
		fmt.Println(string(min))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	// two digit number -- forced to take rightmost digit
	// three digit number -- can get left or right but not middle
	// four digit number -- can get any of the digits
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); ans := "0"
		if len(s) == 2 {
			ans = s[1:2]
		} else if len(s) == 3 {
			ans = s[0:1]
			if s[2:3] < ans { ans = s[2:3] }
		} else {
			ans = "9"
			for i:=0;i<len(s);i++ {
				if s[i:i+1] < ans { ans = s[i:i+1] }
			}
		}
		fmt.Fprintln(wrtr,ans)
	}

}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	//Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		if n < 99 {
			Fprintln(out, n%10)
		} else {
			var min = 10
			for n > 0 {
				if n%10 < min {
					min = n % 10
				}
				n /= 10
			}
			Fprintln(out, min)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }


package main

import "bufio"
import "os"
import "strconv"

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

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fee := make(map[int64]int64)

	q := readInt()
	for i := 0; i < q; i++ {
		cat := readInt()
		u := readInt64()
		v := readInt64()
		if cat == 1 {
			w := readInt64()
			for u != v {
				if u < v {
					u, v = v, u
				}
				fee[u] += w
				u >>= 1
			}
		} else {
			sum := int64(0)
			for u != v {
				if u < v {
					u, v = v, u
				}
				sum += fee[u]
				u >>= 1
			}
			write(sum)
		}
	}
}

// Input and Output
var in *bufio.Scanner
var out *bufio.Writer

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

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

func readInt64() int64 {
	in.Scan()
	val, _ := strconv.ParseInt(in.Text(), 10, 64)
	return val
}

func readFloat64() float64 {
	in.Scan()
	val, _ := strconv.ParseFloat(in.Text(), 64)
	return val
}

func write(args ...interface{}) {
	for i, e := range args {
		switch e.(type) {
		case string:
			out.WriteString(e.(string))
		case int:
			out.WriteString(strconv.Itoa(e.(int)))
		case int64:
			out.WriteString(strconv.FormatInt(e.(int64), 10))
		case float64:
			out.WriteString(strconv.FormatFloat(e.(float64), 'f', -1, 64))
		case []string:
			a := e.([]string)
			for j, x := range a {
				out.WriteString(x)
				if j+1 < len(a) {
					out.WriteByte(' ')
				}
			}
		case []int:
			a := e.([]int)
			for j, x := range a {
				out.WriteString(strconv.Itoa(x))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []int64:
			a := e.([]int64)
			for j, x := range a {
				out.WriteString(strconv.FormatInt(x, 10))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []float64:
			a := e.([]float64)
			for j, x := range a {
				out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		default:
			out.WriteString("###")
		}
		if i+1 < len(args) {
			out.WriteByte(' ')
		}
	}
	out.WriteByte('\n')
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func commonAncestor(a, b int64) int64 {
  ap := int64(1)
  for (ap << 1) <= a {
    ap <<= 1
  }
  bp := int64(1)
  for (bp << 1) <= b {
    bp <<= 1
  }
  x := int64(0)
  for ap != 0 && bp != 0 && ((a & ap == 0) == (b & bp == 0)) {
    x <<= 1
    if (a & ap != 0) {
      x |= 1
    }
    ap >>= 1
    bp >>= 1
  }
  return x
}

func intersectionSize(s, t *Segment) int64 {
  size := int64(0)
  y := commonAncestor(s.v, t.v)
  x := s.u
  if t.u > x {
    x = t.u
  }
  for y > x {
    size++
    y >>= 1
  }
  return size
}

type Segment struct {
  u, v int64
}

type Toll struct {
  segment *Segment
  cost int64
}

func makeSegments(a, b int64) []*Segment {
  x := commonAncestor(a, b)
  if x == a {
    return []*Segment{ &Segment{ a, b } }
  }
  if x == b {
    return []*Segment{ &Segment{ b, a } }
  }
  return []*Segment{ &Segment{ x, a }, &Segment{ x, b } }
}

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

  qNum := getI64()
  tolls := []*Toll{}
  for i := int64(0); i < qNum; i++ {
    q := getI64()
    segments := makeSegments(getI64(), getI64())
    if q == 1 {
      cost := getI64()
      for _, segment := range segments {
        tolls = append(tolls, &Toll{ segment, cost })
      }
    } else {
      cost := int64(0)
      for _, segment := range segments {
        for _, toll := range tolls {
          cost += intersectionSize(segment, toll.segment) * toll.cost
        }
      }
      writer.WriteString(fmt.Sprintf("%d\n", cost))
    }
  }
}

package main

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

func main() {
	q := getInt()
	m := map[int64]int64{}
	buf := &bytes.Buffer{}
	for i := 0; i < q; i++ {
		typ := getInt()
		v := getInt64()
		u := getInt64()
		switch typ {
		case 1:
			w := getInt64()
			for u != v {
				if u < v {
					u, v = v, u
				}
				m[u] += w
				u /= 2
			}
		case 2:
			var w int64
			for u != v {
				if u < v {
					u, v = v, u
				}
				w += m[u]
				u /= 2
			}
			fmt.Fprintf(buf, "%v\n", w)
		}
	}
	io.Copy(os.Stdout, buf)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getInt64() int64 {
	globalInput.Scan()
	x, _ := strconv.ParseInt(globalInput.Text(), 10, 64)
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}

package main

import "bufio"
import "os"
import "strconv"

var fee map[int64]int64

func height(v int64) int {
	h := 0
	for x := int64(1); x <= v; x <<= 1 {
		h++
	}
	return h
}

func add(u int64, w int64) {
	_, found := fee[u]
	if found {
		fee[u] += w
	} else {
		fee[u] = w
	}
}

func get(u int64) int64 {
	f, found := fee[u]
	if found {
		return f
	}
	return 0
}

func update(u int64, v int64, w int64) {
	hu := height(u)
	hv := height(v)
	if hu < hv {
		u, v = v, u
		hu, hv = hv, hu
	}
	pu := u >> 1
	for hu > hv {
		add(u, w)
		u = pu
		pu = u >> 1
		hu--
	}
	pv := v >> 1
	for u != v {
		add(u, w)
		add(v, w)
		u = pu
		pu = u >> 1
		hu--
		v = pv
		pv = v >> 1
		hv--
	}
}

func query(u int64, v int64) int64 {
	sum := int64(0)
	hu := height(u)
	hv := height(v)
	if hu < hv {
		u, v = v, u
		hu, hv = hv, hu
	}
	pu := u >> 1
	for hu > hv {
		sum += get(u)
		u = pu
		pu = u >> 1
		hu--
	}
	pv := v >> 1
	for u != v {
		sum += get(u)
		sum += get(v)
		u = pu
		pu = u >> 1
		hu--
		v = pv
		pv = v >> 1
		hv--
	}
	return sum
}

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

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	fee = make(map[int64]int64)

	q := readInt()
	for i := 0; i < q; i++ {
		cat := readInt()
		u := readInt64()
		v := readInt64()
		if cat == 1 {
			w := readInt64()
			update(u, v, w)
		} else {
			write(query(u, v))
		}
	}
}

// Input and Output
var in *bufio.Scanner
var out *bufio.Writer

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

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

func readInt64() int64 {
	in.Scan()
	val, _ := strconv.ParseInt(in.Text(), 10, 64)
	return val
}

func readFloat64() float64 {
	in.Scan()
	val, _ := strconv.ParseFloat(in.Text(), 64)
	return val
}

func write(args ...interface{}) {
	for i, e := range args {
		switch e.(type) {
		case string:
			out.WriteString(e.(string))
		case int:
			out.WriteString(strconv.Itoa(e.(int)))
		case int64:
			out.WriteString(strconv.FormatInt(e.(int64), 10))
		case float64:
			out.WriteString(strconv.FormatFloat(e.(float64), 'f', -1, 64))
		case []string:
			a := e.([]string)
			for j, x := range a {
				out.WriteString(x)
				if j+1 < len(a) {
					out.WriteByte(' ')
				}
			}
		case []int:
			a := e.([]int)
			for j, x := range a {
				out.WriteString(strconv.Itoa(x))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []int64:
			a := e.([]int64)
			for j, x := range a {
				out.WriteString(strconv.FormatInt(x, 10))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []float64:
			a := e.([]float64)
			for j, x := range a {
				out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		default:
			out.WriteString("###")
		}
		if i+1 < len(args) {
			out.WriteByte(' ')
		}
	}
	out.WriteByte('\n')
}


package main

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

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

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

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

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

		var n, x, y, flips, dis, res int
		fmt.Fscan(r, &n, &x, &y)

		var a, b []byte
		fmt.Fscan(r, &a, &b)

		var adj bool
		dis = n
		for i := range a {
			if a[i] != b[i] {
				flips++

				if i < n-1 && a[i+1] != b[i+1] {
					adj = true
					dis = min(dis, max(i, n-2-i))
				}
			}
		}

		if flips % 2 == 1 {
			res = -1
		} else if flips == 2 && adj {
			if n < 4 {
				res = x
			} else if dis < 2 {
				res = min(x, 3*y)
			} else {
				res = min(x, 2*y)
			}
		} else {
			res = y * flips / 2
		}

		fmt.Fprintln(w, res)

	}

}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		r := -1
		l := -1
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				differ_count++
				if l == -1 {
					l = i
				}
				r = i
			}
		}

		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if differ_count == 2 {
			if l+1 == r {
				if (y * 2) < x {
					fmt.Println(y * 2)
				} else {
					fmt.Println(x)
				}
			} else {
				fmt.Println(y)
			}
			continue
		}

		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		r := -1
		l := -1
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				differ_count++
				if l == -1 {
					l = i
				}
				r = i
			}
		}

		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if differ_count == 2 {
			if l+1 == r {
				if (y * 2) < x {
					fmt.Println(y * 2)
				} else {
					fmt.Println(x)
				}
			} else {
				if (x * uint64(r-l)) < y {
					fmt.Println(x * uint64(r-l))
				} else {
					fmt.Println(y)
				}
			}
			continue
		}

		fmt.Println(differ_count / 2 * y)
	}
}

package main

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

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

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

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

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

		var n, x, y, flips, res int
		fmt.Fscan(r, &n, &x, &y)

		var a, b []byte
		fmt.Fscan(r, &a, &b)

		var adj bool
		for i := range a {
			if a[i] != b[i] {
				flips++

				if i < n-1 && a[i+1] != b[i+1] {
					adj = true
				}
			}
		}

		if flips % 2 == 1 {
			res = -1
		} else if n < 4 && adj {
			res = x
		} else if flips == 2 && adj {
			res = min(x, 2*y)
		} else {
			res = y * flips / 2
		}

		fmt.Fprintln(w, res)

	}

}

package main

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

var a, b string

var diff [100005]bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for cs := 0; cs < T; cs++ {
		var n int
		var x, y int
		fmt.Fscan(in, &n, &x, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		sum := 0
		flag := false
		for i := 0; i < n; i++ {
			diff[i] = (a[i] != b[i])
			if diff[i] {
				sum++
				if i > 0 && diff[i-1] {
					flag = true
				}
			}
		}
		if sum%2 == 1 {
			fmt.Fprintln(out, -1)
			continue
		}
		if sum == 2 && flag {
			if x > y*2 {
				fmt.Fprintln(out, y*2)
			} else {
				fmt.Fprintln(out, x)
			}
		} else {
			fmt.Fprintln(out, sum/2*y)
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		y, _ := strconv.Atoi(arr[2])
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		indexes := make([]int, 0)
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				indexes = append(indexes, i)
			}
		}
		ln := len(indexes)
		if ln%2 > 0 {
			fmt.Println(-1)
		} else if ln == 2 {
			if indexes[1]-indexes[0] == 1 {
				min := x
				if 2*y < min {
					min = 2 * y
				}
				fmt.Println(min)
			} else {
				fmt.Println(y)
			}
		} else {
			fmt.Println(ln / 2 * y)
		}
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x uint64
		var y uint64
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		var differ_count uint64
		differ_count = 0
		for r := 0; r < n; r++ {
			if a[r] != b[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}
		if differ_count == 2 {
			if (y * 2) < x {
				fmt.Println(y * 2)
			} else {
				fmt.Println(x)
			}
			continue
		}
		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
)

// https://codeforces.com/problemset/problem/1733/D1

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x int
		var y int
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		differ_count := 0
		for r := 0; r < n; r++ {
			if a[r] != b[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}
		if differ_count == 2 {
			if (y * 2) < x {
				fmt.Println(y * 2)
			} else {
				fmt.Println(x)
			}
			continue
		}
		fmt.Println(differ_count / 2 * y)
	}
}

package main

import (
	"fmt"
	"strings"
)

// https://codeforces.com/problemset/problem/1733/D1

func Run(length int, a []rune, b []rune, currentcost int, costx int, costy int, smallestcost int) int {
	if currentcost >= smallestcost {
		return smallestcost
	}
	for r := 0; r < length; r++ {
		for l := 0; l < r; l++ {
			tmpa := a
			if tmpa[r] == '0' {
				tmpa[r] = '1'
			} else {
				tmpa[r] = '0'
			}
			if tmpa[l] == '0' {
				tmpa[l] = '1'
			} else {
				tmpa[l] = '0'
			}
			newcost := currentcost
			if l == r-1 {
				newcost = currentcost + costx
			} else {
				newcost = currentcost + costy
			}
			if newcost >= smallestcost {
				continue
			}

			if strings.Compare(string(tmpa), string(b)) == 0 && newcost < smallestcost {
				smallestcost = newcost
				continue
			}
			smallestcost = Run(length, tmpa, b, newcost, costx, costy, smallestcost)
		}
	}
	return smallestcost
}

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	for ; num > 0; num-- {
		var n int
		var x int
		var y int
		fmt.Scanf("%d %d %d\n", &n, &x, &y)
		var a string
		var b string
		fmt.Scanf("%s\n", &a)
		fmt.Scanf("%s\n", &b)

		runea := []rune(a)
		runeb := []rune(b)
		differ_count := 0
		for r := 0; r < n; r++ {
			if runea[r] != runeb[r] {
				differ_count++
			}
		}
		if differ_count%2 == 1 {
			fmt.Println(-1)
			continue
		}

		smallest_change_count := differ_count / 2
		tmpa := runea
		tmpb := runeb
		smallest_cost := 0
		for ; smallest_change_count > 0; smallest_change_count-- {
			for r := 0; r < n; r++ {
				if tmpa[r] == tmpb[r] {
					continue
				}
				for l := 0; l < r; l++ {
					if tmpa[l] == tmpb[l] {
						continue
					}
					tmpa[r] = tmpb[r]
					tmpa[l] = tmpb[l]
					if l == r-1 {
						smallest_cost += x
					} else {
						smallest_cost += y
					}
				}
			}

		}
		smallest_cost = Run(n, runea, runeb, 0, x, y, smallest_cost)
		fmt.Println(smallest_cost)
	}
}

package main

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

var a, b string

var diff [100005]bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for cs := 0; cs < T; cs++ {
		var n int
		var x, y int
		fmt.Fscan(in, &n, &x, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		sum := 0
		for i := 0; i < n; i++ {
			diff[i] = (a[i] != b[i])
			if diff[i] {
				sum++
			}
		}
		if sum%2 == 1 {
			fmt.Fprintln(out, -1)
			continue
		}
		if sum == 2 {
			if x > y*2 {
				fmt.Fprintln(out, y*2)
			} else {
				fmt.Fprintln(out, x)
			}
		} else {
			fmt.Fprintln(out, sum/2*y)
		}
	}
}


package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 2 3")
	Scan(&a[0])
	for i := 1; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	a[0] = (a[1] + a[2] - a[0]) / 2
	Print("! ", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, a, b, c, d int
	fmt.Fscanf(bufin, "%d\n", &n)
	x := make([]int, n+1)

	fmt.Fprintf(bufout, "? 1 2\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &a)

	fmt.Fprintf(bufout, "? 2 3\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &b)

	fmt.Fprintf(bufout, "? 3 1\n")
	bufout.Flush()
	fmt.Fscanf(bufin, "%d\n", &c)

	x[1] = (c - b + a) / 2
	x[2] = a - x[1]
	x[3] = b - x[2]
	for i := 4; i <= n; i++ {
		fmt.Fprintf(bufout, "? %d %d\n", i-1, i)
		bufout.Flush()
		fmt.Fscanf(bufin, "%d\n", &d)
		x[i] = d - x[i-1]
	}

	fmt.Fprintf(bufout, "!")
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, " %d", x[i])
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  n := getI()
  values := make([]int, n)
  fmt.Printf("? 1 2\n")
  fmt.Printf("? 2 3\n")
  fmt.Printf("? 1 3\n")
  x, y, z := getI(), getI(), getI()
  a := (x + z - y) / 2
  values[0] = a
  values[2] = z - a
  values[1] = y - values[2]
  for i := 3; i < n; i++ {
    fmt.Printf("? 1 %d\n", i + 1)
    values[i] = getI() - a
  }
  fmt.Printf("!")
  for _, x = range values {
    fmt.Printf(" %d", x)
  }
  fmt.Printf("\n")
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, s12, s13, s23, s int
	Scan(&n)
	Println("? 1 2")
	Scan(&s12)
	Println("? 1 3")
	Scan(&s13)
	Println("? 2 3")
	Scan(&s23)

	a := make([]int, n)
	a[0] = (s12 + s13 - s23) / 2
	a[1] = s12 - a[0]
	a[2] = s13 - a[0]
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&s)
		a[i] = s - a[0]
	}
	Print("!")
	for _, v := range a {
		Print(" ", v)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol727C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)

	var n, s12, s13, s23 int
	Fscan(in, &n)
	Fprintln(out, "? 1 2")
	out.Flush()
	Fscan(in, &s12)
	Fprintln(out, "? 1 3")
	out.Flush()
	Fscan(in, &s13)
	Fprintln(out, "? 2 3")
	out.Flush()
	Fscan(in, &s23)

	ans := make([]int, n)
	ans[0] = (s12 + s13 - s23) / 2
	ans[1] = s12 - ans[0]
	ans[2] = s13 - ans[0]
	for i := 3; i < n; i++ {
		Fprintln(out, Sprintf("? 1 %d", i+1))
		out.Flush()
		var sum int
		Fscan(in, &sum)
		ans[i] = sum - ans[0]
	}
	Fprint(out, "!")
	for _, v := range ans {
		Fprint(out, " ", v)
	}
	out.Flush()
}

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 1 2")
	Scan(&a[0])
	Println("? 1 3")
	Scan(&a[1])
	Println("? 2 3")
	Scan(&a[2])

	a[0] = (a[1] + a[2] - a[0]) / 2
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	Print("! ", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	Scan(&n)
	a := make([]int, n)
	Println("? 1 2")
	Scan(&a[0])
	Println("? 1 3")
	Scan(&a[1])
	Println("? 2 3")
	Scan(&a[2])

	a[0] = (a[1] + a[2] - a[0]) / 2
	for i := 3; i < n; i++ {
		Println(Sprintf("? 1 %d", i+1))
		Scan(&a[i])
	}
	Print("!", a[0])
	for _, v := range a[1:] {
		Print(" ", v-a[0])
	}
}


package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			d := c / 2
			h := hits(l + d)
			if h == a || d == 0 || h == a+1 && (l+d)%x == 0 && (l+d)%y == 0 {
				break
			}
			if h < a {
				l = l + d + 1
				c = c - d - 1
			} else {
				c = c - d
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

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

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

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

func gcd(a, b int64) int64 {
    for a > 0 && b > 0 {
        if a > b {
            a = a % b
        } else {
            b = b % a
        }
    }
    return a + b
}
func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    x := nextInt64()
    y := nextInt64()
    g := gcd(x, y)
    x /= g
    y /= g
    for i := 0; i < n; i++ {
        a := nextInt64() % (x + y)
        if x == y || a == 0 || a == x + y - 1 {
            fmt.Fprintln(out, "Both")
        } else {
            l := int64(1)
            r := x * y
            for l < r {
                m := l + (r - l) / 2
                va := m / y
                vo := m / x
                if va + vo < a {
                    l = m + 1
                } else {
                    r = m
                }
            }

            if r % y == 0 {
                fmt.Fprintln(out, "Vanya")
            } else {
                fmt.Fprintln(out, "Vova")
            }

        }
    }
}

package main

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

func scanInt(scanner *bufio.Scanner) int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, x, y := scanInt(scanner), scanInt(scanner), scanInt(scanner)
	for i := int64(0); i < n; i++ {
    points := scanInt(scanner)
    low, high := int64(0), int64(1) << 60
    for low != high {
      mid := (low+high)/2
      hits := mid / x + mid / y
      if hits < points {
        low = mid+1
      } else {
        high = mid
      }
      //writer.WriteString(fmt.Sprintf("low = %d, high = %d\n", low, high));
    }
    //writer.WriteString(fmt.Sprintf("low = %d\n", low))
    if (low % y == 0) {
      if (low % x == 0) {
        writer.WriteString("Both\n");
      } else {
        writer.WriteString("Vanya\n");
      }
    } else {
        writer.WriteString("Vova\n");
    }
	}
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			var p, q int64
			if x < y {
				p, q = x, y
			} else {
				p, q = y, x
			}
			for h := (hits*p)/(p+q) - 1; h <= (hits*p)/(p+q)+1; h++ {
				if h <= 0 {
					continue
				}
				if h*(p+q)/p == hits {
					if x < y {
						winner = 'x'
					} else {
						winner = 'y'
					}
					break
				}
			}
			if winner == 0 {
				if x < y {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

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

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000)
		for {
			m := l + c/2
			h := hits(m)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = m + 1
				c /= 2
			} else {
				c = c/2 + c%1
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		van := t / x * x
		von := t / y * y
		switch {
		case van > von:
			z = "Vova"
		case von > van:
			z = "Vanya"
		}
		fmt.Println(z)
	}
}

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			if x < y {
				if hits*x%(y+1) == 0 {
					winner = 'x'
				} else {
					winner = 'y'
				}
			} else {
				if hits*y%(x+1) == 0 {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

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

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

var (
	n    int
	x, y int64
	a    []int64
)

func in() {
	read(&n, &x, &y)
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
}

func out() {
	defer output.Flush()
}

func run() {
	cd := gcd(x, y)
	x = x / cd
	y = y / cd
	for i := 0; i < n; i++ {
		hits := a[i] % (x + y)
		var winner rune
		if hits == 0 || hits == (x+y-1) {
			println("Both")
			continue
		} else {
			if x < y {
				if hits%(y/x+1) == 0 {
					winner = 'x'
				} else {
					winner = 'y'
				}
			} else {
				if hits%(x/y+1) == 0 {
					winner = 'y'
				} else {
					winner = 'x'
				}
			}
		}
		if winner == 'x' {
			println("Vanya")
		} else {
			println("Vova")
		}
	}
}

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

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

/** main **/
func main() {
	in()
	run()
	out()
}

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

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

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

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			d := c / 2
			h := hits(l + d)
			if h == a || d == 0 {
				break
			}
			if h < a {
				l = l + d + 1
				c = c - d - 1
			} else {
				c = c - d
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()
	fmt.Println(x, y)

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000)
		for {
			m := l + c/2
			h := hits(m)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = m + 1
				c /= 2
			} else {
				c = c/2 + c%1
			}
		}
		return l + c/2
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		van := t / x * x
		von := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(t, z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000) * int64(1000000000)
		for {
			c /= 2
			h := hits(l + c)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = l + c + 1
				c--
			}
		}
		return l + c
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vova"
		}
		fmt.Println(z)
	}
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func scanOne() {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
}

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

func nextLong() int64 {
	scanOne()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n, x, y := nextInt(), nextLong(), nextLong()

	solve := func(a int64) int64 {
		hits := func(t int64) int64 {
			return t/x + t/y
		}

		l := int64(0)
		c := int64(1000000000000000000)
		for {
			c /= 2
			h := hits(l + c)
			if h == a || c == 0 {
				break
			}
			if h < a {
				l = l + c + 1
				c--
			}
		}
		return l + c
	}

	for i := 0; i < n; i++ {
		z := "Both"
		a := nextLong()
		t := solve(a)
		von := t / x * x
		van := t / y * y
		switch {
		case van > von:
			z = "Vanya"
		case von > van:
			z = "Vona"
		}
		fmt.Println(z)
	}
}


package main
import (
	"fmt"
)
func main() {
	var n,k int
	fmt.Scan(&n,&k)
	for i:=0;i<k;i++ {
		fmt.Printf("%d ",n-i)
	}
	fmt.Print("1")
	for i:=2; i<=(n-k);i++ {
		fmt.Printf(" %d",i)
	}
	fmt.Println()
}

package main
import (
	"fmt"
)
func main() {
	var n,k int
	fmt.Scan(&n,&k)
	for i:=n;i>n-k;i-- {
		fmt.Printf("%d ",i)
	}
	fmt.Print("1")
	for i:=2; i<=(n-k);i++ {
		fmt.Printf(" %d",i)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

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

	p := make([]int, n*2)
	for i := 0; i < n; i++ {
		p[i] = i + 1
	}
	s1 := 0       // Inclusive
	s2 := 2*n - 1 // Exclusive

	for k > 0 {
		p[s2] = p[s1]
		s1++
		s2--
		k--
	}

	for i := s1; i < n; i++ {
		fmt.Printf("%d ", p[i])
	}
	for i := s2 + 1; i < 2*n; i++ {
		fmt.Printf("%d ", p[i])
	}
	fmt.Printf("\n")
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n,k int
    fmt.Scan(&n,&k)
    for ; k > 0; k-- {
        writer.WriteString(strconv.Itoa(n))
        n--
        if n != 0 { writer.WriteRune(' ') } else { writer.WriteRune('\n')}
    }
    for i := 1; i <= n; i++ {
        writer.WriteString(strconv.Itoa(i))
        if i != n { writer.WriteRune(' ') } else { writer.WriteRune('\n')}
    }
    writer.Flush()
}

package main

import (
	"bytes"
	"fmt"
	"strconv"
)

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

	var buffer bytes.Buffer
	for i := 0; i < k; i++ {
		buffer.WriteString(strconv.Itoa(n-i) + " ")
	}
	for i := 0; i < n-k; i++ {
		buffer.WriteString(strconv.Itoa(i+1) + " ")
	}

	fmt.Println(buffer.String())
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

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

	for index, vl := range arr {
		if index < n-m-1 {
			fmt.Print(vl, " ")
		}
	}

	for i := n - 1; i >= n-m-1; i-- {
		fmt.Print(arr[i], " ")
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

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

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

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

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

	for index, vl := range arr {
		if index < m {
			fmt.Print(vl, " ")
		}
	}

	for i := n - 1; i >= m; i-- {
		fmt.Print(arr[i], " ")
	}
}

package main

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

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

	var n, m int
	fmt.Fscan(reader, &n, &m)

	for i := 1; i <= m; i++ {
		fmt.Printf("%d ", i)
	}

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


package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n < 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] == 0 {
			A[i] = ask(i)
		}
		return A[i]
	}

	l, r := 1, n

	for l < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main
import ("fmt")
var n int

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

func query(a int) int{
  fmt.Println("? ", a)
  var x int
  fmt.Scan(&x)
  return x
}

func main(){
  fmt.Scan(&n)
  if n == 1 {
    fmt.Print("! ", 1)
    return
  }
  if n == 2 {
    var id int = 0; var mn int = 1e9
    var x int = query(1)
    if mn > x{
      mn = x
      id = 1
    }
    x = query(2)
    if mn > x{
      mn = x
      id = 2
    }
    fmt.Print("! ", id)
    return
  }
  var x1 int = query(1); var x2 int = query(2)
  var sl = x1 - x2
  if sl < 0 {
    fmt.Print("! ", 1)
    return
  }
  var l, r int
  l = 2; r = n
  for r - l > 0{
    var mid int = (l + r) / 2;
    var num = query(mid);
    if x1 > x2 && num > x2 {
      r = mid
      continue
    }
    var newsl = num - query(mid + 1)
    if newsl > 0 && sl > 0 {
      l = mid + 1
    } else {
      r = mid
    }
  }
  fmt.Print("! ", l)
}

package main

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

func main() {
	// defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")

	saved := make(map[int]int)
	var n, curr, next int
	scan(&n)

	l, r := 1, n
	for i := 0; i < 100; i++ {
		if l == r {
			fmt.Println("!", l)
			return
		}

		m := l + (r-l)/2

		if x, ok := saved[m]; ok {
			curr = x
		} else {
			fmt.Println("?", m)
			scan(&curr)
			saved[m] = curr
		}

		if x, ok := saved[m+1]; ok {
			next = x
		} else {
			fmt.Println("?", m+1)
			scan(&next)
			saved[m+1] = next
		}

		if curr < next {
			r = m
		} else {
			l = m + 1
		}
	}
}

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

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

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

type (
	input struct{ n int }
	req   struct{ i int }
	resp  struct{ v int }
	guess struct{ ans int }
)

// github.com/EndlessCheng/codeforces-go
func CF1479A(in input, Q func(req) resp) (gs guess) {
	q := func(i int) int { return Q(req{i}).v }
	n := in.n
	if n == 1 || q(1) < q(2) {
		gs.ans = 1
		return
	}
	if q(n-1) > q(n) {
		gs.ans = n
		return
	}
	res := sort.Search(n, func(i int) bool {
		if i < 2 || gs.ans > 0 {
			return false
		}
		x, y, z := q(i-1), q(i), q(i+1)
		if x > y && y < z {
			gs.ans = i
			return false
		}
		return x < y && y < z
	})
	if gs.ans == 0 {
		gs.ans = res
	}
	return
}

func ioq79() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	Q := func(req req) (resp resp) {
		Fprintln(out, "?", req.i)
		out.Flush()
		Fscan(in, &resp.v)
		return
	}

	d := input{}
	Fscan(in, &d.n)
	gs := CF1479A(d, Q)
	Fprint(out, "! ", gs.ans)
	out.Flush()
}

func main() { ioq79() }

package main

import "fmt"

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

	left := 1
	right := n
	for left < right {
		mid := left + (right-left)/2
		var midLeft, midRight int
		fmt.Printf("? %d\n", mid)
		fmt.Scanln(&midLeft)
		fmt.Printf("? %d\n", mid+1)
		fmt.Scanln(&midRight)

		if midLeft < midRight {
			right = mid
		} else if midLeft > midRight {
			left = mid + 1
		} else {
			panic("impossible")
		}
	}
	fmt.Printf("! %d\n", left)
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	l := 1
	r := sint()
	for l < r {
		m := (l + r) / 2
		resm := query(m)
		resmr := query(m + 1)
		if resm < resmr {
			r = m
			continue
		}
		l = m + 1
	}
	if l != r {
		panic("l != r")
	}
	printf("! %d\n", l)
	writer.Flush()
}

func query(i int) int {
	printf("? %d\n", i)
	writer.Flush()
	return sint()
}

package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n <= 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] > 0 {
			return A[i]
		}
		A[i] = ask(i)
		return A[i]
	}

	l, r := 1, n

	for l < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main

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

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

	ask := func(i int) int {
		fmt.Printf("? %d\n", i)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

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
}

// 不变性是在区间[l...r] 中间肯定存在局部最小值
func solve(n int, ask func(int) int) int {
	if n <= 2 {
		return 1
	}
	// ask(i) = a[i]
	// ask(1) = a[1]
	// ask(n) = a[n]
	A := make([]int, n+1)

	cache := func(i int) int {
		if A[i] > 0 {
			return A[i]
		}
		A[i] = ask(i)
		return A[i]
	}

	l, r := 1, n

	for l+1 < r {
		mid := (l + r) / 2
		x := cache(mid)
		y := cache(mid + 1)
		if x > y {
			l = mid + 1
		} else {
			// x < y
			r = mid
		}
	}

	return r
}

package main
import ("fmt")
var n int

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

func query(a int) int{
  fmt.Println(a)
  var x int
  fmt.Scan(&x)
  return x
}

func main(){
  fmt.Scan(&n)
  if n == 1 {
    fmt.Print("! ", 1)
    return
  }
  if n == 2 {
    var id int = 0; var mn int = 1e9
    var x int = query(1)
    if mn > x{
      mn = x
      id = 1
    }
    x = query(2)
    if mn > x{
      mn = x
      id = 2
    }
    fmt.Print("! ", id)
    return
  }
  var x1 int = query(1); var x2 int = query(2)
  var sl = x1 - x2
  if sl < 0 {
    fmt.Print("! ", 1)
    return
  }
  var l, r int
  l = 2; r = n
  for r - l > 0{
    var mid int = (l + r) / 2;
    var num = query(mid);
    if x1 > x2 && num > x2 {
      r = mid
      continue
    }
    var newsl = num - query(mid + 1)
    if newsl > 0 && sl > 0 {
      l = mid + 1
    } else {
      r = mid
    }
  }
  fmt.Print("! ", l)
}

package main

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

type (
	input struct{ n int }
	req   struct{ i int }
	resp  struct{ v int }
	guess struct{ ans int }
)

// github.com/EndlessCheng/codeforces-go
func CF1479A(in input, Q func(req) resp) (gs guess) {
	q := func(i int) int { return Q(req{i}).v }
	n := in.n
	if n == 1 || q(1) < q(2) {
		gs.ans = 1
		return
	}
	if q(n-1) > q(n) {
		gs.ans = n
		return
	}
	res := sort.Search(n, func(i int) bool {
		if i < 2 || gs.ans > 0 {
			return false
		}
		x, y, z := q(i-1), q(i), q(i+1)
		if x > y && y < z {
			gs.ans = i
			return false
		}
		return x < y && y < z
	})
	if gs.ans == 0 {
		gs.ans = res
	}
	return
}

func ioq79() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	Q := func(req req) (resp resp) {
		Fprintln(out, "?", req.i)
		out.Flush()
		Fscan(in, &resp.v)
		return
	}

	d := input{}
	Fscan(in, &d.n)
	gs := CF1479A(d, Q)
	Fprint(out, "!", gs.ans)
	out.Flush()
}

func main() { ioq79() }


/*
URL:
https://codeforces.com/problemset/problem/1369/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n  int
	dp [2000000 + 50]int64
)

func main() {
	for i := 3; i <= 2000000; i++ {
		if i%3 == 0 {
			dp[i] = 2*dp[i-2] + dp[i-1] + 4
		} else {
			dp[i] = 2*dp[i-2] + dp[i-1]
		}
		dp[i] %= MOD
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()

		fmt.Println(dp[n])
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		fmt.Println(solve(n))
	}
}

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 = 2000010

var F [N]int64

const MOD = 1000000007

func init() {
	F[1] = 0
	F[2] = 0
	F[3] = 4

	var x, y int64 = 1, 3

	for i := 4; i < N; i++ {
		F[i] = F[i-3] + 4*x
		F[i] %= MOD
		x, y = y, y+2*x
		y %= MOD
	}
}

func solve(n int) int {
	return int(F[n])
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1369D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int = 1e9 + 7
	const mx int = 2e6
	dp := [mx + 1]int{}
	for i := 3; i <= mx; i++ {
		dp[i] = dp[i-1] + 2*dp[i-2]%mod
		if i%3 == 0 {
			dp[i] += 4
		}
		dp[i] %= mod
	}

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

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

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

const M = 1e9 + 7
const N = 2000000

func (con *contest) main() error {
	s := []int{1, 0, 0}
	t := []int{0, 0, 0}
	a := make([]int, N+1)
	for i := 2; i <= N; i++ {
		s0 := s[0]
		s0 += s[1]
		s0 %= M
		s0 += s[1]
		s0 %= M
		s1 := s[0]
		s2 := s[1]
		s[0], s[1], s[2] = s0, s1, s2
		t[i%3] += s[2]
		t[i%3] %= M
		a[i] = t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
	}
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		con.Println(a[n])
	}
	return nil
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

const M = 1e9 + 7
const N = 2000000

func (con *contest) main() error {
	s := []int{1, 0, 0}
	t := []int{0, 0, 0}
	a := make([]int, N+1)
	for i := 2; i <= N; i++ {
		s0 := s[0]
		s0 += s[1]
		s0 %= M
		s0 += s[1]
		s0 %= M
		s1 := s[0]
		s2 := s[1]
		s[0], s[1], s[2] = s0, s1, s2
		t[i%3] += s[2]
		t[i%3] %= M
		a[i] = t[i%3] * 4
		a[i] %= M
	}
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		con.Println(a[n])
	}
	return nil
}


package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  n, p1, p2, p3, t1, t2 := getI(), getI(), getI(), getI(), getI(), getI()
  result := 0
  l, r := getI(), getI()
  result += p1*(r-l)
  for i := 1; i < n; i++ {
    L, R := getI(), getI()
    w1, w2, w3 := L-r, 0, 0
    if w1 > t1 {
      w2 = w1-t1
      w1 = t1
      if w2 > t2 {
        w3 = w2-t2
        w2 = t2
      }
    }
    result += p1*w1 + p2*w2 + p3*w3
    l, r = L, R
    result += p1*(r-l)
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

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

	var n, p1, p2, p3, t1, t2 int
	fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)

	power, last := 0, 0
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Fscanf(reader, "%d %d\n", &l, &r)
		if i == 0 {
			last = l
		}
		if l-last <= t1 {
			power = power + p1*(l-last)
		} else if l-last <= t1+t2 {
			power = power + p1*t1 + p2*(l-last-t1)
		} else {
			power = power + p1*t1 + p2*t2 + p3*(l-last-t1-t2)
		}
		power = power + (r-l)*p1
		last = r
	}
	fmt.Printf("%d", power)
}

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

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

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

func main() {
	var (
		n, p1, p2, p3, t1, t2 int
		l, r, lastr int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &p1, &p2, &p3, &t1, &t2)
	total := 0
	for i := 0; i < n; i++ {
		lastr = r
		fmt.Fscan(input, &l, &r)
		total += (r - l) * p1
		if i == 0 {
			continue
		}

		inactive := l - lastr
		total += min(t1, inactive) * p1
		if inactive - t1 > 0 {
			inactive -= t1
			total += min(t2, inactive) * p2
			if inactive - t2 > 0 {
				total += (inactive - t2) * p3
			}
		}
	}

	fmt.Println(total)
}

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

package main

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

func read(r *bufio.Scanner) int {
	r.Scan()
	a, _ := strconv.Atoi(r.Text())
	return a
}

func main() {
	z := bufio.NewScanner(os.Stdin)
	z.Split(bufio.ScanWords)
	n, P1, P2,P3, T1,T2 :=	read(z),read(z), read(z),read(z),read(z),read(z)
	p, t := 0, 0
	u1, u2 := read(z), read(z)
	p += (u2 - u1) * P1
	t = u2

	for i := 1; i < n; i++ {
		u1, u2 = read(z), read(z)
		p += (u2 - u1) * P1
		switch {
			case u1 - t >= T1 + T2:
				p += P3 * (u1-t-T1-T2) + P2 * T2 + P1 * T1
			case u1 - t >= T1:
				p += P2 * (u1 - t - T1) + P1 * T1
			default:
				p += P1 * (u1 - t)
		}
		t = u2
	}
	fmt.Println(p)
}

package main

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

/* YEEY */
type Use struct {
	timeStart int
	timeEnd   int
}

func main() {
	var n, p1, p2, p3, t1, t2 int
	reader := bufio.NewReader(os.Stdin)

	input, _, _ := reader.ReadLine()

	inputList := strings.Split(string(input), " ")

	n, _ = strconv.Atoi(inputList[0])
	p1, _ = strconv.Atoi(inputList[1])
	p2, _ = strconv.Atoi(inputList[2])
	p3, _ = strconv.Atoi(inputList[3])
	t1, _ = strconv.Atoi(inputList[4])
	t2, _ = strconv.Atoi(inputList[5])

	useList := make([]Use, n)

	for i := 0; i < n; i++ {
		input, _, _ = reader.ReadLine()
		inputList = strings.Split(string(input), " ")

		t1, _ := strconv.Atoi(inputList[0])
		t2, _ := strconv.Atoi(inputList[1])

		use := Use{timeStart: t1, timeEnd: t2}

		useList[i] = use
	}

	lastTime := -1

	result := 0

	for i := 0; i < n; i++ {
		use := useList[i]
		result += (use.timeEnd - use.timeStart) * p1

		if lastTime != -1 {
			oldUse := useList[i-1]

			if use.timeStart-oldUse.timeEnd >= t1 {
				result += t1 * p1

				if use.timeStart-oldUse.timeEnd-t1 >= t2 {
					result += t2 * p2
					result += (use.timeStart - oldUse.timeEnd - t1 - t2) * p3
				} else {
					result += (use.timeStart - oldUse.timeEnd - t1) * p2
				}
			} else {
				result += (use.timeStart - oldUse.timeEnd) * p1
			}
		}

		lastTime = use.timeEnd
	}

	fmt.Println(result)
}

package main

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

type State struct {
	l, r int
}

func main() {
	fsc := NewFastScanner()
	values := make([]int, 0)
	for i := 0; i < 6; i++ {
		values = append(values, fsc.NextInt())
	}
	N := values[0]
	P1 := values[1]
	P2 := values[2]
	P3 := values[3]
	T1 := values[4]
	T2 := values[5]
	querys := make([]State, 0)
	for i := 0; i < N; i++ {
		l, r := fsc.NextInt(), fsc.NextInt()
		querys = append(querys, State{l, r})
	}
	start := querys[0].l
	end := querys[N-1].r

	res := 0
	last := 0
	for t := start; t < end; t++ {
		for _, v := range querys {
			if t >= v.l && t <= v.r {
				last = t
				break
			}
		}
		diff := t - last
		consume := P1
		if diff >= T1 {
			consume = P2
		}
		if diff >= T1+T2 {
			consume = P3
		}
		res += consume
	}
	fmt.Println(res)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) 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 *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) 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
		}
	}
}

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

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

// Author: sighduck
// URL: https://codeforces.com/contest/10/problem/A

package main

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

type Interval struct {
	start int
	end   int
}

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

func computeRestPower(p1 int, p2 int, p3 int, t1 int, t2 int, restLength int) int {
	totalPower := 0
	totalPower += min(restLength, t1) * p1
	restLength -= min(restLength, t1)
	totalPower += min(restLength, t2) * p2
	restLength -= min(restLength, t2)
	totalPower += restLength * p3
	return totalPower
}

func Solve(n int, p1 int, p2 int, p3 int, t1 int, t2 int, intervals []Interval) int {
	totalPower := 0
	for i := 0; i < n; i++ {
		interval := intervals[i]
		totalPower += (interval.end - interval.start) * p1
		if i != 0 {
			restLength := interval.start - intervals[i-1].end
			totalPower += computeRestPower(p1, p2, p3, t1, t2, restLength)
		}
	}
	return totalPower
}

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

	var n, p1, p2, p3, t1, t2 int
	fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)
	intervals := make([]Interval, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &intervals[i].start, &intervals[i].end)
	}
	fmt.Fprintf(writer, "%d\n", Solve(n, p1, p2, p3, t1, t2, intervals))
}

package main

import "fmt"

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d\n", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

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

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

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 "fmt"

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

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"
	"os"
	"strconv"
)

func read(r *bufio.Scanner) int {
	r.Scan()
	a, _ := strconv.Atoi(r.Text())
	return a
}

func main() {
	z := bufio.NewScanner(os.Stdin)
	z.Split(bufio.ScanWords)
	n, P1, P2,P3, T1,T2 :=	read(z),read(z), read(z),read(z),read(z),read(z)
	p, t := 0, 0
	u1, u2 := read(z), read(z)
	p += (u2 - u1) * P1
	t = u2

	for i := 1; i < n; i++ {
		u1, u2 = read(z), read(z)
		p += (u2 - u1) * P1
		switch {
			case u1 - t >= T1 + T2:
				fmt.Println("a")
				p += P3 * (u1-t-T1-T2) + P2 * T2 + P1 * T1
			case u1 - t >= T1:
				fmt.Println("b")
				p += P2 * (u1 - t - T1) + P1 * T1
			default:
				fmt.Println("c")
				p += P1 * (u1 - t)
		}
		t = u2
	}
	fmt.Println(p)
}