package main

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

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

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

func solve() {
	var n, k int64
	scan(&n, &k)
	mod := int64(1e9) + 7
	var ans, x int64 = 0, 1
	for k > 0 {
		ans += x * (k % 2)
		ans %= mod
		x %= mod
		x *= n
		k /= 2
	}
	printf("%d\n", ans)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, k, tot, pl := int64(0), int64(0), int64(0), int64(1)
		fmt.Fscan(f, &n, &k)
		p := strconv.FormatInt(k, 2)
		for j := len(p) - 1; j >= 0; j-- {
			if string(p[j]) == "1" {
				tot += pl
			}
			pl *= n
			pl %= (1e9 + 7)
		}
		fmt.Fprintln(w, tot%(1e9+7))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

/*

 */

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

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

	for ; t > 0; t-- {
		var n, k int64
		scanf("%d %d\n", &n, &k)

		num := int64(0)
		power := int64(0)

		for k != 0 {
			if k&1 != 0 {
				bigNum := big.NewInt(0)
				bigNum.Exp(big.NewInt(n), big.NewInt(power), big.NewInt(1_000_000_007))

				num += bigNum.Int64()
				num %= 1_000_000_007
			}

			k >>= 1
			power++
		}

		fmt.Fprintln(writer, num)
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

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

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

		const mod = 1e9 + 7
		var c int64
		for p := int64(1); k > 0; k >>= 1 {
			c = (c + k&1*p) % mod
			p = p * n % mod
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1594B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7

	var T, n, k int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ans := int64(0)
		for p := int64(1); k > 0; k >>= 1 {
			ans = (ans + k&1*p) % mod
			p = p * n % mod
		}
		Fprintln(out, ans)
	}
}

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

package main

import(
	"fmt"
)
const mod =1e9+7
func main() {
	var t,n,k,ans,d int64
	fmt.Scan(&t)
	for t>0{
		t--
		fmt.Scan(&n,&k)
		ans=0
		d=1
		for k>0{
			if k%2==1{
				ans=(ans+d)%mod
			}
			k=k/2
			d=(d*n)%mod
		}
		fmt.Println(ans)
	}
}

package main

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

const MOD = 1e9 + 7

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 _int() int {
	s := _string()
	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 _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int64()
		k := _int64()
		printf("%d\n", sol(n, k))
	}
}

func sol(n, k int64) int64 {
	ret := int64(0)
	curr := int64(1)
	for k > 0 {
		if k&1 == 1 {
			ret += curr
		}
		curr *= n
		curr %= MOD
		k >>= 1
	}
	return ret % MOD
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	//out := bufio.NewWriter(os.Stdout)
	mod := int64(1000000007)
	var t int
	var n ,k int64
	fmt.Fscanf(in, "%d\n", &t)
	for i:= 0;i < t;i++{

		fmt.Fscanf(in, "%d %d\n", &n,&k)
		d := int64(1)
		ans := int64(0)
		for k > 0{
			if (k%2) == 1{
				ans = (ans + d)%mod
			}
			d = (d*n)%mod
			k /= 2
		}
		fmt.Printf("%v\n",ans)
	}

}

package main

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

var N, K int64

const MOD int64 = 1000000007

var v []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &N, &K)

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int64 {
	if K == 1{
		return binpow(N, 0, MOD)
	} else if K == 2 {
		return binpow(N, 1, MOD)
	} else if K == 3 {
		return binpow(N, 0, MOD) + binpow(N, 1, MOD)
	}

	var sum int64

	for ; K > 0; {
		var i int64
		for i = 0; i <= 40; i++ {
			var t int64
			t = 1 << uint(i)

			if t <= K {
				continue
			}
			break
		}
		var d int64
		d = i - 1

		t := binpow(N, d, MOD)

		sum += t

		sum = sum % MOD

		K -= (1 << uint(d))
	}

	return sum % MOD

}

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

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

func binpow(a int64, b int64, m int64) int64 {
	a %= m
	var res int64 = 1
	for ; b > 0;
	{
		if b & 1 == 1 {
			res = res * a % m
		}

		a = a * a % m
		b >>= 1
	}
	return res
}

package main

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

func main()  {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int64
	fmt.Fscan(input, &t)
	for t > 0 {
		var n int64
		var k int64
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)
		mod:=1000000007
		fmt.Println(getAns(n,k, int64(mod)))
		t--
	}
}

func getAns(n int64, k int64, mod int64) int64 {
	ans:=int64(0)
	temp:=int64(1)
	for k>0 {
		if k%2==1 {
			ans+=temp
		}
		k/=2
		temp*=n
		temp%=mod
	}
	return ans%mod
}

package main

import "fmt"

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

func solve() {
	mod := 1e9 + 7
	var n, k int
	fmt.Scan(&n, &k)
	var res, base int64
	res, base = 0, 1
	for k > 0 {
		if k&1 == 1 {
			res = (res + base) % int64(mod)

		}
		k /= 2
		base = (base * int64(n)) % int64(mod)
	}
	fmt.Println(res % int64(mod))
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, k int
		var u int64
		e := int64(1)
		m := int64(1000000007)
		fmt.Scanf("%d %d\n", &n, &k)
		for ; k > 0; k /= 2 {
			if math.Mod(float64(k), 2.0) == 1 {
				u = (u + e) % m
			}
			e = (e * int64(n)) % m
		}
		fmt.Printf("%d\n", u)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, k int
		fmt.Scanf("%d %d\n", &n, &k)
		var kBinary string = fmt.Sprintf("%b", k)
		var u int64
		e := int64(1)
		for i := len(kBinary) - 1; i >= 0; i-- {
			if kBinary[i] == '1' {
				u += e
				u %= int64(1000000007)
			}
			e *= int64(n)
			e %= int64(1000000007)
		}
		fmt.Printf("%d\n", u)
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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, k int64

		fmt.Fscan(input, &n, &k)

		var ans int64

		pp := k
		init := int64(1)
		for pp > 0 {
			if pp%2 == 1 {
				ans = ans + init
				ans = ans % 1000000007
				pp = pp / 2
			} else {
				pp = pp / 2

			}
			init = init * n
			init = init % 1000000007

		}
		fmt.Println(ans)

	}

}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n, k int
		fmt.Fscanf(r, "%d %d\n", &n, &k)

		res := int64(0)
		x := int64(1)
		for i := 0; i < 32; i++ {
			if k&(1<<i) != 0 {
				res += x
				res %= 1000000007
			}
			x *= int64(n)
			x %= 1000000007
		}

		fmt.Println(res)
	}
}

package main

import "fmt"

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

func solve() {
	mod := 1e9 + 7
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k&1 == 1 {
			res += (base % int(mod))
			res = res % int(mod)
		}
		k /= 2
		base *= n
	}
	fmt.Println(res % int(mod))
}

package main

