package main

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

var abc = []byte("abcdefghijklmnopqrstuvwxyz")

func getOtherThan(chars []byte) byte {
	for _, a := range (abc) {
		if !byteInList(a, chars) {
			return a;
		}
	}
	panic("abc is too small")
}

func byteInList(a byte, list []byte) bool {
	for _, b := range list {
		if b == a {
			return true
		}
	}
	return false
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputstr, _ := reader.ReadString('\n')

	input := []byte(inputstr)

	result := []byte{}

	var last byte = '\n'
	for n, ch := range input {
		if (last == ch) {
			exclude := []byte{last}
			if n + 1  < len(input) { // perf
				  exclude = append(exclude, input[n+1])
			}
			newCh := getOtherThan(exclude)
			last = newCh
			result = append(result, newCh)
		} else {
			last = ch
			result = append(result, ch)
		}
	}

	fmt.Print(string(result))
}

package main

import "fmt"

func main() {
	s := make([]byte, 2e5+1)
	fmt.Scanf("%s", &s)
	for i := range s[1:] {
		if s[i] == s[i+1] {
			c := byte('a')
			for s[i] == c || i+2 < len(s) && s[i+2] == c {
				c++
			}
			s[i+1] = c
		}
	}
	fmt.Printf("%s\n", s)
}

package main

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

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

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

	s, _ := reader.ReadBytes('\n')
	s = bytes.TrimSpace(s)

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

			for c := byte('a'); c <= 'z'; c++ {
				if i == 0 {
					if c != s[i+1] {
						s[i] = c
						break
					}
				} else if c != s[i-1] && c != s[i+1] {
					s[i] = c
					break
				}
			}
		}
	}

	println(string(s))
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

	var s []byte
	Fscan(in, &s)
	for i, b := range s {
		if i+1 < len(s) && b == s[i+1] {
			s[i+1] = b + 1
			if s[i+1] > 'z' {
				s[i+1] = 'a'
			}
			if i+2 < len(s) && s[i+1] == s[i+2] {
				s[i+1]++
				if s[i+1] > 'z' {
					s[i+1] = 'a'
				}
			}
		}
	}
	Fprint(out, string(s))
}

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

package main

import "fmt"

func main() {
	s := make([]byte, 2e5+1)
	fmt.Scanf("%s", &s)
	for i := range s[1:] {
		if s[i] == s[i+1] {
			c := byte('a')
			for s[i] == c || i+1 < len(s) && s[i+1] == c {
				c++
			}
			s[i+1] = c
		}
	}
	fmt.Printf("%s\n", s)
}

package main

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

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

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

	s, _ := reader.ReadBytes('\n')
	s = bytes.TrimSpace(s)

	for i := 1; i < len(s)-1; i++ {
		if s[i] == s[i-1] || s[i] == s[i+1] {
			for c := byte('a'); c <= 'z'; c++ {
				if c != s[i-1] && c != s[i+1] {
					s[i] = c
					break
				}
			}
		}
	}

	println(string(s))
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

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

	s, _ := reader.ReadBytes('\n')
	s = bytes.TrimSpace(s)

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

			for c := byte('a'); c <= 'z'; c++ {
				if i == 0 {
					if c != s[i+1] {
						s[i] = c
						break
					}
				} else if c != s[i-1] && c != s[i+1] {
					s[i] = c
					break
				}
			}
		}
	}

	println(string(s))
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for  t := in() ; t > 0; t-- {
		n := in()

		if n < 31 {
			fmt.Println("No")
		} else if n == 40 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 9)
		} else if n == 36 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 5)
		} else if n == 44 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 13)
		} else {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, n - (10 + 6 + 14))		}
	}
}

package main

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

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

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		if n > 6+10+14 {
			io.println("YES")
			nn := n - 6 - 10 - 14
			if nn == 6 || nn == 10 || nn == 14 {
				io.printlnInts(6, 10, 15, n-6-10-15)
			} else {
				io.printlnInts(6, 10, 14, n-6-10-14)
			}
		} else {
			io.println("NO")
		}
	}
}

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

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

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

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

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

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

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

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		// // s:=reader.NextString();
		// k:= reader.NextInt64()
		// aa := make([]int64, n)
		// for i := 0; i < len(aa); i++ {
		// 	aa[i]=reader.NextInt64()
		// }
		sol(n)
	}
}

func sol(n int64) {
	if n<=30 {
		writer.Printf("NO\n")
	}else{
		writer.Printf("YES\n")
		if (n==36){
			writer.Printf("5 6 10 15\n")
		}else if (n==40) {
			writer.Printf("6 10 15 9\n")
		}else if (n==44){
			writer.Printf("6 7 10 21\n")
		}else{
			writer.Printf("6 10 14 %d\n",n-30)
		}
	}
}

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
}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