import "fmt"

const (
	mod = 1e9 + 7
)

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k&1 == 1 {
			res += (base % int(mod))
			res = res % int(mod)
		}
		k /= 2
		base *= n
	}
	fmt.Println(res % int(mod))
}

package main

import "fmt"

const (
	mod = 1e9 + 7
)

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k%2 == 1 {
			res += base
					}
		k /= 2
		base *= n
	}
	fmt.Println(res % int(mod))
}

package main

import "fmt"

const (
	mod = 1e9 + 7
)

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k%2 == 1 {
			res += base
			res = res % int(mod)
		}
		k /= 2
		base *= n
	}
	fmt.Println(res % int(mod))
}

package main

import "fmt"

const (
	mod = 1e9 + 7
)

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k%2 == 1 {
			res += base
		}
		k /= 2
		base *= n
	}
	fmt.Println(res % mod)
}

package main

import "fmt"

const (
	mod = 1e9 + 7
)

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	res, base := 0, 1
	for k > 0 {
		if k%2 == 1 {
			res += base
		}
		k /= 2
		base *= n
	}
	fmt.Println(res)
}

package main

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

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

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

func solve() {
	var n, k int
	scan(&n, &k)
	mod := int(1e9) + 7
	x, ans := 1, 0
	for k > 0 {
		ans += x * (k % 2)
		ans %= mod
		x *= n
		k /= 2
	}
	printf("%d\n", ans)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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, k int

		fmt.Fscan(input, &n, &k)

		var ans int

		p := k
		init := 1
		for p > 0 {

			if p%2 == 1 {
				ans = ans + init
				ans = ans % 1000000007
				p = p / 2
			} else {
				p = p / 2

			}
			init = init * n
			init = init % 1000000007

		}
		fmt.Println(ans)

	}

}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n, k int
		fmt.Fscanf(r, "%d %d\n", &n, &k)

		res := 0
		x := 1
		for i := 0; i < 32; i++ {
			if k&(1<<i) != 0 {
				res += x
				res %= 1000000007
			}
			x *= n
			x %= 1000000007
		}

		fmt.Println(res)
	}
}


package main

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

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

func CF1670E(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()
	const (
		four = 4
		six  = 6
	)

	findMax := func(n int64) int64 {
		left := n % four
		if left == 0 {
			return n / four
		}
		for i := n / four; i >= 0; i-- {
			sLeft := (n - i*4) % six
			if sLeft == 0 {
				return i + (n-i*4)/six
			}
		}
		return -1
	}

	findMin := func(n int64) int64 {
		left := n % six
		if left == 0 {
			return n / six
		}
		for i := n / six; i >= 0; i-- {
			sLeft := (n - i*6) % four
			if sLeft == 0 {
				return i + (n-i*6)/four
			}
		}
		return -1
	}

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int64
		fmt.Fscan(r, &n)
		if n%2 == 1 {
			fmt.Fprintln(w, "-1")
			continue
		}

		f, s := findMax(n), findMin(n)
		if f == -1 || s == -1 {
			fmt.Fprintln(w, "-1")
			continue
		}
		fmt.Fprintln(w, s, f)
	}

}

package main

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

func main_div2_791_A() {
	_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 int64
		Fscan(in, &n)
		// x * 4 + y * 6 = n
		// x * 2  + y * 3 = n/2
		// x * 2  + y * 2  + y = n/2

		// max min
		// max 4 best
		if n%2 != 0 {
			Fprintln(out, -1)
			return
		}
		var k = n / 2
		if k == 1 {
			Fprintln(out, -1)
			return
		}
		var min, max int64
		if k%2 == 0 {
			max = k / 2
		} else {
			max = 1 + (k-3)/2
		}
		if k%3 == 0 {
			min = k / 3
		} else {
			if k%3 == 2 {
				k -= 2
				min = 1 + k/3
			} else {
				k -= 4
				min = 2 + k/3
			}
		}
		Fprintln(out, min, max)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div2_791_A()
}

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

// 1679A - AvtoBus

// Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses.
// You own a small bus service business and you have just received an order to replace n tires. You know that the bus fleet owns two types of buses: with two axles (these buses have 4 wheels) and with three axles (these buses have 6 wheels).
// You don't know how many buses of which type the AvtoBus bus fleet owns, so you wonder how many buses the fleet might have. You have to determine the minimum and the maximum number of buses that can be in the fleet if you know that the total number of wheels for all buses is n.

// Input
// The first line contains an integer t (1≤t≤1000) — the number of test cases. The following lines contain description of test cases.
// The only line of each test case contains one integer n (1≤n≤10^18) — the total number of wheels for all buses.

// Output
// For each test case print the answer in a single line using the following format.
// Print two integers x and y (1≤x≤y) — the minimum and the maximum possible number of buses that can be in the bus fleet.
// If there is no suitable number of buses for the given n, print the number −1 as the answer.

// Example
// input
// 4
// 4
// 7
// 24
// 998244353998244352
// output
// 1 1
// -1
// 4 6
// 166374058999707392 249561088499561088

// Note

// In the first test case the total number of wheels is 4. It means that there is the only one bus with two axles in the bus fleet.
// In the second test case it's easy to show that there is no suitable number of buses with 7 wheels in total.
// In the third test case the total number of wheels is 24. The following options are possible:
//  • Four buses with three axles.
//  • Three buses with two axles and two buses with three axles.
//  • Six buses with two axles.
// So the minimum number of buses is 4 and the maximum number of buses is 6.

// Tutorial

// Let the number of buses with two axles is x and the number of buses with three axles is y. Then the equality 4x+6y=n must be true. If n is odd, there is no answer, because the left part of the equality is always even. Now we can divide each part of the equality by two: 2x+3y=n/2.
// Let's maximize the number of buses. Then we should make x as large as possible. So, we will get 2+…+2+2=n2 if n2 is even, and 2+…+2+3=n/2 otherwise. In both cases the number of buses is ⌊n/2⌋.
// Now let's minimize the number of buses. So, we should make y as large is possible. We will get 3+…+3+3+3=n/2 if n/2 is divisible by 3, 3+…+3+3+2=n/2 if n≡2(mod 3), and 3+…+3+2+2=n/2 if n≡1(mod 3). In all cases the number of buses is ⌈n/3⌉.
// Also don't forget the case n=2 — each bus has at least four wheels, so in this case there is no answer.
// Time complexity: O(1).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t uint
	var n uint64

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			if n&1 == 1 || n < 4 {
				fmt.Fprintln(writer, -1)
			} else {
				fmt.Fprintln(writer, (n+5)/6, n/4)
			}
		}
	}

	writer.Flush()
}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	mins := map[int64]int64{0: 0, 4: 1, 6: 1, 8: 2, 10: 2, 12: 2, 14: 3}
	maxes := map[int64]int64{0: 0, 4: 1, 6: 1, 8: 2, 10: 2, 12: 3, 14: 3}
	for t := 1; t <= T; t++ {
		var n int64
		fmt.Fscan(reader, &n)
		if n%2 == 1 || n == 2 {
			fmt.Println(-1)
		} else {
			if n%12 == 2 {
				fmt.Println((n-14)/6+mins[14], (n-14)/4+maxes[14])
			} else {
				rem := n - (n % 12)
				fmt.Println(rem/6+(mins[n%12]), rem/4+(maxes[n%12]))
			}
		}

	}
}