/*
URL:
https://codeforces.com/contest/1388/problem/A
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"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
	// MOD          = 998244353
	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

	C []int
)

func main() {
	_, P := sieve(30)
	for i := 0; i < len(P); i++ {
		for j := i + 1; j < len(P); j++ {
			p, q := P[i], P[j]
			C = append(C, p*q)
		}
	}
	sort.Sort(sort.IntSlice(C))
	PrintfDebug("%v\n", C)

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

		solve()
	}
}

func solve() {
	for i := 0; i < len(C); i++ {
		for j := i + 1; j < len(C); j++ {
			for k := j + 1; k < len(C); k++ {
				s, t, u := C[i], C[j], C[k]
				last := n - (s + t + u)

				if last > 0 && last != s && last != t && last != u {
					fmt.Println("YES")
					fmt.Println(s, t, u, last)
					return
				}
			}
		}
	}
	fmt.Println("NO")
}

// エラトステネスの篩: O(NloglogN)
// n以下の素数の数と素数のスライスを返す
func sieve(n int) (int, []int) {
	// var prime [2000000 + 5]int
	prime := []int{}
	var isPrime [2000000 + 5 + 1]bool

	p := 0
	for i := 0; i <= n; i++ {
		isPrime[i] = true
	}
	isPrime[0], isPrime[1] = false, false

	for i := 2; i <= n; i++ {
		// iがtrueで残っている場合は素数認定し、自分より大きい倍数を取り除いていく
		if isPrime[i] {
			// prime[p] = i
			prime = append(prime, i)
			p++

			// 倍数の除去
			for j := 2 * i; j <= n; j += i {
				isPrime[j] = false
			}
		}
	}

	return p, prime
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		if n < 31 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		last := n - 30
		if last == 6 || last == 10 || last == 14 {
			last--
			fmt.Printf("6 10 15 %d\n", last)
			continue
		}
		fmt.Printf("6 10 14 %d\n", last)
	}
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		if n <= 30 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			if n == 36 {
				fmt.Println(6, 10, 15, 5)
			} else if n == 40 {
				fmt.Println(6, 10, 15, 9)
			} else if n == 44 {
				fmt.Println(6, 10, 15, 13)
			} else {
				fmt.Println(6, 10, 14, n-30)
			}
		}
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n int
		Fscan(in, &n)

		if(n<=30){
			Fprintln(out,"NO")
			continue
		}

		if(n!=36&&n!=40&&n!=44){
			Fprintln(out,"YES")
			Fprintln(out,6,10,14,n-30)
			continue
		}
		Fprintln(out,"YES")
		Fprintln(out,6,10,15,n-31)
	}
}

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

package main

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

func main() {

	var input io.Reader = bufio.NewReader(os.Stdin)

	var n, t int

	fmt.Fscan(input, &t)

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

		if n < 31 {
			fmt.Println("NO")
			continue
		}
		if n == 36 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 5)
			continue
		}
		if n == 40 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 9)
			continue
		}
		if n == 44 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 13)
			continue
		} else {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 14, n-30)
			continue
		}
	}
}

package main

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

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

	var pattern = []int{6, 10, 14, 15}

	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)

		var ret = make([]int, 0)

		for i := 0; i < len(pattern); i++ {
			for j := i + 1; j < len(pattern); j++ {
				for k := j + 1; k < len(pattern); k++ {

					if len(ret) > 0 {
						continue
					}

					var rm = n - pattern[i] - pattern[j] - pattern[k]
					if rm != pattern[i] && rm != pattern[j] && rm != pattern[k] && rm > 0 {
						ret = append(ret, pattern[i])
						ret = append(ret, pattern[j])
						ret = append(ret, pattern[k])
						ret = append(ret, rm)
					}
				}
			}
		}
		if len(ret) > 0 {
			fmt.Fprintf(writer, "YES\n")
			for _, v := range ret {
				fmt.Fprintf(writer, "%d ", v)
			}
			fmt.Fprintf(writer, "\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

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

//Task -
type Task struct {
	Number int
}

func (t *Task) Solve() {
	if t.Number > 44 {
		fmt.Println("YES")
		fmt.Println(6, 10, 14, t.Number-30)
	} else if t.Number < 31 {
		fmt.Println("NO")
	} else if t.Number >= 31 && t.Number < 36 {
		fmt.Println("YES")
		fmt.Println(6, 10, 14, t.Number-30)
	} else if t.Number == 36 {
		fmt.Println("YES")
		fmt.Println(6, 15, 14, 1)
	} else if t.Number > 36 && t.Number < 40 {
		fmt.Println("YES")
		fmt.Println(6, 10, 14, t.Number-30)
	} else if t.Number == 40 {
		fmt.Println("YES")
		fmt.Println(6, 10, 21, 3)
	} else if t.Number > 40 && t.Number < 44 {
		fmt.Println("YES")
		fmt.Println(6, 10, 14, t.Number-30)
	} else if t.Number == 44 {
		fmt.Println("YES")
		fmt.Println(6, 15, 14, 9)
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// counter := 0
	// tasksAmount := 0
	tasks := []Task{}
	_ = scanner.Scan()
	for scanner.Scan() {

		var currentTask Task
		//Заполняем новое задание
		currentTask = Task{
			Number: 0,
		}
		text := scanner.Text()

		currentTask.Number, _ = strconv.Atoi(text)

		tasks = append(tasks, currentTask)

	}

	for _, t := range tasks {
		t.Solve()
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, tmp int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		fmt.Scanf("%d\n", &tmp)
		if tmp == 36 || tmp == 40 || tmp == 44 {
			fmt.Printf("YES\n6 10 15 %d\n", tmp-31)
		} else if tmp > 30 {
			fmt.Printf("YES\n6 10 14 %d\n", tmp-30)
		} else {
			fmt.Printf("NO\n")
		}
	}
}

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 i := 0; i < t; i++ {

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

		n -= 30

		if n <= 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			switch n {
			case 6, 10, 14:
				fmt.Fprintln(out, 6, 10, 15, n-1)
			default:
				fmt.Fprintln(out, 6, 10, 14, n)
			}
		}
	}

}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for  t := in() ; t > 0; t-- {
		n := in()

		if n < 31 {
			fmt.Println("No")
		} else if n == 31 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, 1)
		} else if n == 36 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, 5)
		} else if n == 44 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 13)
		} else {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, n - (10 + 6 + 14))		}
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for  t := in() ; t > 0; t-- {
		n := in()

		if n < 31 {
			fmt.Println("No")
		} else if n == 31 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, 1)
		} else if n == 36 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 5)
		} else if n == 44 {
			fmt.Println("Yes")
			fmt.Println(6, 10, 15, 13)
		} else {
			fmt.Println("Yes")
			fmt.Println(6, 10, 14, n - (10 + 6 + 14))		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		if n < 31 {
			fmt.Println("No")
			continue
		}
		fmt.Println("Yes")
		last := n - 30
		fmt.Printf("6 10 14 %d\n", last)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		if n < 31 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		last := n - 30
		fmt.Printf("6 10 14 %d\n", last)
	}
}

package main

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

func main() {

	var input io.Reader = bufio.NewReader(os.Stdin)

	var n, t int

	fmt.Fscan(input, &t)

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

		if n < 31 {
			fmt.Println("NO")
		}
		if n == 36 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 5)
		}
		if n == 40 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 9)
		}
		if n == 44 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 15, 13)
		} else {
			fmt.Println("YES")
			fmt.Printf("%d %d %d %d\n", 6, 10, 14, n-30)
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, a int
	fmt.Fscan(os.Stdin, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(os.Stdin, &a)
		if a <= 30 {
			fmt.Print("NO", "\n")
		} else {
			fmt.Print("YES", "\n", "6 10 14 ", a-12)
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, a int
	fmt.Fscan(os.Stdin, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(os.Stdin, &a)
		if a <= 30 {
			fmt.Print("NO", "\n")
		} else {
			fmt.Print("YES", "\n", "6 10 14 ", a-30, "\n")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, a int
	fmt.Fscan(os.Stdin, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(os.Stdin, &a)
		if a <= 30 {
			fmt.Print("NO", "\n")
		} else
		if a == 31 {
			fmt.Print("YES", "\n", "6 10 14 ", a-30, "\n")
		}else {
			fmt.Print("YES", "\n", "6 10 15 ", a-31, "\n")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, a int
	fmt.Fscan(os.Stdin, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(os.Stdin, &a)
		if a <= 30 {
			fmt.Print("NO", "\n")
		} else {
			fmt.Print("YES", "\n", "6 10 14 ", a-30)
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, a int
	fmt.Fscan(os.Stdin, &n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(os.Stdin, &a)
		if a <= 31 {
			fmt.Print("NO", "\n")
		} else {
			fmt.Print("YES", "\n", "6 10 15 ", a-31, "\n")
		}
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n int
		Fscan(in, &n)

		if(n<=30){
			Fprintln(out,"NO")
			continue
		}

		if(n!=36&&n!=40&&n!=44){
			Fprintln(out,"YES")
			Fprintln(out,6,10,14,n-30)
			continue
		}
		Fprintln(out,"GC")
		Fprintln(out,6,10,15,n-31)
	}
}

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

package main

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

func main() {

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

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

	for i := 0; i < t; i++ {

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

		if n < 31 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			fmt.Fprintln(out, 6, 10, 14, n-30)
		}
	}

}

package main

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

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

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		if n > 6+10+14 {
			io.println("YES")
			io.printlnInts(6, 10, 14, n-6-10-14)
		} else {
			io.println("NO")
		}
	}
}

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

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

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

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

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

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

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

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}


// Codeforces 717 C Potions Homework
// int - 32 bit type !!!!
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
    "sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
    var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for i:=0; i<len(ss); i++ {
        a[i], err = strconv.Atoi(ss[i])
        if err != nil {
            fmt.Println("n atoi failure", err)
            panic(err)
        }
    }
    return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
    a := make([]int, n)
    s, err := in.ReadString('\n')
    if err != nil {
        fmt.Println("read failure", err)
        panic(err)
    }
    ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for j:=0; j<n; j++ {
        aa,err := strconv.Atoi(ss[j])
        if err != nil {
            fmt.Println("aa conv failed", err)
            panic(err)
        }
        a[j] = aa
    }
    return a
}

var n int
var sum int64
var a []int

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    a = make([]int, n)
    for i:=0; i<n; i++ {
        a[i],_,_,_,_ = readFive()
    }
    sort.Ints(a)
}

func solve() {
    sum = 0

    for i:=0; i<n; i++ {
        sum += int64(a[i]) * int64(a[n-i-1])
    }
    sum = sum % 10007
}

func printRes() {
    fmt.Println(sum)
}

func main() {
 	readData()
    solve()
    printRes()
}

package main

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

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

	var n int
	fmt.Fscanf(bufin, "%d\n", &n)

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

	sort.Ints(a)
	mod := 10007

	res := 0
	for i := 0; i < n; i++ {
		x := a[i] % mod
		y := a[n-1-i] % mod
		res += (x * y) % mod
		res %= mod
	}

	fmt.Fprintf(bufout, "%d\n", res)
}

// Codeforces 717 C Potions Homework
// int - 32 bit type !!!!
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
    "sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
    var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for i:=0; i<len(ss); i++ {
        a[i], err = strconv.Atoi(ss[i])
        if err != nil {
            fmt.Println("n atoi failure", err)
            panic(err)
        }
    }
    return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
    a := make([]int, n)
    s, err := in.ReadString('\n')
    if err != nil {
        fmt.Println("read failure", err)
        panic(err)
    }
    ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for j:=0; j<n; j++ {
        aa,err := strconv.Atoi(ss[j])
        if err != nil {
            fmt.Println("aa conv failed", err)
            panic(err)
        }
        a[j] = aa
    }
    return a
}

var n int
var sum int64
var a []int

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    a = make([]int, n)
    for i:=0; i<n; i++ {
        a[i],_,_,_,_ = readFive()
    }
    sort.Ints(a)
}

func solve() {
    sum = 0

    for i:=0; i<n; i++ {
        sum += int64(a[i]) * int64(a[n-i-1])
    }
}

func printRes() {
    fmt.Println(sum)
}

func main() {
 	readData()
    solve()
    printRes()
}

// Codeforces 717 C Potions Homework
// int - 32 bit type !!!!
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
    var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for i:=0; i<len(ss); i++ {
        a[i], err = strconv.Atoi(ss[i])
        if err != nil {
            fmt.Println("n atoi failure", err)
            panic(err)
        }
    }
    return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
    a := make([]int, n)
    s, err := in.ReadString('\n')
    if err != nil {
        fmt.Println("read failure", err)
        panic(err)
    }
    ss := strings.Split(strings.Trim(s, " \n\r"), " ")
    for j:=0; j<n; j++ {
        aa,err := strconv.Atoi(ss[j])
        if err != nil {
            fmt.Println("aa conv failed", err)
            panic(err)
        }
        a[j] = aa
    }
    return a
}

var n int
var sum int64
var a []int64

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    a = make([]int64, n)
    for i:=0; i<n; i++ {
        var aa int
        aa,_,_,_,_ = readFive()
        a[i] = int64(aa)
    }
}

func solve() {
    sum = 0

    for i:=0; i<n; i++ {
        sum += a[i] * a[n-i-1]
    }
}

func printRes() {
    fmt.Println(sum)
}

func main() {
 	readData()
    solve()
    printRes()
}


package main

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

type pair [2]uint64

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

	line, _ := reader.ReadString('\n')
	line = strings.TrimSpace(line)
	size, _ := strconv.ParseUint(line, 10, 64)

	roadsV := make([]bool, size)
	roadsH := make([]bool, size)

	shedule := make([]pair, size*size)

	for i := uint64(0); i < size*size; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		for n, item := range strings.Split(line, " ") {
			shedule[i][n], _ = strconv.ParseUint(item, 10, 64)
		}
	}

	var goodDay []uint64
	for day, item := range shedule {
		if roadsV[item[0]-1] == false && roadsH[item[1]-1] == false {
			roadsV[item[0]-1] = true
			roadsH[item[1]-1] = true
			goodDay = append(goodDay, uint64(day)+1)
		}
	}

	for _, day := range goodDay {
		fmt.Print(day, " ")
	}
}

package main

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

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

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

	n := nextInt()
	h, v := make([]bool, n), make([]bool, n)
	a, b := 0, 0

	for i := 0; i < n*n; i++ {
		a, b = nextInt(), nextInt()

		if !h[a-1] && !v[b-1] {
			h[a-1] = true
			v[b-1] = true
			print(i+1, " ")
		}

	}

	println()
}

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

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import "fmt"

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

	var visit [2][]bool
	var day []int
	visit[0], visit[1] = make([]bool, n+1), make([]bool, n+1)

	for i := 1; i <= n*n; i++ {
		fmt.Scan(&h, &v)
		if !visit[0][h] && !visit[1][v] {
			day = append(day, i)
			visit[0][h] = true
			visit[1][v] = true
		}
	}

	for i := 0; i < len(day); i++ {
		if i != 0 {
			fmt.Print(" ")
		}

		fmt.Print(day[i])
	}
}

package main

import "fmt"

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

	var visit [2][]bool
	var day []int
	visit[0], visit[1] = make([]bool, n+1), make([]bool, n+1)

	for i := 0; i < n*n; i++ {
		fmt.Scan(&h, &v)
		if !visit[0][h] && !visit[1][v] {
			day = append(day, n*(h-1)+v)
			visit[0][h] = true
			visit[1][v] = true
		}
	}

	for i := 0; i < len(day); i++ {
		if i != 0 {
			fmt.Print(" ")
		}

		fmt.Print(day[i])
	}
}


package main

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

func solve() {
	n := readInt()
	s := make([]int, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		s[i] = readInt()
		d[i] = readInt()
	}
	cur := s[0] + 1
	for i := 1; i < n; i++ {
		p := s[i]
		for p < cur {
			p += d[i]
		}
		cur = p + 1
	}

	fmt.Println(cur - 1)
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

func Init() {
}

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

	day := 0
	for i := 0; i < N; i++ {
		S := io.NextInt()
		D := io.NextInt()

		day++
		for day < S || (day - S) % D != 0 {
			day++
		}
	}
	io.Println(day)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func Init() {
}

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

	day := 0
	for i := 0; i < N; i++ {
		S := io.NextInt()
		D := io.NextInt()

		for day < S || (day - S) % D != 0 {
			day++
		}
	}
	io.Println(day)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

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

	in := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var a, b, c, d int
		fmt.Fscan(in, &a, &b, &c, &d)
		if a+b > c+d {
			fmt.Fprintf(out, "%d\n", a+b)
		} else {
			fmt.Fprintf(out, "%d\n", c+d)
		}
	}
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	rd := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscan(rd, &q)
	for t := 0; t < q; t++ {
		var a, b, c, d int
		fmt.Fscan(rd, &a, &b, &c, &d)
		fmt.Println(max(a + b, c + d))
	}
}

package main

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

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

func print(str string) {
	writer.WriteString(str)
}

func nextInt() int {
	scanner.Scan()
	str := scanner.Text()
	val, _ := strconv.Atoi(str)
	return val
}

func nextFloat() float64 {
	scanner.Scan()
	str := scanner.Text()
	val, _ := strconv.ParseFloat(str, 64)
	return val
}

func nextString() string {
	scanner.Scan()
	str := scanner.Text()
	return str
}

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

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

	t := nextInt()
	for t != 0 {
		a, b := nextInt(), nextInt()
		c, d := nextInt(), nextInt()
		res := max(a+b, c+d)
		print(strconv.Itoa(res)+"\n")
		t--
	}
}

package main

import (
	"fmt"
)

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

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

package main

import (
	"fmt"
)

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

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


// cf 733b project main.go
package main

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

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func ReadString() string {
	scanner.Scan()
	return scanner.Text()
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func PrintStrings(strs ...string) {
	for _, value := range strs {
		writer.WriteString(value)
		writer.WriteByte(' ')
	}
}

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

	var n int = ReadInt32()
	var a, ai, b, bi, ls, rs int
	for i := 0; i < n; i++ {
		var l, r int = ReadInt32(), ReadInt32()
		if l-r > a {
			a = l - r
			ai = i + 1
		}
		if r-l > b {
			b = r - l
			bi = i + 1
		}
		ls += l
		rs += r

	}
	if ls+b > rs+a || ls == rs {
		PrintInts(bi)
	} else if ls+b < rs+a {
		PrintInts(ai)
	} else {
		PrintInts(0)
	}

}

package main

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

func solve() {
    n := readInt()
	a := make([]int, n)

	sum := 0
	for i := 0; i < n; i++ {
        l, r := readInt(), readInt()
		a[i] = l - r
		sum += a[i]
	}

	ans, best := 0, abs(sum)
	for i := 0; i < n; i++ {
		cur := abs(sum - 2*a[i])
		if cur > best {
			best = cur
			ans = i + 1
		}

	}
	fmt.Println(ans)
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
    scanner.Split(bufio.ScanWords)
    solve()
}

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

// IO

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

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

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

package main

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

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

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

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

	var n int
	fmt.Fscanf(bufin, "%d\n", &n)

	l := make([]int, n+1)
	r := make([]int, n+1)

	lsum := 0
	rsum := 0
	for i := 1; i <= n; i++ {
		fmt.Fscanf(bufin, "%d %d\n", &l[i], &r[i])
		lsum += l[i]
		rsum += r[i]
	}

	res := 0
	maxBeauty := abs(lsum - rsum)

	for i := 1; i <= n; i++ {
		lnow := lsum - l[i] + r[i]
		rnow := rsum - r[i] + l[i]
		beauty := abs(lnow - rnow)
		if maxBeauty < beauty {
			maxBeauty = beauty
			res = i
		}
	}

	fmt.Fprintf(bufout, "%d\n", res)
}

package main

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

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

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

	n := nextInt()
	L, R := 0, 0
	l := make([]int, n)
	r := make([]int, n)
	ans := -1

	for i := 0; i < n; i++ {
		l[i] = nextInt()
		r[i] = nextInt()
		L += l[i]
		R += r[i]
	}
	// println(abs(L - R))
	maxBeaty := abs(L - R)

	for i := 0; i < n; i++ {
		newBeaty := abs(L - R + 2*(r[i]-l[i]))
		// println(newBeaty)
		if newBeaty > maxBeaty {
			maxBeaty = newBeaty
			ans = i
		}
	}

	println(ans + 1)
}

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

	return n
}

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

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

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

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

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N int
	fmt.Fscanf(bufin, "%d\n", &N)
	var l = make([]int, N)
	var r = make([]int, N)
	var L, R = 0, 0
	for i := 0; i < N; i++ {
		fmt.Fscanf(bufin, "%d %d\n", &l[i], &r[i])
		L += l[i]
		R += r[i]
	}
	var beauty = abs(L - R)
	var ans = 0
	for i := 0; i < N; i++ {
		var nL = L - l[i] + r[i]
		var nR = R - r[i] + l[i]
		var nbeauty = abs(nL - nR)
		if beauty < nbeauty {
			beauty = nbeauty
			ans = i + 1
		}
	}
	fmt.Fprintf(bufout, "%d\n", ans)

}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
    scanner.Split(bufio.ScanWords)

    n := ReadInt()
    deltas := make([]int, n)
    plus, minus := 0, 0

    for i := 0; i < n; i++ {
        left, right := ReadInt(), ReadInt()
        deltas[i] = left - right

        if deltas[i] > 0 {
            plus += deltas[i]
        } else {
            minus += deltas[i]
        }
    }

    maxIndex := -1
    maxPretty := math.Abs(float64(plus + minus))

    for i := 0; i < n; i++ {
        if deltas[i] == 0 {
            continue
        }

        newPretty := math.Abs(float64(plus + minus - 2 * deltas[i]))

        if newPretty > maxPretty {
            maxPretty = newPretty
            maxIndex = i
        }
    }

    fmt.Print(maxIndex + 1)
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	type Tup struct {
		A int
		B int
	}

	T := make([]Tup, N)
	for i := 0; i < N; i++ {
		T[i] = Tup{A:sc.NextInt(), B:sc.NextInt()}
	}

	a := 0
	b := 0
	for i := 0; i < N; i++ {
		a += T[i].A
		b += T[i].B
	}

	z := abs(a - b)
	index := 0
	for i := 0; i < N; i++ {
		c := a - T[i].A + T[i].B
		d := b + T[i].A - T[i].B

		if abs(c - d) > z {
			z = abs(c - d)
			index = i + 1
		}
	}
	fmt.Println(index)

}

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

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

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

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

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

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

	return mp
}

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

// cf733b project main.go
package main

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

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func ReadString() string {
	scanner.Scan()
	return scanner.Text()
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func PrintStrings(strs ...string) {
	for _, value := range strs {
		writer.WriteString(value)
		writer.WriteByte(' ')
	}
}

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

	var n int = ReadInt32()
	var a, ai, b, bi, ls, rs int
	for i := 0; i < n; i++ {
		var l, r int = ReadInt32(), ReadInt32()
		if l-r > a {
			a = l - r
			ai = i + 1
		}
		if r-l > b {
			b = r - l
			bi = i + 1
		}
		ls += l
		rs += r

	}
	if ls+b > rs+a || ls == rs {
		PrintInts(bi)
	} else if ls+b < rs+a {
		PrintInts(ai)
	} else {
		PrintInts(0)
	}

}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
    scanner.Split(bufio.ScanWords)

    n := ReadInt()
    deltas := make([]int, n)
    plus, minus := 0, 0

    for i := 0; i < n; i++ {
        left, right := ReadInt(), ReadInt()
        deltas[i] = left - right

        if deltas[i] > 0 {
            plus++
        } else {
            minus++
        }
    }

    maxIndex := -1

    for i := 0; i < n; i++ {
        if deltas[i] == 0 || (plus > minus && deltas[i] > 0) || (plus < minus && deltas[i] < 0) {
            continue
        }

        if maxIndex == -1 || math.Abs(float64(deltas[maxIndex])) < math.Abs(float64(deltas[i])) {
            maxIndex = i
        }
    }

    fmt.Print(maxIndex + 1)
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	type Tup struct {
		A int
		B int
	}

	T := make([]Tup, N)
	for i := 0; i < N; i++ {
		T[i] = Tup{A:sc.NextInt(), B:sc.NextInt()}
	}

	L := 0
	for i := 0; i < N; i++ {
		if T[i].A - T[i].B > 0 {
			L++
		} else {
			L--
		}
	}
	if L == 0 {
		fmt.Println(1)
		return
	}
	mx := 0
	mxI := -1
	for i := 0; i < N; i++ {
		if L >= 0 {
			if mx < T[i].B - T[i].A {
				mx = T[i].B - T[i].A
				mxI = i
			}
		} else {
			if mx < T[i].A - T[i].B {
				mx = T[i].A - T[i].B
				mxI = i
			}
		}
	}
	fmt.Println(mxI + 1)

}

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

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

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

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

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

	return mp
}

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

// cf 733b project main.go
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a, ai, b, bi, ls, rs int
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		if l-r > a {
			a = l - r
			ai = i + 1
		}
		if r-l > b {
			b = r - l
			bi = i + 1
		}
		ls += l
		rs += r

	}
	if ls+b > rs+a {
		fmt.Println(bi)
	} else if ls+b < rs+a {
		fmt.Println(ai)
	} else {
		fmt.Println(0)
	}

}

// cf 733b project main.go
package main

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

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func ReadString() string {
	scanner.Scan()
	return scanner.Text()
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func PrintStrings(strs ...string) {
	for _, value := range strs {
		writer.WriteString(value)
		writer.WriteByte(' ')
	}
}

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

	var n int = ReadInt32()
	var a, ai, b, bi, ls, rs int
	for i := 0; i < n; i++ {
		var l, r int = ReadInt32(), ReadInt32()
		if l-r > a {
			a = l - r
			ai = i + 1
		}
		if r-l > b {
			b = r - l
			bi = i + 1
		}
		ls += l
		rs += r

	}
	if ls+b > rs+a || a == b {
		PrintInts(bi)
	} else if ls+b < rs+a {
		PrintInts(ai)
	} else {
		PrintInts(0)
	}

}


package main

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

const INF = 0x3f3f3f3f
const MOD = 1000000007

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, m := cin.NextInt(), cin.NextInt()
	s, t := cin.NextInt()-1, cin.NextInt()-1
	g := make([][]int, n)
	for i := 0; i < m; i++ {
		u, v := cin.NextInt()-1, cin.NextInt()-1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	dist := make([]int, n)
	dp0 := make([]int, n)
	dp1 := make([]int, n)
	for i := 0; i < n; i++ {
		dist[i] = INF
		dp0[i] = 0
		dp1[i] = 0
	}
	dist[s] = 0
	dp0[s] = 1
	var q []int
	q = append(q, s)
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		if u < n {
			for _, v := range g[u] {
				if dist[v] == INF {
					dist[v] = dist[u] + 1
					q = append(q, v)
				}
				if dist[v] == dist[u]+1 {
					dp0[v] += dp0[u]
					dp0[v] %= MOD
				}
				if dist[v] == dist[u] {
					dp1[v] += dp0[u]
					dp1[v] %= MOD
				}
			}
			q = append(q, u+n)
		} else {
			u -= n
			for _, v := range g[u] {
				if dist[v] == dist[u]+1 {
					dp1[v] += dp1[u]
					dp1[v] %= MOD
				}
			}
		}
	}
	cout.Println((dp0[t] + dp1[t]) % MOD)
	// cerr.Println(dist)
	// cerr.Println(dp0)
	// cerr.Println(dp1)
}

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

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

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

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

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

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

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

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

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

type writer struct {
	w *bufio.Writer
}

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

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

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

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

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

// }}}

// vim: fdm=marker

package main

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

const INF = 0x3f3f3f3f
const MOD = 1000000007

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, m := cin.NextInt(), cin.NextInt()
	s, t := cin.NextInt()-1, cin.NextInt()-1
	g := make([][]int, n)
	for i := 0; i < m; i++ {
		u, v := cin.NextInt()-1, cin.NextInt()-1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	dist := make([]int, n)
	dp0 := make([]int64, n)
	dp1 := make([]int64, n)
	for i := 0; i < n; i++ {
		dist[i] = INF
		dp0[i] = 0
		dp1[i] = 0
	}
	dist[s] = 0
	dp0[s] = 1
	var q []int
	q = append(q, s)
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		if u < n {
			for _, v := range g[u] {
				if dist[v] == INF {
					dist[v] = dist[u] + 1
					q = append(q, v)
				}
				if dist[v] == dist[u]+1 {
					dp0[v] += dp0[u]
					dp0[v] %= MOD
				}
				if dist[v] == dist[u] {
					dp1[v] += dp0[u]
					dp1[v] %= MOD
				}
			}
			q = append(q, u+n)
		} else {
			u -= n
			for _, v := range g[u] {
				if dist[v] == dist[u]+1 {
					dp1[v] += dp1[u]
					dp1[v] %= MOD
				}
			}
		}
	}
	cout.Println((dp0[t] + dp1[t]) % MOD)
	// cerr.Println(dist)
	// cerr.Println(dp0)
	// cerr.Println(dp1)
}

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

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

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

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

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

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

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

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

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

type writer struct {
	w *bufio.Writer
}

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

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

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

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

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

// }}}

// vim: fdm=marker


/*
URL:
https://codeforces.com/contest/1473/problem/B
*/