package main

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

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n int64
		fmt.Fscan(scanner, &n)
		if n%2 == 1 || n == 2 {
			fmt.Fprintln(writer, "-1")
		} else {
			min := n / 4 // max
			max := n / 6 // hmm
			switch n - (6 * max) {
			case 2:
				max++
			case 4:
				max++
			}
			fmt.Fprintln(writer, max, min)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
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 gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
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
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi64()
		m1,m2 := int64(0),int64(0)
		if N % 2 == 1 || N < 4 {
			m1 = -1
		} else {
			n1 := N; for n1 % 6 != 0 { n1 -= 4; m1++ }; m1 += n1/6
			n2 := N; for n2 % 4 != 0 { n2 -= 6; m2++ }; m2 += n2/4
		}
		if m1 == -1 { fmt.Fprintln(wrtr,-1) } else { fmt.Fprintf(wrtr,"%v %v\n",m1,m2) }
	}
}

package main

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

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

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

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

		// 4x
		// 6y
		// 4x + 6y = n

		var mn, mx int64 = 1e18, 0
		for i := 0;i <= 10; i++ {
			if int64(i * 4) > n {
				break
			}
			if int64(n - int64(i * 4)) % 6 == 0 {
				j := int64((n - int64(i * 4)) / 6)
				mn = min(mn, int64(int64(i) + j))
				mx = max(mx, int64(int64(i) + j))
			}
		}
		for i := 0;i <= 10; i++ {
			if int64(i * 6) > n {
				break
			}
			if int64(n - int64(i * 6)) % 4 == 0 {
				j := int64((n - int64(i * 6)) / 4)
				mn = min(mn, int64(int64(i) + j))
				mx = max(mx, int64(int64(i) + j))
			}
		}
		if mn == 1e18 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, mn, mx)
		}
	}
}

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

package main

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

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

func slove() {
	var n int64
	fmt.Fscan(r, &n)
	if n % 2 == 1 || n <= 3{
		fmt.Fprintln(w, "-1")
		return
	}
	var ll, rr int64
	if n % 6 == 2 {
		ll = 2 + (n - 8) / 6
	} else {
		ll = n / 6
		if n % 6 != 0 {
			ll++
		}
	}
	if n % 4 == 2 {
		rr = 1 + (n - 6) / 4
	} else {
		rr = n / 4
	}
	fmt.Fprintln(w, ll, rr)
}

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		min := int64(0)
		max := int64(0)
		a := n / 4
		llantasSobrantes := n - (a * 4)
		if llantasSobrantes == 2 || llantasSobrantes == 0 {
			max = a
			min = a
		} else {
			max = 0
		}

		b := n / 6
		llantasSobrantes = n - (b * 6)
		if llantasSobrantes == 2 || llantasSobrantes == 4 {
			min = b + 1
		} else if llantasSobrantes == 0 {
			min = b
		}

		if min == 0 || max == 0 {
			fmt.Println(-1)
		} else {
			fmt.Println(min, max)
		}

	}
}

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

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

package main

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

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

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

		if n%2 != 0 || n < 4 {
			fmt.Fprintln(out, -1)
		} else {
			a := n / 4
			b := n / 6
			if n%6 != 0 {
				b++
			}
			fmt.Fprintln(out, b, a)

		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		min := int64(0)
		max := int64(0)
		a := int64(math.Floor(float64(n) / 4.))
		llantasSobrantes := n - (a * 4)
		if llantasSobrantes == 2 || llantasSobrantes == 0 {
			max = a
			min = a
		} else {
			max = 0
		}

		b := int64(math.Floor(float64(n) / 6.))
		llantasSobrantes = n - (b * 6)
		if llantasSobrantes == 2 || llantasSobrantes == 4 {
			min = b + 1
		} else if llantasSobrantes == 0 {
			min = b
		}

		if min == 0 || max == 0 {
			fmt.Println(-1)
		} else {
			fmt.Println(min, max)
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= int64(2)
			max := int64(float64(n) / float64(2))
			min := int64(0)
			if n%3 == 0 {
				min = n / int64(3)
			} else {
				min = n/int64(3) + int64(1)
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= int64(2)
			max := int64(float64(n) / float64(2))
			min := int64(0)
			if n%3 == 0 {
				min = n / 3
			} else {
				min = n/3 + 1
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= 2
			max := int64(float64(n) / float64(2))
			min := int64(float64(n) / float64(2))
			if n%3 == 0 {
				min = n / 3
			} else {
				min = n/3 + 1
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= 2
			max := int64(float64(n) / 2.)
			min := int64(float64(n) / 2.)
			if n%3 == 0 {
				min = n / 3
			} else {
				min = n/3 + 1
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= 2
			max := int64(math.Floor(float64(n) / 2.))
			min := int64(float64(n) / 2.)
			if n%3 == 0 {
				min = n / 3
			} else {
				min = (n / 3) + 1
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		if n%2 != 0 || n < 4 {
			fmt.Println(-1)
		} else {
			n /= 2
			max := int64(math.Floor(float64(n) / 2.))
			min := int64(math.Ceil(float64(n) / 2.))
			if n%3 == 0 {
				min = n / 3
			} else {
				min = (n / 3) + 1
			}

			fmt.Println(min, max)
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1679A
Date: 8/21/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1679/A
Problem: CF1679A
**/
func (in *CF1679A) Run() {
  for t := in.NextInt(); t > 0; t-- {
    n := in.NextInt64()
    if n%4 == 0 || n%6 == 0 {
      if n%4 == 0 && n%6 != 0 {
        fmt.Println(n/4, n/4)
      } else if n%6 == 0 && n%4 != 0 {
        fmt.Println(n/6, n/6)
      } else {
        fmt.Println(n/6, n/4)
      }

    } else {
      fmt.Println(-1)
    }
  }
}

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

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

package main

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

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

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

		if n%2 != 0 || n < 4 {
			fmt.Fprintln(out, -1)
		} else {
			a := n / 4
			b := n / 6
			if n%6 != 0 {
				b = a
			}
			fmt.Fprintln(out, b, a)

		}
	}
}

package main

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

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

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

		a := n / 4
		if n%4 != 0 && (a-1)*4+6 != n {
			a = -1
		}

		b := n / 6
		if n%6 != 0 && (b-1)*6+4 != n {
			b = a
		}

		if a <= 0 && b <= 0 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, b, a)
		}
	}
}

package main

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

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

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

		a := n / 4
		if n%4 != 0 && (a-1)*4+6 != n {
			a = -1
		}

		b := n / 6
		if n%6 != 0 && (b-1)*6+4 != n {
			b = a
		}

		if a < 0 && b < 0 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, b, a)
		}
	}
}