package main

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

var (
	println = fmt.Println

	q    int
	S, T []rune
)

func main() {
	defer stdout.Flush()

	q = readi()
	for i := 0; i < q; i++ {
		S, T = readrs(), readrs()

		solve()
	}
}

func solve() {
	a, b := len(S), len(T)
	l := Lcm(a, b)

	SS := []rune{}
	TT := []rune{}
	for i := 0; i < l/a; i++ {
		SS = append(SS, S...)
	}
	for i := 0; i < l/b; i++ {
		TT = append(TT, T...)
	}

	if string(SS) == string(TT) {
		printf("%s\n", string(SS))
	} else {
		printf("-1\n")
	}
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 0).
// Negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a < 0 || b < 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	if b == 0 {
		return a
	}
	return Gcd(b, a%b)
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 0).
// Negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a < 0 || b < 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	if a == 0 || b == 0 {
		return 0
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	g := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / g) * b
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// 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)
}

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

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

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

// 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
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "strings"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

func gcd(a, b int) int {
    if b == 0 { return a}
    return gcd(b, a % b)
}

func solve() {
    var (
        s, t string
    )
    fmt.Fscanln(input, &s)
    fmt.Fscanln(input, &t)
    if len(s) < len(t) {s, t = t, s}

    ans := ""
    for i := 1; i <= len(s) * len(t); i++ {
        str := strings.Repeat(s, i)
        if len(str) % len(t) == 0 {
            res := true
            for i := 0; i < len(str); i++ {
                if str[i] != t[i % len(t)] {
                    res = false
                    break
                }
            }
            if res {
                ans = str
                goto q
            }
        }
    }

    q:
    if len(ans) > 0 {
        fmt.Fprintln(output, ans)
    } else {
        fmt.Fprintln(output, "-1")
    }
}