package main

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

func main_div2_791_A() {
	_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 int64
		Fscan(in, &n)
		// x * 4 + y * 6 = n
		// x * 2  + y * 3 = n/2
		// x * 2  + y * 2  + y = n/2

		// max min
		// max 4 best
		if n%2 != 0 {
			Fprintln(out, -1)
			return
		}
		var k = n / 2
		if k == 1 {
			Fprintln(out, -1)
			return
		}
		var min, max int64
		if k%2 == 0 {
			max = k / 2
		} else {
			k -= 3
			max = 1 + k/2
		}
		if k%3 == 0 {
			min = k / 3
		} else {
			if k%3 == 2 {
				k -= 2
				min = 1 + k/3
			} else {
				k -= 4
				min = 2 + k/3
			}
		}
		Fprintln(out, min, max)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div2_791_A()
}


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

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

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

func main() {
	var (
		n, k int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &k)
	middle := k / 2
	cost := make([][]int, k)
	used := make([][]bool, k)
	for i := 0; i < k; i++ {
		used[i] = make([]bool, k)
		cost[i] = make([]int, k)
		cost[i][0] = abs(i - middle) + middle
		for j := 1; j < k; j++ {
			cost[i][j] = abs(i - middle) + abs(j - middle)
			cost[i][j] += cost[i][j - 1]
		}
	}

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

		mincost := int(1e9)
		minrow := -1
		minfrom := 0
		for row := 0; row < k; row++ {
			for s := 0; s + group - 1 < k; s++ {
				se := s + group - 1
				clean := true
				for cc := s; cc <= se; cc++ {
					if used[row][cc] {
						clean = false
						break
					}
				}
				if !clean {
					continue
				}

				currcost := cost[row][se]
				if s > 0 {
					currcost -= cost[row][s - 1]
				}

				if currcost < mincost {
					mincost = currcost
					minrow = row
					minfrom = s
				}
			}
		}
		if minrow < 0 {
			fmt.Println(-1)
		} else {
			fmt.Println(minrow + 1, minfrom + 1, minfrom + group)
			for cc := minfrom; cc < minfrom + group; cc++ {
				used[minrow][cc] = true
			}
		}
	}
}

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

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, k := getI(), getI()
  tails := make([][]int, k+1)
  for x := 1; x <= k; x++ {
    tails[x] = make([]int, k+1)
    for y := 1; y <= k; y++ {
      tails[x][y] = k+1-y
    }
  }
  c := (k+1)/2
  for ni := 0; ni < n; ni++ {
    m := getI()
    bestX, bestY, bestScore := -1, -1, -1
    for x := 1; x <= k; x++ {
      v := c-x
      if v < 0 {
        v *= -1
      }
      for y := 1; y <= k; y++ {
        if tails[x][y] < m {
          continue
        }
        la, ra, lb, rb := c, c, c, c
        L, R := y, y+m-1
        if L < c {
          la, ra = L, c-1
          if ra > R {
            ra = R
          }
        }
        if R > c {
          lb, rb = c+1, R
          if lb < L {
            lb = L
          }
        }
        score := (R+1-L)*v
        score += (ra+1-la)*c - (la+ra)*(ra+1-la)/2
        score += (lb+rb)*(rb+1-lb)/2 - (rb+1-lb)*c
        if bestScore == -1 || score < bestScore {
          bestX, bestY, bestScore = x, y, score
        }
      }
    }
    if bestScore == -1 {
      writer.WriteString("-1\n")
    } else {
      writer.WriteString(fmt.Sprintf("%d %d %d\n", bestX, bestY, bestY+m-1))
      for y := bestY+m-1; y >= bestY; y-- {
        tails[bestX][y] = 0
      }
      for y := bestY-1; y >= 1 && tails[bestX][y] != 0; y-- {
        tails[bestX][y] = bestY-y
      }
    }
  }
}

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
type crows struct {
	lf, rf int
}

func main() {
	var (
		n, k int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &k)
	rows := make([]*crows, k)
	middle := k / 2 +1
	for i := 0; i < n; i++ {
		var group int
		fmt.Fscan(input, &group)
		if i < k {
			rows[i] = &crows{
				lf: (k - group) / 2,
				rf: k - group - ((k - group) / 2),
			}
			fmt.Println(i + 1, rows[i].lf + 1, rows[i].lf + group)
			continue
		}

		maxl := -1
		maxrow := -1
		minr := k + 1
		minrow := -1
		for row := 0; row < k; row++ {
			if rows[row].lf >= group {
				if maxl < rows[row].lf - group + 1 {
					maxrow = row
					maxl = rows[row].lf - group + 1
				}
			}

			if rows[row].rf >= group {
				if minr > k - rows[row].rf + 1 {
					minrow = row
					minr = k - rows[row].rf + 1
				}
			}
		}

		if maxrow < 0 && minrow < 0 {
			fmt.Println(-1)
		}  else {
			if maxrow >= 0 && minrow >= 0 {
				if middle - maxl < minr - middle {
					fmt.Println(maxrow + 1, maxl, rows[maxrow].lf)
					rows[maxrow].lf -= group
				} else {
					fmt.Println(maxrow + 1, minr, k - rows[minrow].rf + group)
					rows[minrow].rf -= group
				}
			} else if maxrow >= 0 {
				fmt.Println(maxrow + 1, maxl, rows[maxrow].lf)
					rows[maxrow].lf -= group
			} else {
				fmt.Println(maxrow + 1, minr, k - rows[minrow].rf + group)
					rows[minrow].rf -= group
			}
		}
	}
}

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

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

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

func main() {
	var (
		n, k int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &k)
	middle := k / 2 +1
	cost := make([][]int, k)
	used := make([][]bool, k)
	for i := 0; i < k; i++ {
		cost[i] = make([]int, k)
		used[i] = make([]bool, k)
		for j := 0; j < k; j++ {
			cost[i][j] = abs(i - middle) + (j - middle)
			if i > 0 {
				cost[i][j] += cost[i - 1][j]
			}
		}
	}

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

		mincost := int(1e9)
		minrow := -1
		minfrom := 0
		for row := 0; row < k; row++ {
			for s := 0; s <= k - group; s++ {
				se := s + group - 1
				clean := true
				for cc := s; cc <= se; cc++ {
					if used[row][cc] {
						clean = false
						break
					}
				}
				if !clean {
					continue
				}

				if mincost > cost[row][s + group - 1] - cost[row][s] {
					mincost = cost[row][s + group - 1] - cost[row][s]
					minrow = row
					minfrom = s
				}
			}
		}
		if minrow < 0 {
			fmt.Println(-1)
		} else {
			fmt.Println(minrow + 1, minfrom + 1, minfrom + group)
			for cc := minfrom; cc < minfrom + group; cc++ {
				used[minrow][cc] = true
			}
		}
	}
}

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


package main

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

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

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var n int
		n, _ = GetInt(input)

		// Get numbers
		x := make([]int, n)
		input, _ = reader.ReadString('\n')
		for i:=0; i<n; i++ {
			x[i], input = GetInt(input)
		}

		y := make([]int, n)
		prev := x[0]
		for i:=1; i<n; i++ {
			prev = x[i] | prev
			y[i] = prev ^ x[i]
		}

		for _, val := range y {
			fmt.Printf("%d ", val)
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

const N int = 2e5 + 10

var a, b [N]int

func solve(num int, res int) (ans int, sum int) {
	for j := 0; ; j++ {
		x, y := res>>j, num>>j
		if x == 0 && y == 0 {
			break
		}

		if x&1 == 1 && y&1 == 0 {
			ans += 1 << j
			sum += 1 << j
		} else if y&1 == 1 {
			sum += 1 << j
		}
	}
	return
}

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

	T := 0
	Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		//b[1] = 0
		res := a[1]
		b[1] = 0
		for i := 2; i <= n; i++ {
			b[i], res = solve(a[i], res)
		}

		for i := 1; i < n; i++ {
			Fprint(out, b[i], " ")
		}
		Fprint(out, b[n], " ")
	}
}

package main

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

const N int = 2e5 + 10

var a, b [N]int

func solve(num int, res int) (ans int, sum int) {
	for j := 0; ; j++ {
		x, y := res>>j, num>>j
		if x == 0 && y == 0 {
			break
		}

		if x&1 == 1 && y&1 == 0 {
			ans += 1 << j
			sum += 1 << j
		} else if y&1 == 1 {
			sum += 1 << j
		}
	}
	return
}

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

	T := 0
	Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		b[1] = 0
		res := a[1]
		for i := 2; i <= n; i++ {
			b[i], res = solve(a[i], res)
		}

		for i := 1; i < n; i++ {
			Fprint(out, b[i], " ")
		}
		Fprint(out, b[n], " ")
	}
}

package main

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

const N int = 2e5 + 10

var a, b [N]int

func solve(num int, res int) (ans int, sum int) {
	for j := 0; ; j++ {
		x, y := res>>j, num>>j
		if x == 0 && y == 0 {
			break
		}

		if x&1 == 1 && y&1 == 0 {
			ans += 1 << j
			sum += 1 << j
		} else if y&1 == 1 {
			sum += 1 << j
		}
	}
	return
}

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

	T := 0
	Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}

		b[1] = 0
		res := a[1]
		for i := 2; i <= n; i++ {
			b[i], res = solve(a[i], res)
		}

		for i := 1; i < n; i++ {
			Fprintf(out, "%d ", b[i])
		}
		Fprintf(out, "%d\n", b[n])
	}
}

package main

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

const N int = 2e5 + 10

var a, b [N]int

func solve(num int, res int) (ans int, sum int) {
	for j := 0; ; j++ {
		x, y := res>>j, num>>j
		if x == 0 && y == 0 {
			break
		}

		if x&1 == 1 && y&1 == 0 {
			ans += 1 << j
			sum += 1 << j
		} else if y&1 == 1 {
			sum += 1 << j
		}
	}
	return
}

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

	T := 0
	fmt.Fscanf(in, "%d\n", &T)
	for ; T > 0; T-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")

		b[1] = 0
		res := a[1]
		for i := 2; i <= n; i++ {
			b[i], res = solve(a[i], res)
		}

		for i := 1; i < n; i++ {
			fmt.Fprintf(out, "%d ", b[i])
		}
		fmt.Fprintf(out, "%d\n", b[n])
	}
}

package main

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

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

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var n int
		n, _ = GetInt(input)

		// Get numbers
		input, _ = reader.ReadString('\n')
		var prev int
		prev, input = GetInt(input)
		fmt.Printf("%d ", 0)
		for i:=1; i<n; i++ {
			var num int
			num, input = GetInt(input)
			prev = prev | num
			y := prev ^ num
			fmt.Printf("%d ", y)
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
	var T int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fscan(os.Stdin,&T)
	for T>0 {
		T--
		var n int
		fmt.Fscan(in,&n)
		V := make([]int,n)
		res := make([]int,n)
		for i:=0;i<n;i++ {
			fmt.Fscan(in,&V[i])
		}
		cur := 0
		for i:=0;i<n;i++ {
			for j:=0;j<30;j++ {
				if((cur&(1<<j))!=0&&(V[i]&(1<<j))==0) {
					res[i]^=(1<<j)
				}
			}
			cur=V[i]^res[i]
		}
		for i:=0;i<n;i++ {
			fmt.Fprintf(out,"%d ",res[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

	var t int
	var n int
	arr := make([]int64, 2e5+10)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		Fprintf(out, "%d ", 0)
		it := arr[0]
		for i := 1; i < n; i++ {
			it |= arr[i]
			Fprintf(out, "%d ", it^arr[i])
		}
		Fprintln(out)
	}
}

func main() {
	CF1547D(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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		x := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x[i])
		}

		y := make([]int, n)
		for i := 1; i < n; i++ {
			d := x[i-1] & x[i]
			y[i] = d ^ x[i-1]
			x[i] ^= y[i]
		}

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

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}

		b := make([]int, n)
		for i := 1; i < n; i++ {
			c := a[i-1] ^ b[i-1]
			b[i] = c ^ (c & a[i])
		}

		for i := 0; i < n; i++ {
			_, _ = fmt.Fprintf(out, "%d ", b[i])
		}

		_, _ = fmt.Fprintln(out)
	}

	_ = out.Flush()
}

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

	return n
}

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

	return b
}

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

	return b
}

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 sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		x := sint64s(n)
		res := sol(n, x)
		for _, r := range res {
			printf("%d ", r)
		}
		printf("\n")
	}
}