package main

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < q; i++ {
		var s, t string
		fmt.Fscan(reader, &s, &t)

		lcmVal := lcm(len(s), len(t))

		var sLcm, tLcm string
		for i := 0; i < lcmVal/len(s); i++ {
			sLcm += s
		}
		for i := 0; i < lcmVal/len(t); i++ {
			tLcm += t
		}

		if sLcm == tLcm {
			fmt.Fprintln(writer, sLcm)
		} else {
			fmt.Fprintln(writer, -1)
		}
	}
}

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

func gcd(a, b int) int {
	if b == 0 {
		return a
	}

	return gcd(b, a%b)
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	a   string
	b   string
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)

		solve(a, b)

	}

}

func solve(a string, b string) {

	index := 0
	flag := true

	//fmt.Println(a[len(a)-len(b) : len(a)])

	if len(a) >= len(b) {

		for i := 0; i < len(a); i++ {

			if a[i] != b[index] {
				flag = false
			}

			index++

			if index == len(b) {
				index = 0
			}

		}

		if a[len(a)-len(b):len(a)] != b {
			flag = false
		}

		if flag {
			for i := 0; i < Lcm(len(a), len(b)); i++ {

				fmt.Fprintf(out, "%c", b[index])

				index++

				if index == len(b) {
					index = 0
				}

				if i == Lcm(len(a), len(b))-1 {
					fmt.Fprintf(out, "\n")
				}

			}
		} else {
			fmt.Fprintln(out, "-1")
		}

	} else {

		for i := 0; i < len(b); i++ {

			if b[i] != a[index] {
				flag = false
			}

			index++

			if index == len(a) {
				index = 0
			}

		}

		if b[len(b)-len(a):len(b)] != a {
			flag = false
		}

		if flag {
			for i := 0; i < Lcm(len(a), len(b)); i++ {

				fmt.Fprintf(out, "%c", a[index])

				index++

				if index == len(a) {
					index = 0
				}

				if i == Lcm(len(a), len(b))-1 {
					fmt.Fprintf(out, "\n")
				}

			}
		} else {
			fmt.Fprintln(out, "-1")
		}

	}

}