func sol(n int64, x []int64) []int64 {
	ret := make([]int64, n)
	for i := 1; i < len(ret); i++ {
		prev := x[i-1] ^ ret[i-1]
		if x[i]|prev == x[i] {
			continue // 0
		}
		ret[i] = (x[i] | prev) ^ x[i]
	}
	return ret
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := 1; i < n; i++ {
			if a[i-1] & a[i] == a[i-1] {
				continue
			}
			xor := a[i-1]^a[i]
			need := a[i-1] & xor
			b[i] = need
			a[i] ^=need
		}
		for _, v := range b {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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


package main

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

func main() {
	var n int
	var line string
	fmt.Scanf("%d\n", &n)
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrSlova := strings.Split(strings.TrimSpace(line), " ")
	for i := range arrSlova{
		arrSlova[i]=delBuk(arrSlova[i])
	}
	sort.Strings(arrSlova)
	var m = make(map[string]int)
	for i:=0;i<n;i++{
		m[arrSlova[i]]++
	}
	var result int
	for range m{
		result++
	}
	fmt.Println(result)
}

func delBuk(in string) string{
	var m = make(map[byte]int)
	sl := len(in)
	for i:=0;i<sl;i++{
		m[in[i]]++
	}
	var result []byte
	for k := range m{
		result = append(result, k)
	}
	for j := 1; j < len(result); j++ {
		key := result[j]
		i := j - 1
		for i >= 0 && result[i] > key {
			result[i+1] = result[i]
			i = i - 1
		}
		result[i+1] = key
	}
	return string(result)
}

package main

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

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

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

func main() {
	var manuscripts int

	scanf("%d\n", &manuscripts)
	ciphers := make([]string, manuscripts)

	for i := range ciphers {
		scanf("%s", &ciphers[i])
	}

	used := make(map[string]bool)

	for i := range ciphers {
		letterUsed := make(map[byte]bool)
		for j := range ciphers[i] {
			letterUsed[ciphers[i][j]] = true
		}

		var letters []byte
		for j := range letterUsed {
			letters = append(letters, j)
		}

		sort.Slice(letters, func(i, j int) bool { return letters[i] < letters[j] })
		used[string(letters)] = true
	}

	fmt.Printf("%d", len(used))
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	s := make([]string, n)
	for i := range s {
		scanf("%s", &s[i])
	}
	obj := make(map[string]bool)
	for i := range s {
		letters := make(map[byte]bool)
		for j := range s[i] {
			letters[s[i][j]] = true
		}
		var word []byte
		for j := byte('a'); j <= 'z'; j++ {
			if letters[j] {
				word = append(word, j)
			}
		}
		obj[string(word)] = true
	}
	printf("%d", len(obj))
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	s := make([]string, n)
	for i := range s {
		scanf("%s", &s[i])
	}
	obj, letters := make(map[string]bool), [26]bool{false}
	for i := range s {
		for j := range s[i] {
			letters[s[i][j]-'a'] = true
		}
		var word []byte
		for j := range letters {
			if letters[j] {
				word = append(word, byte(j+'a'))
			}
		}
		obj[string(word)] = true
		for j := range letters {
			letters[j] = false
		}
	}
	printf("%d", len(obj))
}

package main

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

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 scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanChar(a interface{})            { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{})          { fmt.Fscanf(reader, "%s", a) }

func main() {
	defer writer.Flush()

	var n int
	scanlnInt(&n)
	s := make([]string, n)
	for i := range s {
		scanString(&s[i])
	}
	obj := make(map[string]bool)
	for i := range s {
		letters := make(map[byte]bool)
		for j := range s[i] {
			letters[s[i][j]] = true
		}
		var word []byte
		for j := range letters {
			word = append(word, j)
		}
		sort.Slice(word, func(i, j int) bool { return word[i] < word[j] })
		obj[string(word)] = true
	}

	printf("%d", len(obj))
}

package main

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

func main() {
	var (
		n int
		word string
		wordN int
		b []byte
	)

	b = make([]byte, 0, 1024)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()

	n, _ = strconv.Atoi(scanner.Text())

	var m = make(map[string]bool)
	var letters = make([]bool, 26)

	cnt := 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		word = scanner.Text()
		wordN = len(word)

		// clear slice
		for j := range letters {
		   letters[j] = false
		}

		for j := 0; j < wordN; j++ {
			letters[word[j] - 'a'] = true
		}

		// clear slice
		b = b[:0]

		for j := 0; j < 26; j++ {
			if letters[j] {
				b = append(b, byte('a' + j))
			}
		}

		word = string(b)

		if m[word] {
			continue
		}

		cnt++

		m[word] = true
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var (
		n int
		s []byte
	)

	var meet = make([]bool, 24)

	fmt.Scanln(&n)

	cnt := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&s)

		hasNew := false
		for _, ch := range s {
			pos := ch - 'a'

			if !meet[pos] {
				hasNew = true
			}

			meet[pos] = true
		}

		if hasNew {
			cnt++
		}
	}

	fmt.Println(cnt)
}


package main
import "fmt"
import "math"
func main(){
	var a, b int
	fmt.Scanf("%d%d\n", &a, &b)
	var n int
	fmt.Scanf("%d\n", &n)
	m := 1000000.0
	for ; n>0 ;n--{
		var xi, yi, vi int
		fmt.Scanf("%d%d%d\n", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main

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

import "math"

var in *bufio.Scanner
var out *bufio.Writer

var a, b, x, y, v, res float64
var n int

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	a, _ = strconv.ParseFloat(in.Text(), 64)

	in.Scan()
	b, _ = strconv.ParseFloat(in.Text(), 64)

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	res = float64(1000000000000000.0)

	for i := 1; i <= n; i++ {
		in.Scan()
		x, _ = strconv.ParseFloat(in.Text(), 64)
		in.Scan()
		y, _ = strconv.ParseFloat(in.Text(), 64)
		in.Scan()
		v, _ = strconv.ParseFloat(in.Text(), 64)

		dx := x - a
		dy := y - b
		d := dx*dx + dy*dy

		t := math.Sqrt(d) / v
		if t < res {
			res = t
		}
	}

	out.WriteString(strconv.FormatFloat(res, 'f', -1, 64))
	out.WriteByte('\n')
}

package main

import(
    "fmt"
    "math"
)

func main(){
	var a, b float64
	var n int
	var minDist float64 = 99999999.0
	fmt.Scanf("%f %f %f\n", &a, &b)
	fmt.Scanf("%d\n", &n)
	for i:=0; i<n; i++{
		var x, y, v float64
		fmt.Scanf("%f %f %f\n", &x, &y, &v)
		minDist = math.Min(minDist, math.Sqrt((x-a)*(x-a) + (y-b)*(y-b))/v)
	}
	fmt.Println(minDist)
}

// http://codeforces.com/problemset/problem/710/A

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var x, y, n int

	fmt.Scanln(&x, &y)
	fmt.Scanln(&n)

	times := make([]float64, n)

	for i := 0; i < n; i++ {
		var x1, y1, v1 int
		fmt.Scanln(&x1, &y1, &v1)

		times[i] = math.Sqrt(float64((x - x1)*(x - x1) + (y - y1)*(y - y1))) / float64(v1)
	}

	sort.Float64s(times)
	fmt.Println(times[0])
}

package main

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

func getLine(s *bufio.Scanner, n int) []int {
    s.Scan()
    ab := strings.Fields(s.Text())
    a := make([]int,n)
    for i:=0; i<n; i++ {
        a[i], _ = strconv.Atoi(ab[i])
    }
    return a
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    a := getLine(scanner,2)
    n := getLine(scanner,1)
    min := math.MaxFloat64
    for i := 0; i < n[0]; i++ {
        b := getLine(scanner,3)
        x1,y1,x2,y2,v := float64(a[0]), float64(a[1]), float64(b[0]), float64(b[1]), float64(b[2])
        d := math.Sqrt(math.Pow(x1-x2,2.0) + math.Pow(y1-y2,2.0))/v
        if  d < min {
            min = d
        }
    }
    fmt.Printf("%.20f",min)
}

package main
import (
	"fmt"
	"io"
	"os"
	"bufio"
	"strings"
	"strconv"
	"math"
)

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

	// Determine the home coordinates
	line, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line = strings.TrimSpace(line)
	home := strings.Fields(line)
	a, _ := strconv.Atoi(home[0])
	b, _ := strconv.Atoi(home[1])

	// Determine the number of taxis available
	line2, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line2 = strings.TrimSpace(line2)
	n, _ := strconv.Atoi(line2)

	// for each taxi, calculate distance and keep track of min arrival time
	var minimumArrivalTime float64

	for i := 0; i < n; i++ {
		taxiLine, err := reader.ReadString('\n')
		if err != nil && err != io.EOF {
			os.Exit(3)
		}

		taxiLine = strings.TrimSpace(taxiLine)
		taxiInfo := strings.Fields(taxiLine)
		x, _ := strconv.Atoi(taxiInfo[0])
		y, _ := strconv.Atoi(taxiInfo[1])
		v, _ := strconv.Atoi(taxiInfo[2])

		// calculate distance
		if (x == 0 && y == 0) {
			minimumArrivalTime = 0.0
			break
		} else {
			xDiff := math.Pow(float64(x) - float64(a), 2)
			yDiff := math.Pow(float64(y) - float64(b), 2)
			distance := math.Sqrt(xDiff + yDiff)

			// determine arrival time
			arrivalTime := distance / float64(v)

			// update minimum
			if i == 0 || (arrivalTime < minimumArrivalTime) {
				minimumArrivalTime = arrivalTime
			}
		}
	}

	fmt.Printf("%v", minimumArrivalTime)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int
	//fmt.Scanf("%d%d\n", &a, &b)
	fmt.Scan(&a, &b)
	var n int
	//fmt.Scanf("%d\n", &n)
	fmt.Scan(&n)
	m := 1000000.0
	for i:=1; i<=n ;i++{
		var xi, yi, vi int
		//fmt.Scanf("%d%d%d\n", &xi, &yi, &vi)
		fmt.Scan(&xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var  n int
	var a, b, d float64
	d = 1000000000000.0
	fmt.Scan(&a, &b, &n)
	for i := 0; i < n; i++ {
		var x, y, v float64
		fmt.Scan(&x, &y, &v)
		d0 := math.Sqrt(math.Pow(a-x, 2) + math.Pow(b-y, 2)) / v
		if d>d0{
			d=d0
		}
	}
	fmt.Print(d)
}

package main
import "fmt"
import "math"
func main(){
	var a, b float64
	fmt.Scanf("%f %f\n", &a, &b)
	var n int
	fmt.Scanf("%d\n", &n)
	m := 1000000.0
	for i:=0; i<n ; i++{
		var xi, yi, vi float64
		fmt.Scanf("%f %f %f\n", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main

import "fmt"
import "math"

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

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    var n int
    fmt.Scan(&n)
    var minTime float64 = 10000000.0
    for i:=0; i<n; i++ {
        var xi, yi, speed int
        fmt.Scan(&xi, &yi, &speed)
        dx := float64(xi - x)
        dy := float64(yi - y)
        dz := math.Sqrt(dx*dx + dy*dy)
        time := dz / float64(speed)
        if time < minTime {
            minTime = time
        }
    }
    fmt.Printf("%f", minTime)
}

package main

import (
	"fmt"
	"math"
)

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

	mn := -1.0
	for i := 0; i < N; i++ {
		var x, y, v int
		fmt.Scan(&x, &y, &v)
		k := math.Sqrt(float64(pow(a - x, 2) + pow(b - y, 2))) / float64(v)
		if mn == -1.0 || mn > k {
			mn = k
		}
	}
	fmt.Println(mn)

}
//aのb乗をします O(log b)
func pow(a int, b int) int {
	total := 1
	tmp := a
	for b > 0 {
		if b % 2 == 1 {
			total *= tmp
		}
		b /= 2
		tmp *= tmp
	}
	return total
}

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

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := len(arr) / 2

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var x, y, n int
	fmt.Fscanf(reader, "%d %d\n%d\n", &x, &y, &n)
	var r float64
	r = 1000000
	for i := 0; i < n; i++ {
		var xx, yy, vv int
		fmt.Fscanf(reader, "%d %d %d\n", &xx, &yy, &vv)
		l := math.Sqrt( float64((x - xx) * (x - xx) + (y - yy) * (y - yy)))
		l /= float64(vv)
		if l < r {
			r = l
		}
	}
	fmt.Fprintf(writer, "%0.7f\n", r)
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, result float64
	fmt.Scanf("%f %f\n", &a, &b)
	fmt.Scanf("%f\n", &n)
	var min float64
	min = 999999.0
	for ; n > 0; n-- {
		fmt.Scanf("%f %f %f\n", &x, &y, &v)
		s = math.Sqrt(math.Pow(a-x, 2) + math.Pow(b-y, 2))
		result = s / v
		if min > s/v {
			min = result
		}
	}
	fmt.Printf("%.20f\n", min)
}

package main

import(
    "fmt"
    "math"
)

func main(){
	var a, b float64
	var n int
	var minDist float64 = 99999999.0
	fmt.Scanf("%f %f %f", &a, &b)
	fmt.Scanf("%d", &n)
	for i:=0; i<n; i++{
		var x, y, v float64
		fmt.Scanf("%f %f %f", &x, &y, &v)
		minDist = math.Min(minDist, math.Sqrt((x-a)*(x-a) + (y-b)*(y-b))/v)
	}
	fmt.Println(minDist)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	var n int
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for i:=1; i<=n ;i++{
		var xi, yi, vi int
		fmt.Scanf("%d %d %d", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b float64
	fmt.Scanf("%f %f", &a, &b)
	var n float64
	fmt.Scanf("%f", &n)
	m := 1000000.0
	for ; n>0 ;n--{
		var xi, yi, vi float64
		fmt.Scanf("%f %f %f", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int
	fmt.Scanf("%d%d", &a, &b)
	var n int
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for ; n>0 ;n--{
		var xi, yi, vi int
		fmt.Scanf("%d%d%d", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int64
	fmt.Scanf("%d %d", &a, &b)
	var n int64
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for ; n>0 ;n--{
		var xi, yi, vi int64
		fmt.Scanf("%d %d %d", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b float64
	fmt.Scanf("%f %f", &a, &b)
	var n int
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for i:=0; i<n ; i++{
		m = 3000000.0
		var xi, yi, vi float64
		fmt.Scanf("%f %f %f", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b float64
	fmt.Scanf("%f %f", &a, &b)
	var n int64
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for ; n>0 ;n--{
		var xi, yi, vi float64
		fmt.Scanf("%f %f %f", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int
	fmt.Scanf("%d%d", &a, &b)
	var n int
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for i:=1; i<=n ;i++{
		var xi, yi, vi int
		fmt.Scanf("%d%d%d", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b float64
	fmt.Scanf("%f %f", &a, &b)
	var n int
	fmt.Scanf("%d", &n)
	m := 1000000.0
	for i:=0; i<n ; i++{
		var xi, yi, vi float64
		fmt.Scanf("%f %f %f", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main
import "fmt"
import "math"
func main(){
	var a, b int
	fmt.Scanf("%d%d", &a, &b)
	var n int
	fmt.Scanf("%d\n", &n)
	m := 1000000.0
	for i:=1; i<=n ;i++{
		var xi, yi, vi int
		fmt.Scanf("%d%d%d", &xi, &yi, &vi)
		m = math.Min(m, math.Sqrt(float64((xi-a)*(xi-a)+(yi-b)*(yi-b)))/float64(vi))
	}
	fmt.Println(m)
}

package main

import "fmt"
import "math"

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

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    var n int
    fmt.Scan(&n)
    var minTime float64 = 10000000.0
    for i:=0; i>n; i++ {
        var xi, yi, speed int
        fmt.Scan(&xi, &yi, &speed)
        dx := float64(xi - x)
        dy := float64(yi - y)
        dz := math.Sqrt(dx*dx + dy*dy)
        time := dz / float64(speed)
        if time < minTime {
            minTime = time
        }
    }
    fmt.Printf("%f", minTime)
}

package main

import "fmt"
import "math"

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

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    var n int
    fmt.Scan(&n)
    var minTime float64 = 10000000.0
    for i:=0; i>n; i++ {
        var xi, yi, speed int
        fmt.Scan(&xi, &yi, &speed)
        dx := float64(xi - x)
        dy := float64(yi - y)
        dz := math.Sqrt(dx*dx + dy*dy)
        time := dz / float64(speed)
        if time < minTime {
            minTime = time
        }
    }
    fmt.Print(minTime)
}

package main

import "fmt"
import "math"

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

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    var n int
    fmt.Scan(&n)
    var minTime float64 = 10000000.0
    for i:=0; i>n; i++ {
        var xi, yi, speed int
        fmt.Scan(&xi, &yi, &speed)
        dx := float64(xi - x)
        dy := float64(yi - y)
        dz := math.Sqrt(dx*dx + dy*dy)
        fmt.Println(dz, " ", speed)
        time := dz / float64(speed)
        if time < minTime {
            minTime = time
        }
    }
    fmt.Printf("%f", minTime)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, result float64
	fmt.Scanf("%f %f", &a, &b)
	fmt.Scanf("%f", &n)
	fmt.Scanf("%f %f %f", &x, &y, &v)
	var min float64
	min = 99999
	for ; n > 0; n-- {
		fmt.Scanf("%f %f %f", &x, &y, &v)
		s = math.Sqrt(math.Pow(a-x, 2) + math.Pow(b-y, 2))
		result = s / v
		if min > s/v {
			min = result
		}
	}
	fmt.Printf("%.20f\n", min)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, min float64
	fmt.Scanf("%f %f", &a, &b)
	fmt.Scanf("%d", &n)
	fmt.Scanf("%f %f %f", &x, &y, &v)
	s = math.Abs(a-x) + math.Abs(b-y)
	min = s
	for n-1 > 0 {
		s = math.Abs(a-x) + math.Abs(b-y)
		min = s
		if min > s {
			min = s
		}
		n--
	}
	fmt.Printf("%.20f\n", min)
}

//package main
//
//import "fmt"
//
//func main() {
//	var x, h, m int
//	fmt.Scanf("%d", &x)
//	fmt.Scanf("%d %d", &h, &m)
//
//	y := 0
//	for m%10 != 7 && m != 7 && h != 7 && h !=17 {
//		if m < x {
//			m += 60
//			h--
//		}
//		if h<0 {
//			h += 24
//		}
//		m -= x
//		y++
//	}
//	fmt.Println(y)
//}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, min, result float64
	fmt.Scanf("%f %f", &a, &b)
	fmt.Scanf("%f", &n)
	fmt.Scanf("%f %f %f", &x, &y, &v)
	s = math.Abs(a-x) + math.Abs(b-y)
	result = s/v
	min = result
	for n-1 > 0 {
		fmt.Scanf("%f %f %f", &x, &y, &v)
		s = math.Sqrt(math.Pow(math.Abs(a-x),2) + math.Pow(math.Abs(b-y),2))
		result = s/v
		if min > s/v {
			min = result
		}
		n--
	}
	fmt.Printf("%.20f\n", min)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, min, result float64
	fmt.Scanf("%f %f", &a, &b)
	fmt.Scanf("%f", &n)
	fmt.Scanf("%f %f %f", &x, &y, &v)
	s = math.Abs(a-x) + math.Abs(b-y)
	result = s/v
	min = result
	for n-1 > 0 {
		fmt.Scanf("%f %f %f", &x, &y, &v)
		s = math.Sqrt(math.Pow(math.Abs(a-x),2) + math.Pow(math.Abs(b-y),2))
		result = s/v
		min = result
		if min > s/v {
			min = result
		}
		n--
	}
	fmt.Printf("%.20f\n", min)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, result float64
	fmt.Scanf("%d %d", &a, &b)
	fmt.Scanf("%d", &n)
	var min float64
	min = 999999.0
	for ; n > 0; n-- {
		fmt.Scanf("%f %f %f", &x, &y, &v)
		s = math.Sqrt(math.Pow(a-x, 2) + math.Pow(b-y, 2))
		result = s / v
		if min > s/v {
			min = result
		}
	}
	fmt.Printf("%.20f\n", min)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, n, x, y, v, s, result float64
	fmt.Scanf("%d %d", &a, &b)
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d %d %d", &x, &y, &v)
	var min float64
	min = 999999.0
	for ; n > 0; n-- {
		fmt.Scanf("%f %f %f", &x, &y, &v)
		s = math.Sqrt(math.Pow(a-x, 2) + math.Pow(b-y, 2))
		result = s / v
		if min > s/v {
			min = result
		}
	}
	fmt.Printf("%.20f\n", min)
}