//最大公因數
func Gcd(a int, b int) int {
	var twoCounter uint

	for {
		if a == b || b == 0 {
			return a << twoCounter
		} else if a == 0 {
			return b << twoCounter
		} else if a&1 == 0 {
			a >>= 1

			if b&1 == 0 {
				b >>= 1

				twoCounter += 1
			}
		} else if b&1 == 0 {
			b >>= 1
		} else if a > b {
			a = (a - b) >> 1
		} else {
			b = (b - a) >> 1
		}
	}
}

//最小公倍數
func Lcm(a int, b int) int {
	return a * b / Gcd(a, b)
}

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, 1e6), 1e6)
}

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

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

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

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		ss := sstring()
		tt := sstring()
		printf("%s\n", sol(ss, tt))
	}
}

func sol(s, t string) string {
	si, ti := 0, 0
	count := 0
	flag := false
	for {
		if s[si] != t[ti] {
			return "-1"
		}
		count++
		if si == 0 && ti == 0 && flag {
			break
		}
		flag = true
		si++
		si %= len(s)
		ti++
		ti %= len(t)
	}
	count--
	ret := ""
	for i := 0; i < count/len(s); i++ {
		ret += s
	}
	return ret
}

package main

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

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

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

func gcd(x, y int) int {
	if x < y {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(s, t string) string {
	l := lcm(len(s), len(t))
	a := strings.Repeat(s, l/len(s))
	for i := 0; i < len(a); i++ {
		if a[i] != t[i%len(t)] {
			return "-1"
		}
	}
	return a
}

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

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1473B
 Date: 11/06/21
 User: pepradere
 URL: https://codeforces.com/contest/1473/problem/B
 Problem: CF1473B
**/
func (in *CF1473B) Run() {

	q := in.NextInt()
	for ; q > 0; q-- {
		s := in.NextString()
		t := in.NextString()
		ans := "-1"
		if len(s) == len(t) {
			if s == t {
				ans = s
			}
		} else {
			ans = in.g(s, t)
		}

		fmt.Println(ans)
	}

}

func (in *CF1473B) g(s, t string) string {
	os := s
	ot := t
	ans := "-1"
	a, b := 1, 1
	for ; len(s) != len(t) && a < 5000 && b < 5000; {
		if len(s) < len(t) {
			s = in.f(s, os)
			a++
		} else if len(s) > len(t) {
			t = in.f(t, ot)
			b++
		}
	}
	if len(s) == len(t) && s == t {
		ans = t
	}

	return ans
}

func (in *CF1473B) f(str string, o string) string {
	return o + str
}

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

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

package main

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

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

func Scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func Scanln(a ...interface{})  { fmt.Fscanln(reader, a...) }
func Print(a ...interface{})   { fmt.Fprint(writer, a...) }
func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }

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

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

func main() {
	defer writer.Flush()
	var t int
	Scanln(&t)
	for tc := 0; tc < t; tc++ {
		var a, b string
		Scanln(&a)
		Scanln(&b)
		n := len(a)
		m := len(b)
		g := lcm(n, m)
		var cur_a, cur_b string
		for i := 0; i < g/n; i++ {
			cur_a += a
		}
		for i := 0; i < g/m; i++ {
			cur_b += b
		}
		if cur_a == cur_b {
			Println(cur_a)
		} else {
			Println(-1)
		}
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for q := scanInt(); q > 0; q-- {
		s, t := ScanString(), ScanString()

		n := lcm(len(s), len(t))

		s = strings.Repeat(s, n/len(s))
		t = strings.Repeat(t, n/len(t))

		if s == t {
			fmt.Println(s)
		} else {
			fmt.Println(-1)
		}
	}
}

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

func gcd(x, y int) int {
	switch {
	case x > y:
		return gcd(x%y, y)
	case x == 0:
		return y
	default:
		return gcd(y%x, x)
	}
}

package main

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

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

func gen(a, b string) string {
	var c string
	for i := 0; ; i++ {
		c += string(a[i%len(a)])
		if c[i] != b[i%len(b)] {
			return "-1"
		}
		if (i+1)%len(a) == 0 && (i+1)%len(b) == 0 {
			return c
		}
	}
	return "-1"
}

func main() {
	t := 0
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var a, b string
		fmt.Fscan(in, &a, &b)
		if len(a) < len(b) {
			a, b = b, a
		}
		fmt.Fprintln(out, gen(a, b))
	}
	out.Flush()
}

package main

// https://codeforces.com/problemset/problem/313/B
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(s string, l string) string {
	l1 := len(s)
	l2 := len(l)
	// iisaikais viemeer otrais
	if l1 < l2 {
		tmp := s
		s = l
		l = tmp
	}
	l1 = len(s)
	l2 = len(l)

	gcd := gcd(l1, l2)
	// 3 , 2
	// 1
	m := l1 * l2 / gcd
	//	fmt.Println("m", m)
	ll := strings.Repeat(l, m/l2)
	//	fmt.Println("ll", ll)

	ss := strings.Repeat(s, m/l1)
	//	fmt.Println("ss", ss)

	if ss == ll {
		return ss
	}

	return "-1"

}
func main() {

	// fmt.Println(3 * 2 / gcd(3, 2))
	buf := make([]byte, 0, 1000000)

	reader := bufio.NewScanner(os.Stdin)
	reader.Buffer(buf, 1000000)
	reader.Scan()
	// line := reader.Text() // number of test cases

	//	m := reader.Text()

	for reader.Scan() {

		s1 := reader.Text()
		reader.Scan()
		t1 := reader.Text()

		fmt.Println(lcm(s1, t1))

	}

	if err := reader.Err(); err != nil {
		fmt.Println("Error reading from stdin", err)
	}
}

package main

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

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

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

func lcm(a, b int) int {
	p := a * b
	for ; b != 0; a %= b {
		if b > a {
			a, b = b, a
		}
		if b == 0 {
			break
		}
	}
	return p / a
}

func solve() {
	var s, t string
	scanf("%s\n%s\n", &s, &t)
	n := len(s)
	m := len(t)
	d := lcm(n, m)
	ss := ""
	for i := 0; i < d / n; i++ {
		ss += s
	}
	tt := ""
	for i := 0; i < d / m; i++ {
		tt += t
	}
	if tt == ss {
		printf(tt + "\n")
	} else {
		printf("-1\n")
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

func main() {
	sc:=bufio.NewScanner(os.Stdin)
	sc.Scan()
	l,_:=strconv.Atoi(sc.Text())
	for i:=0; i<l;i++{
		sc.Scan()
		a := sc.Text()
		sc.Scan()
		fmt.Printf("%s\n",fn(a, sc.Text()))
	}
}

func fn(a string, d string) string{
	l1:=len(a)
	l2:=len(d)
	p:=l1*l2
	i1,i2 := 1,1
	for true{
		if i1*l1 == i2*l2 {
			if strings.Repeat(a, i1) == strings.Repeat(d, i2)  {
				return strings.Repeat(a, i1)
			}else{
				return "-1"
			}

		}
		if i1*l1>p || i2*l2>p{
			break
		}
		if l2*i2>l1*i1{
			i1++
		}else {
			i2++
		}

	}
	return "-1"
}

package main

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

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		STRING1 := make([]byte, 0)
		NEWSTRING := make([]byte, 0)
		fmt.Fscan(input, &n)

		fmt.Fscan(input, &STRING1)
		fmt.Fscan(input, &NEWSTRING)

		len1 := len(STRING1)
		len2 := len(NEWSTRING)

		if len2 >= len1 {
			initial := len2
			for i := 1; i < len1+2; i++ {
				if initial%len1 == 0 {
					break
				} else {
					initial = initial + len2
				}
			}

			var LCM string
			for j := 1; j < (initial/len2)+1; j++ {
				LCM = LCM + string(NEWSTRING)
			}
			mao := 0
			for k := 0; k < initial/len1; k++ {
				if string(STRING1) != LCM[(k*len1):(k+1)*len1] {
					mao = mao + 1
					break
				}
			}

			if mao > 0 {
				fmt.Println(-1)
			} else {
				fmt.Println(LCM)
			}

		} else {
			initial := len1
			for i := 1; i < len2+2; i++ {
				if initial%len2 == 0 {
					break
				} else {
					initial = initial + len1
				}
			}

			var LCM string
			for j := 1; j < (initial/len1)+1; j++ {
				LCM = LCM + string(STRING1)
			}
			mao := 0
			for k := 0; k < initial/len2; k++ {
				if string(NEWSTRING) != LCM[(k*len2):(k+1)*len2] {
					mao = mao + 1
				}
			}

			if mao > 0 {
				fmt.Println(-1)
			} else {
				fmt.Println(LCM)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "strings"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

func gcd(a, b int) int {
    if b == 0 { return a}
    return gcd(b, a % b)
}

func solve() {
    var (
        s, t string
    )
    fmt.Fscanln(input, &s)
    fmt.Fscanln(input, &t)
    if len(s) < len(t) {s, t = t, s}

    ans := ""
    for i := 1; i < len(s) * len(t); i++ {
        str := strings.Repeat(s, i)
        if len(str) % len(t) == 0 {
            res := true
            for i := 0; i < len(str); i++ {
                if str[i] != t[i % len(t)] {
                    res = false
                    break
                }
            }
            if res {
                ans = str
                goto q
            }
        }
    }

    q:
    if len(ans) > 0 {
        fmt.Fprintln(output, ans)
    } else {
        fmt.Fprintln(output, "-1")
    }
}

package main

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < q; i++ {
		var s, t string
		fmt.Fscan(reader, &s, &t)

		g := gcd(s, t)
		if g == -1 {
			fmt.Fprintln(writer, -1)
			continue
		}

		lcm := len(s) * len(t) / g
		ans := s

		for len(ans) < lcm {
			ans += s
		}

		fmt.Fprintln(writer, ans)
	}
}

func gcd(s, t string) int {
	if len(t) > len(s) {
		tmp := t
		t = s
		s = tmp
	}

	if composedOfString(s, t) {
		return len(t)
	}

	if composedOf(s, 'a') && composedOf(t, 'a') {
		return 1
	}

	if composedOf(s, 'b') && composedOf(t, 'b') {
		return 1
	}

	return -1
}

func composedOf(s string, r rune) bool {
	for _, v := range s {
		if v != r {
			return false
		}
	}

	return true
}

func composedOfString(s string, r string) bool {
	for len(s) > 0 {
		if len(s) < len(r) {
			return false
		}

		if s[:len(r)] != r {
			return false
		}

		s = s[len(r):]
	}

	return true
}

package main

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

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

func main() {
	defer writer.Flush()

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

	for i := 0; i < q; i++ {
		var s, t string
		fmt.Fscan(reader, &s, &t)

		g := gcd(s, t)
		if g == -1 {
			fmt.Fprintln(writer, -1)
			continue
		}

		lcm := len(s) * len(t) / g
		ans := s

		for len(ans) < lcm {
			ans += s
		}

		fmt.Fprintln(writer, ans)
	}
}

func gcd(s, t string) int {
	if composedOf(s, 'a') && composedOf(t, 'a') {
		return 1
	}

	if composedOf(s, 'b') && composedOf(t, 'b') {
		return 1
	}

	if len(t) > len(s) {
		tmp := t
		t = s
		s = tmp
	}

	if !composedOfString(s, t) {
		return -1
	}

	return len(t)
}

func composedOf(s string, r rune) bool {
	for _, v := range s {
		if v != r {
			return false
		}
	}

	return true
}

func composedOfString(s string, r string) bool {
	for len(s) > 0 {
		if len(s) < len(r) {
			return false
		}

		if s[:len(r)] != r {
			return false
		}

		s = s[len(r):]
	}

	return true
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	t   int
	a   string
	b   string
)

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)

		solve(a, b)

	}

}

func solve(a string, b string) {

	index := 0
	flag := true

	if len(a) >= len(b) {

		for i := 0; i < len(a); i++ {

			if a[i] != b[index] {
				flag = false
			}

			index++

			if index == len(b) {
				index = 0
			}

		}

		if a[len(a)-1] != b[len(b)-1] {
			flag = false
		}

		if flag {
			for i := 0; i < Lcm(len(a), len(b)); i++ {

				fmt.Fprintf(out, "%c", b[index])

				index++

				if index == len(b) {
					index = 0
				}

				if i == Lcm(len(a), len(b))-1 {
					fmt.Fprintf(out, "\n")
				}

			}
		} else {
			fmt.Fprintln(out, "-1")
		}

	} else {

		for i := 0; i < len(b); i++ {

			if b[i] != a[index] {
				flag = false
			}

			index++

			if index == len(a) {
				index = 0
			}

		}

		if a[len(a)-1] != b[len(b)-1] {
			flag = false
		}

		if flag {
			for i := 0; i < Lcm(len(a), len(b)); i++ {

				fmt.Fprintf(out, "%c", a[index])

				index++

				if index == len(a) {
					index = 0
				}

				if i == Lcm(len(a), len(b))-1 {
					fmt.Fprintf(out, "\n")
				}

			}
		} else {
			fmt.Fprintln(out, "-1")
		}

	}

}

//最大公因數
func Gcd(a int, b int) int {
	var twoCounter uint

	for {
		if a == b || b == 0 {
			return a << twoCounter
		} else if a == 0 {
			return b << twoCounter
		} else if a&1 == 0 {
			a >>= 1

			if b&1 == 0 {
				b >>= 1

				twoCounter += 1
			}
		} else if b&1 == 0 {
			b >>= 1
		} else if a > b {
			a = (a - b) >> 1
		} else {
			b = (b - a) >> 1
		}
	}
}

//最小公倍數
func Lcm(a int, b int) int {
	return a * b / Gcd(a, b)
}

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, 1e6), 1e6)
}

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

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

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

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		ss := sstring()
		tt := sstring()
		printf("%s\n", sol(ss, tt))
	}
}

func sol(s, t string) string {
	si, ti := 0, 0
	count := 0
	flag := false
	for {
		if s[si] != t[ti] {
			return "-1"
		}
		count++
		if si == 0 && ti == 0 && flag {
			break
		}
		flag = true
		si++
		si %= len(s)
		ti++
		ti %= len(t)
	}
	ret := ""
	for i := 0; i < count/len(s); i++ {
		ret += s
	}
	return ret
}