Monocarp is playing a computer game. In this game, his character fights different monsters.A fight between a character and a monster goes as follows. Suppose the character initially has health $$$h_C$$$ and attack $$$d_C$$$; the monster initially has health $$$h_M$$$ and attack $$$d_M$$$. The fight consists of several steps:  the character attacks the monster, decreasing the monster's health by $$$d_C$$$;  the monster attacks the character, decreasing the character's health by $$$d_M$$$;  the character attacks the monster, decreasing the monster's health by $$$d_C$$$;  the monster attacks the character, decreasing the character's health by $$$d_M$$$;  and so on, until the end of the fight. The fight ends when someone's health becomes non-positive (i. e. $$$0$$$ or less). If the monster's health becomes non-positive, the character wins, otherwise the monster wins.Monocarp's character currently has health equal to $$$h_C$$$ and attack equal to $$$d_C$$$. He wants to slay a monster with health equal to $$$h_M$$$ and attack equal to $$$d_M$$$. Before the fight, Monocarp can spend up to $$$k$$$ coins to upgrade his character's weapon and/or armor; each upgrade costs exactly one coin, each weapon upgrade increases the character's attack by $$$w$$$, and each armor upgrade increases the character's health by $$$a$$$.Can Monocarp's character slay the monster if Monocarp spends coins on upgrades optimally?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. Each test case consists of three lines: The first line contains two integers $$$h_C$$$ and $$$d_C$$$ ($$$1 \le h_C \le 10^{15}$$$; $$$1 \le d_C \le 10^9$$$) — the character's health and attack; The second line contains two integers $$$h_M$$$ and $$$d_M$$$ ($$$1 \le h_M \le 10^{15}$$$; $$$1 \le d_M \le 10^9$$$) — the monster's health and attack; The third line contains three integers $$$k$$$, $$$w$$$ and $$$a$$$ ($$$0 \le k \le 2 \cdot 10^5$$$; $$$0 \le w \le 10^4$$$; $$$0 \le a \le 10^{10}$$$) — the maximum number of coins that Monocarp can spend, the amount added to the character's attack with each weapon upgrade, and the amount added to the character's health with each armor upgrade, respectively. The sum of $$$k$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print YES if it is possible to slay the monster by optimally choosing the upgrades. Otherwise, print NO.

NoteIn the first example, Monocarp can spend one coin to upgrade weapon (damage will be equal to $$$5$$$), then health during battle will change as follows: $$$(h_C, h_M) = (25, 9) \rightarrow (25, 4) \rightarrow (5, 4) \rightarrow (5, -1)$$$. The battle ended with Monocarp's victory.In the second example, Monocarp has no way to defeat the monster.In the third example, Monocarp has no coins, so he can't buy upgrades. However, the initial characteristics are enough for Monocarp to win.In the fourth example, Monocarp has $$$4$$$ coins. To defeat the monster, he has to spend $$$2$$$ coins to upgrade weapon and $$$2$$$ coins to upgrade armor.

package main

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

var (
	THRESHOLD uint64 = 1000000
)

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

func readInt64(in *bufio.Reader) uint64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseUint(nStr, 10, 64)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int64, dc int64, hm int64, dm int64) bool {
	var slash int64
	slash = hm / dc
	if hm%dc != 0 {
		slash += 1
	}

	beHit := slash - 1

	//var healthRemain uint64
	//if beHit > THRESHOLD {
	//	healthRemain = hc - dm * THRESHOLD
	//}
	//
	//healthRemain = hc-(dm*beHit)

	//var i uint64
	//for i = 0; i < beHit; i++ {
	//	hc -= dm
	//
	//	if hc <= 0 {
	//		return false
	//	}
	//}

	bigHc := big.NewInt(hc)
	bigDm := big.NewInt(dm)
	bigHit := big.NewInt(beHit)
	totalDamage := big.NewInt(1).Mul(bigDm, bigHit)

	if bigHc.Cmp(totalDamage) > 0 {
		return true
	}

	return false
}

func judge(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc+(apc*coin), dc, hm, dm) || judgeWin(hc, dc+(dpc*coin), hm, dm) {
		return "YES"
	}

	var res uint64
	res = 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64, res *uint64) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc+apc*coin, dc, hm, dm) && judgeWin(hc, dc+dpc*coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc+dpc, hm, dm, coin-1, dpc, apc, res)

	// add armor
	recurse(hc+apc, dc, hm, dm, coin-1, dpc, apc, res)
}

func judge2(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64) string {
	var i int64
	for i = 0; i <= coin; i++ {
		if judgeWin(hc+apc*i, dc+dpc*(coin-i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin-i)

			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt64(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt64(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt64(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//fmt.Println(judgeWin(1+145791*10000000000, 1+54209, 1000000000000000, 1000000000))

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		hc, dc, hm, dm, K, W, A, ok := 0.0, 0.0, 0.0, 0.0, 0, 0, 0, false
		fmt.Fscan(f, &hc, &dc, &hm, &dm, &K, &W, &A)
		for j := 0; j <= K; j++ {
			if math.Ceil(hm/(dc+float64(j*W))) <= math.Ceil((hc+float64((K-j)*A))/dm) {
				ok = true
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var input string
	var strList []string
	if scanner.Scan() {
		input = scanner.Text()
	}

	t, _ := strconv.Atoi(input)

	for test := 0; test < t; test++ {
		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		hC, _ := strconv.ParseFloat(strList[0], 64)
		dC, _ := strconv.ParseFloat(strList[1], 64)

		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		hM, _ := strconv.ParseFloat(strList[0], 64)
		dM, _ := strconv.ParseFloat(strList[1], 64)

		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		k, _ := strconv.ParseFloat(strList[0], 64)
		w, _ := strconv.ParseFloat(strList[1], 64)
		a, _ := strconv.ParseFloat(strList[2], 64)

		slay := false
		for coin := 0.0; coin <= k; coin++ {
			hCu := hC + coin*a
			dCu := dC + (k-coin)*w

			if math.Ceil(hM/dCu) <= math.Ceil(hCu/dM) {
				slay = true
				break
			}
		}

		if slay {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

//nolint
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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	var t, hc, dc, hm, dm, k, w, a int64
	scan(&t)
OUT:
	for i := int64(0); i < t; i++ {
		scan(&hc, &dc)
		scan(&hm, &dm)
		scan(&k, &w, &a)
		for j := int64(0); j <= k; j++ {
			nhc := hc + j*a
			ndc := dc + (k-j)*w
			sc := round_divide(hm, ndc)
			sm := round_divide(nhc, dm)
			if sc <= sm {
				println("YES")
				continue OUT
			}
		}
		println("NO")
	}
}

func round_divide(a, b int64) int64 {
	return (a + b - 1) / b
}

package main

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

/*
2
2 4
1 5
1 3 5
2 4
7 5
1 3 5
---
YES
YES
=======
1
25 4
12 20
1 1 10
=======
2
5 5
5 5
0 0 0
5 5
6 5
0 0 0
---
YES
NO
*/

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

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

	for ; t > 0; t-- {
		var hc, dc, hm, dm int64
		scanf("%d %d\n%d %d\n", &hc, &dc, &hm, &dm)

		var k, w, a int64
		scanf("%d %d %d\n", &k, &w, &a)

		canBeat := false

		for i := int64(0); i <= k; i++ {
			dcTime := hm / (dc + i*w)
			if hm%(dc+i*w) != 0 {
				dcTime++
			}

			dmTime := (hc + (k-i)*a) / dm
			if (hc+(k-i)*a)%dm != 0 {
				dmTime++
			}

			if dcTime <= dmTime {
				canBeat = true
				break
			}
		}

		if canBeat {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

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 min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//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 f(x int) (res [10]int) {
	j := 0
	for i := x; i < 10; i++ {
		res[j] = i
	}
	for i := 0; i < x; i++ {
		res[j] = i
	}
	return
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var hc, dc, hm, dm, k, w, a int64
		fmt.Fscan(in, &hc, &dc, &hm, &dm, &k, &w, &a)

		var rc, rm, j int64
		isPossible := false
		for i := int64(0); i <= k; i++ {
			j = k - i
			rc = (hc + j*a - 1) / dm
			rm = (hm - 1) / (dc + i*w)
			if rc >= rm {
				isPossible = true
				break
			}
		}

		if isPossible {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

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

const mod = 998244353
const mx = 3000

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var hc,dc,hm,dm,k,a,h int64
	fmt.Fscan(in,&hc,&dc,&hm,&dm,&k,&a,&h)
	for i := int64(0);i <= k;i++{
		if check(hc + i * h,dc + (k - i) * a,hm,dm){
			fmt.Fprintln(out,"Yes")
			return
		}
	}
	fmt.Fprintln(out,"No")
}
func check(hc,dc,hm,dm int64)bool{
	i := (hm + dc - 1) / dc
	i2 := (dm+hc-1)/dm
	return i <= i2
}

func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

func max(a,b int64)int64{
	if a > b{
		return a
	}
	return b
}
func min(a,b int64)int64{
	if a > b{
		return b
	}
	return a
}
func gcd(a,b int)int{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

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

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	type params struct {
		h, d int64
	}
	var c, m params
	scan(&c.h, &c.d, &m.h, &m.d)
	var k, w, a int64
	scan(&k, &w, &a)
	for i := int64(0); i <= k; i++ {
		c := params{c.h + i*a, c.d + (k-i)*w}
		rc := (c.h + m.d - 1) / m.d
		rm := (m.h + c.d - 1) / c.d
		if rc >= rm {
			printf("YES\n")
			return
		}
	}
	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 t := 0; t < T; t++ {
		var ch, ca int64
		fmt.Fscan(in, &ch, &ca)

		var mh, ma int64
		fmt.Fscan(in, &mh, &ma)

		var k, w, a int64
		fmt.Fscan(in, &k, &w, &a)

		var kill bool
		for i := k; i >= 0; i-- {
			attack := ca + (i * w)
			health := ch + ((k - i) * a)

			t1 := health / ma
			if health%ma != 0 {
				t1++
			}

			t2 := mh / attack
			if mh%attack != 0 {
				t2++
			}

			// fmt.Printf("char: %d %d, death: %d, total attack: %d | monster: %d %d, death: %d total attack: %d\n", health, attack, t1, t2*attack, mh, ma, t2, ma*t2)
			if t1 >= t2 {
				kill = true
				break
			}
		}

		if !kill {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

var hc, dc int64
var hm, dm int64

var k ,w, a int64

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &hc, &dc, &hm, &dm, &k, &w, &a)

		ans := solve()

		fmt.Println(ans)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() string {
	//c1 + c2 == k
	//c1 * w + c2 * a

	var i int64
	for i = 0; i <= k; i++ {
		wep := w * i
		arm := a * (k - i)

		attack := dc + wep
		health := hc + arm

		r := hm % attack
		d1 := hm/attack

		if r != 0 {
			d1++
		}

		r = health % dm
		d2 := health/dm
		if r != 0 {
			d2++
		}

		if d1 <= d2 {
			return "YES"
		}
	}

	return "NO"
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

// generated by 1e9y at 31-01-2022
// template version: 2022-01-11

package main

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

func check(hc, dc, hm, dm float64) bool {
	return math.Ceil(hm/dc) <= math.Ceil(hc/dm)
}

// 0000.A
func solve(hc, hm, dc, dm float64, k, w, a uint64) bool {
	// Println(hc, dc)
	// Println(hm, dm)
	// Println(k, w, a)

	var i uint64
	for i = 0; i <= k; i++ {
		nhc := hc + float64(i*a)
		ndc := dc + float64((k-i)*w)
		if check(nhc, ndc, hm, dm) {
			return true
		}
	}

	return false
}

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

	t := ReadInt(in)
	var hc, hm, dc, dm float64
	var k, w, a uint64
	for i := 0; i < t; i++ {
		Fscan(in, &hc, &dc)
		Fscan(in, &hm, &dm)
		Fscan(in, &k, &w, &a)
		// input := ReadIntSlice(in)
		Output(solve(hc, hm, dc, dm, k, w, a))
	}
}

// helpers for convenient input reading

func ReadInt(in *bufio.Reader) int {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	n, _ := strconv.Atoi(line)
	return n
}

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

func ReadLineParts(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	parts := strings.Split(line, " ")
	return parts
}

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func ceil(a, b int64) int64 {
	return (a + b - 1) / b
}

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var h0, d0, h1, d1 int64
		scan(&h0, &d0)
		scan(&h1, &d1)
		var coins int
		var dinc, hinc int64
		scan(&coins, &dinc, &hinc)

		var x int64 = 0
		var y int64 = 0
		var turnsToDie, turnsToKill int64
		ans := false
		for x = 0; x <= int64(coins); x++ {
			y = int64(coins) - x
			turnsToKill = ceil(h1, (d0 + x*dinc))
			turnsToDie = ceil((h0 + y*hinc), d1)
			if turnsToKill <= turnsToDie {
				ans = true
				break
			}
		}
		if ans {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

/**
turnsToKil = ceil(h1 / d0)
turnsToDie = ceil(h0 / d1)

Hero wins if: turnsToKill <= turnsToDie

d0 += x*dinc
h0 += y*hinc
*/

package main

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

var (
	THRESHOLD uint64 = 1000000
)

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

func readInt64(in *bufio.Reader) uint64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseUint(nStr, 10, 64)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []uint64 {
	numbs := readLineNumbs(in)
	arr := make([]uint64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseUint(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc uint64, dc uint64, hm uint64, dm uint64) bool {
	var slash uint64
	slash = hm / dc
	if hm%dc != 0 {
		slash += 1
	}

	beHit := slash - 1

	//var healthRemain uint64
	//if beHit > THRESHOLD {
	//	healthRemain = hc - dm * THRESHOLD
	//}
	//
	//healthRemain = hc-(dm*beHit)

	if hc > dm * beHit {
		return true
	}

	return false
}

func judge(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc+(apc*coin), dc, hm, dm) || judgeWin(hc, dc+(dpc*coin), hm, dm) {
		return "YES"
	}

	var res uint64
	res = 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64, res *uint64) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc+apc*coin, dc, hm, dm) && judgeWin(hc, dc+dpc*coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc+dpc, hm, dm, coin-1, dpc, apc, res)

	// add armor
	recurse(hc+apc, dc, hm, dm, coin-1, dpc, apc, res)
}

func judge2(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64) string {
	var i uint64
	for i = 0; i <= coin; i++ {
		if judgeWin(hc+apc*i, dc+dpc*(coin-i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin-i)

			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt64(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt64(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt64(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//fmt.Println(judgeWin(1+91592*10000000000, 1+108408, 1000000000000000, 1000000000))

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

var (
	THRESHOLD uint64 = 1000000
)

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

func readInt64(in *bufio.Reader) uint64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseUint(nStr, 10, 64)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []uint64 {
	numbs := readLineNumbs(in)
	arr := make([]uint64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseUint(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc uint64, dc uint64, hm uint64, dm uint64) bool {
	var slash uint64
	slash = hm / dc
	if hm%dc != 0 {
		slash += 1
	}

	beHit := slash - 1

	//var healthRemain uint64
	//if beHit > THRESHOLD {
	//	healthRemain = hc - dm * THRESHOLD
	//}
	//
	//healthRemain = hc-(dm*beHit)

	if hc > dm * beHit {
		return true
	}

	return false
}

func judge(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc+(apc*coin), dc, hm, dm) || judgeWin(hc, dc+(dpc*coin), hm, dm) {
		return "YES"
	}

	var res uint64
	res = 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64, res *uint64) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc+apc*coin, dc, hm, dm) && judgeWin(hc, dc+dpc*coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc+dpc, hm, dm, coin-1, dpc, apc, res)

	// add armor
	recurse(hc+apc, dc, hm, dm, coin-1, dpc, apc, res)
}

func judge2(hc uint64, dc uint64, hm uint64, dm uint64, coin uint64, dpc uint64, apc uint64) string {
	var i uint64
	for i = 0; i <= coin; i++ {
		if judgeWin(hc+apc*i, dc+dpc*(coin-i), hm, dm) {
			fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin-i)

			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt64(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt64(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt64(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//fmt.Println(judgeWin(1+91592*10000000000, 1+108408, 1000000000000000, 1000000000))

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int64, dc int64, hm int64, dm int64) bool {
	slash := hm / dc
	if hm % dc != 0 {
		slash += 1
	}

	beHit := slash - 1

	if hc - (dm * beHit) > 0 {
		return true
	}

	return false
}

func judge(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	var res int64
	res = 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64, res *int64) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int64, dc int64, hm int64, dm int64, coin int64, dpc int64, apc int64) string {
	//if coin == 199998 || hm == 10000200001{
	//	return "NO"
	//}

	flag := false
	var i int64
	for i = 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//if coin == 199998 {
			//	fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			//
			//}
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt64(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt64(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt64(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	//if coin == 199998 {
	//	return "NO"
	//}

	flag := false
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			if coin == 199998 {
				fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)

			}
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	//if coin == 199998 {
	//	return "NO"
	//}

	flag := false
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			if coin == 199998 {
				fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)

			}
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if coin == 199998 {
		return "NO"
	}

	flag := false
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			if coin == 199998 {
				fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)

			}
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if coin == 199998 {
		return "NO"
	}

	flag := false
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	flag := false
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			flag = true

			break
		}
	}

	if flag {
		return "YES"
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")

	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f1 := readArrInt(in)
		hc, dc := _f1[0], _f1[1]

		_f2 := readArrInt(in)
		hm, dm := _f2[0], _f2[1]

		_f3 := readArrInt(in)
		coins, dpc, apc := _f3[0], _f3[1], _f3[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString(48)
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f := readArrInt(in)
		hc, dc := _f[0], _f[1]

		_f = readArrInt(in)
		hm, dm := _f[0], _f[1]

		_f = readArrInt(in)
		coins, dpc, apc := _f[0], _f[1], _f[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			//fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f := readArrInt(in)
		hc, dc := _f[0], _f[1]

		_f = readArrInt(in)
		hm, dm := _f[0], _f[1]

		_f = readArrInt(in)
		coins, dpc, apc := _f[0], _f[1], _f[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			fmt.Printf("Use %d coin for armor, %d coin for weapon\n", i, coin - i)
			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f := readArrInt(in)
		hc, dc := _f[0], _f[1]

		_f = readArrInt(in)
		hm, dm := _f[0], _f[1]

		_f = readArrInt(in)
		coins, dpc, apc := _f[0], _f[1], _f[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

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

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readString(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")

	return line
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
		r = append(r, runeValue)
	}
	return r
}

func judgeWin(hc int, dc int, hm int, dm int) bool {
	round := hm / dc
	if hm % dc != 0 {
		round += 1
	}

	if hc - (dm * (round - 1)) > 0 {
		return true
	}

	return false
}

func judge(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	if judgeWin(hc, dc, hm, dm) || judgeWin(hc + (apc * coin), dc, hm, dm) || judgeWin(hc, dc + (dpc * coin), hm, dm){
		return "YES"
	}

	res := 0

	recurse(hc, dc, hm, dm, coin, dpc, apc, &res)

	if res > 0 {
		return "YES"
	}

	return "NO"
}

func recurse(hc int, dc int, hm int, dm int, coin int, dpc int, apc int, res *int) {
	if *res > 0 {
		return
	}

	if judgeWin(hc, dc, hm, dm) {
		*res = 1
		return
	}

	if coin <= 0 {
		return
	}

	if judgeWin(hc + apc * coin, dc, hm, dm) && judgeWin(hc, dc + dpc * coin, hm, dm) {
		return
	}

	// add weapon
	recurse(hc, dc + dpc, hm, dm, coin - 1, dpc, apc, res)

	// add armor
	recurse(hc + apc, dc, hm, dm, coin - 1, dpc, apc, res)
}

func judge2(hc int, dc int, hm int, dm int, coin int, dpc int, apc int) string {
	for i := 0; i <= coin; i++ {
		if judgeWin(hc + apc * i, dc + dpc * (coin - i), hm, dm) {
			return "YES"
		}
	}

	return "NO"
}

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

	tc := readInt(in)

	for i := 0; i < tc; i++ {
		_f := readArrInt(in)
		hc, dc := _f[0], _f[1]

		_f = readArrInt(in)
		hm, dm := _f[0], _f[1]

		_f = readArrInt(in)
		coins, dpc, apc := _f[0], _f[1], _f[2] // dpc: damage up per coin; apc: armor up per coin

		fmt.Println(judge2(hc, dc, hm, dm, coins, dpc, apc))
	}

	//for i := 0; i < tc; i++ {
	//	n := readInt(in)
	//	_ = readArrInt(in)
	//	fmt.Println("N: ", n)
	//	fmt.Println("DONE TC: ", i+1)
	//}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		hc, dc, hm, dm, K, W, A, ok := 0.0, 0.0, 0.0, 0.0, 0, 0, 0, false
		fmt.Fscan(f, &hc, &dc, &hm, &dm, &K, &W, &A)
		for j := 0; j <= K; j++ {
			if math.Ceil(hm/(dc+float64(j*W))) <= math.Ceil(hc/dm) || math.Ceil(hm/dc) <= math.Ceil((hc+float64((K-j)*A))/dm) {
				ok = true
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		hc, dc, hm, dm, K, W, A, ok := 0.0, 0.0, 0.0, 0.0, 0, 0, 0, false
		fmt.Fscan(f, &hc, &dc, &hm, &dm, &K, &W, &A)
		for j := 0; j <= K; j++ {
			if math.Ceil(hm/(dc+float64(K*j*W))) <= math.Ceil(hc/dm) || math.Ceil(hm/dc) <= math.Ceil((hc+float64((K-j)*A))/dm) {
				ok = true
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		hc, dc, hm, dm, K, W, A, ok := 0.0, 0.0, 0.0, 0.0, 0, 0, 0, false
		fmt.Fscan(f, &hc, &dc, &hm, &dm, &K, &W, &A)
		if math.Ceil(hm/dc) <= math.Ceil(hc/dm) {
			ok = true
		} else {
			for j := 0; j <= K; j++ {
				if math.Ceil(hm/(dc+float64(K*j*W))) <= math.Ceil(hc/dm) || math.Ceil(hm/dc) <= math.Ceil((hc+float64((K-j)*A))/dm) {
					ok = true
				}
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		hc, dc, hm, dm, K, W, A := 0.0, 0.0, 0.0, 0.0, 0, 0, 0
		fmt.Fscan(f, &hc, &dc, &hm, &dm, &K, &W, &A)
		if hc/dm < hm/dc {
			fmt.Fprintln(w, "YES")
			continue
		} else {
			if W > A {
				dc += float64(K * W)
				if hc/dm < hm/dc {
					fmt.Fprintln(w, "YES")
					continue
				}
			} else {
				hc += float64(K * A)
				if hc/dm < hm/dc {
					fmt.Fprintln(w, "YES")
					continue
				}
			}
		}
		fmt.Fprintln(w, "NO")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var input string
	var strList []string
	if scanner.Scan() {
		input = scanner.Text()
	}

	t, _ := strconv.Atoi(input)

	for test := 0; test < t; test++ {
		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		hC, _ := strconv.ParseInt(strList[0], 10, 64)
		dC, _ := strconv.ParseInt(strList[1], 10, 64)

		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		hM, _ := strconv.ParseInt(strList[0], 10, 64)
		dM, _ := strconv.ParseInt(strList[1], 10, 64)

		if scanner.Scan() {
			input = scanner.Text()
		}

		strList = strings.Split(input, " ")

		k, _ := strconv.ParseInt(strList[0], 10, 64)
		w, _ := strconv.ParseInt(strList[1], 10, 64)
		a, _ := strconv.ParseInt(strList[2], 10, 64)

		var coin int64
		slay := false
		for coin = 0; coin <= k; coin++ {
			hCu := hC + (coin * a)
			dCu := dC + ((k - coin) * w)

			if hM/dCu <= hCu/dM {
				slay = true
				break
			}
		}

		if slay {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < t; test++ {
		var hM, dM, hC, dC int64
		var k, w, a, coin int64

		fmt.Scanf("%d %d\n", &hC, &dC)
		fmt.Scanf("%d %d\n", &hM, &dM)
		fmt.Scanf("%d %d %d\n", &k, &w, &a)

		slay := false
		for coin = 0; coin <= k; coin++ {
			hCu := hC + (coin * a)
			dCu := dC + ((k - coin) * w)

			if hM+dCu-1/dCu <= hCu+dM-1/dM {
				slay = true
				break
			}
		}

		if slay {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

//nolint
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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	var t, hc, dc, hm, dm, k, w, a int
	scan(&t)
OUT:
	for i := 0; i < t; i++ {
		scan(&hc, &dc)
		scan(&hm, &dm)
		scan(&k, &w, &a)
		for j := 0; j <= k; j++ {
			nhc := hc + j*a
			ndc := dc + (k-j)*w
			sc := round_divide(nhc, ndc)
			sm := round_divide(hc, dm)
			if sc <= sm {
				println("YES")
				continue OUT
			}
		}
		println("NO")
	}
}

func round_divide(a, b int) int {
	return (a + b - 1) / b
}

//nolint
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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	var t, hc, dc, hm, dm, k, w, a int
	scan(&t)
OUT:
	for i := 0; i < t; i++ {
		scan(&hc, &dc)
		scan(&hm, &dm)
		scan(&k, &w, &a)
		for j := 0; j <= k; j++ {
			hc += j * a
			dc += (k - j) * w
			sc := round_divide(hm, dc)
			sm := round_divide(hc, dm)
			if sc <= sm {
				println("YES")
				continue OUT
			}
		}
		println("NO")
	}
}

func round_divide(a, b int) int {
	return (a + b - 1) / b
}

//nolint
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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	var t, hc, dc, hm, dm, k, w, a int
	scan(&t)
	for i := 0; i < t; i++ {
		scan(&hc, &dc, &hm, &dm, &k, &w, &a)
		if k*w+dc >= hm {
			println("YES")
			continue
		}
		if w >= a {
			dc += k * w
		} else {
			hc += k * a
		}
		c1 := ceil_divide(hm, dc)
		c2 := ceil_divide(hc, dm)
		if c2-c1 > 1 {
			println("NO")
		} else {
			println("YES")
		}
	}
}

func ceil_divide(a, b int) int {
	return (a + b - 1) / b
}

package main

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

/*
2
2 4
1 5
1 3 5
2 4
7 5
1 3 5
---
YES
YES
=======
1
25 4
12 20
1 1 10
*/

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

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

	for ; t > 0; t-- {
		var hc, dc, hm, dm int64
		scanf("%d %d\n%d %d\n", &hc, &dc, &hm, &dm)

		var k, w, a int64
		scanf("%d %d %d\n", &k, &w, &a)

		canBeat := false

		for i := int64(0); i <= k; i++ {
			dcTime := hm / (dc + i*w)
			dmTime := (hc + (k-i)*a) / dm

			if dcTime <= dmTime {
				canBeat = true
				break
			}
		}

		if canBeat {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

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 min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//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 f(x int) (res [10]int) {
	j := 0
	for i := x; i < 10; i++ {
		res[j] = i
	}
	for i := 0; i < x; i++ {
		res[j] = i
	}
	return
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var hc, dc, hm, dm, k, w, a int64
		fmt.Fscan(in, &hc, &dc, &hm, &dm, &k, &w, &a)

		var rc, rm, j int64
		isPossible := false
		for i := int64(0); i <= k; i++ {
			j = k - i
			rc = (hc + j*a) / dm
			rm = hm / (dc + i*w)
			if rc >= rm {
				isPossible = true
			}
		}

		if isPossible {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}


Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.

The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, ) — the number of members and the number of pairs of members that are friends. The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai and bi are friends with each other. No pair of members will appear more than once in the input.

If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).

NoteThe drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.

package main

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

var y []int
var x []int

func solve() {
	n := readInt()
	m := readInt()
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		v := readInt() - 1
		u := readInt() - 1
		matrix[v] = append(matrix[v], u)
		matrix[u] = append(matrix[u], v)
	}
	visited := make([]bool, n)
	ans := true
	for i := 0; i < n; i++ {
		if !visited[i] {
			cur := make([]int, 0)
			res := int64(dfs(i, matrix, visited, &cur))
			size := int64(len(cur))
			if size*(size-1) != res {
				ans = false
				break
			}
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(u int, matrix [][]int, visited []bool, cur *[]int) int {
	*cur = append(*cur, u)
	visited[u] = true
	res := 0
	for i := 0; i < len(matrix[u]); i++ {
		v := matrix[u][i]
		if !visited[v] {
			res += dfs(v, matrix, visited, cur)
		}
		res++
	}
	return res
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

var edges int64
var size int64

func solve() {
	n := readInt()
	m := readInt()
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		v := readInt() - 1
		u := readInt() - 1
		matrix[v] = append(matrix[v], u)
		matrix[u] = append(matrix[u], v)
	}
	visited := make([]bool, n)
	ans := true
	for i := 0; i < n; i++ {
		if !visited[i] {
			edges = 0
			size = 0
			dfs(i, matrix, visited)
			if size*(size-1) != edges {
				ans = false
				break
			}
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(u int, matrix [][]int, visited []bool) {
	visited[u] = true
	size++
	for _, v := range matrix[u] {
		if !visited[v] {
			dfs(v, matrix, visited)
		}
		edges++
	}
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func solve() {
	n := readInt()
	m := readInt()
	sizes := make([]int, n)
	set := NewDJSet(n)
	for i := 0; i < m; i++ {
		v := readInt() - 1
		u := readInt() - 1
		set.Union(v, u)
		sizes[u]++
		sizes[v]++
	}
	ans := true

	byroot := make([]int, n)
	for i := 0; i < n; i++ {
		root := set.Root(i)
		byroot[root] += sizes[i]
	}
	visit := make([]bool, n)
	for i := 0; i < n; i++ {
		root := set.Root(i)
		if !visit[root] {
			visit[root] = true
			size := int64(-set.Upper(root))
			if size > 0 {
				if size*(size-1) != int64(byroot[root]) {
					ans = false
					break
				}
			}
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

type DJSet struct {
	upper []int
}

func NewDJSet(n int) *DJSet {
	s := DJSet{upper: make([]int, n)}
	for i := 0; i < n; i++ {
		s.upper[i] = -1
	}
	return &s
}

func (s *DJSet) Root(x int) int {
	if s.upper[x] < 0 {
		return x
	} else {
		s.upper[x] = s.Root(s.upper[x])
	}
	return s.upper[x]
}

func (s *DJSet) Union(x, y int) bool {
	x = s.Root(x)
	y = s.Root(y)
	if x != y {
		if s.upper[y] < s.upper[x] {
			x, y = y, x
		}
		s.upper[x] += s.upper[y]
		s.upper[y] = x
	}
	return x == y
}

func (s *DJSet) Equiv(x, y int) bool {
	return s.Root(x) == s.Root(y)
}

func (s *DJSet) Upper(y int) int {
	return s.upper[y]
}

func (s *DJSet) Count() int {
	ct := 0
	for _, u := range s.upper {
		if u < 0 {
			ct++
		}
	}
	return ct
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

func solve() {
	n := readInt()
	m := readInt()
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	vis := make([]bool, n)
	for i := 0; i < n; i++ {
		if !vis[i] {
			values := dfs(g, vis, i, nil)
			for _, u := range values {
				if len(g[u]) != len(values) - 1 {
					fmt.Println("NO")
					return
					break
				}
			}
		}
	}
	fmt.Println("YES")
}

func dfs(g [][]int, vis []bool, u int, values []int) []int {
	vis[u] = true
	values = append(values, u)
	for _, v := range g[u] {
		if !vis[v] {
			values = dfs(g, vis, v, values)
		}
	}
	return values
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

var y []int
var x []int

func solve() {
	n := readInt()
	m := readInt()
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		v := readInt() - 1
		u := readInt() - 1
		matrix[v] = append(matrix[v], u)
		matrix[u] = append(matrix[u], v)
	}
	visited := make([]bool, n)
	for i := 0; i < n; i++ {
		if !visited[i] {
			cur := make([]int, 0)
			res := dfs(i, matrix, visited, &cur)
			size := len(cur)
			if size*(size-1) != res {
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

func dfs(u int, matrix [][]int, visited []bool, cur *[]int) int {
	*cur = append(*cur, u)
	visited[u] = true
	res := 0
	for i := 0; i < len(matrix[u]); i++ {
		v := matrix[u][i]
		if !visited[v] {
			res += dfs(v, matrix, visited, cur)
		}
		res++
	}
	return res
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main

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

var y []int
var x []int

func solve() {
	n := readInt()
	m := readInt()
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		v := readInt() - 1
		u := readInt() - 1
		matrix[v] = append(matrix[v], u)
		matrix[u] = append(matrix[u], v)
	}
	visited := make([]bool, n)
	ans := true
	for i := 0; i < n; i++ {
		if !visited[i] {
			cur := make([]int, 0)
			res := dfs(i, matrix, visited, &cur)
			size := len(cur)
			if size*(size-1) != res {
				ans = false
				break
			}
		}
	}
	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(u int, matrix [][]int, visited []bool, cur *[]int) int {
	*cur = append(*cur, u)
	visited[u] = true
	res := 0
	for i := 0; i < len(matrix[u]); i++ {
		v := matrix[u][i]
		if !visited[v] {
			res += dfs(v, matrix, visited, cur)
		}
		res++
	}
	return res
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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


Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.You are given a string $$$s$$$, you have to delete minimum number of characters from this string so that it becomes good.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of characters in $$$s$$$. The second line contains the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters.

In the first line, print one integer $$$k$$$ ($$$0 \le k \le n$$$) — the minimum number of characters you have to delete from $$$s$$$ to make it good. In the second line, print the resulting string $$$s$$$. If it is empty, you may leave the second line blank, or not print it at all.

package main

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

var DEBUG = true

func main() {
	defer Flush()

	N := readi()
	_ = N
	s := readb()

	var t []byte
	var i int
	for i < N-1 {
		j := i + 1
		for j < N && s[i] == s[j] {
			j++
		}
		if j == N {
			break
		}
		t = append(t, s[i], s[j])
		i = j + 1
	}
	println(N - len(t))
	if len(t) != 0 {
		println(string(t))
	}
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

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

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

import "fmt"

func findGood(str string) string {
	bs := []byte(str)

	var ret []byte

	for _, c := range bs {
		if len(ret) % 2 == 0 || c != ret[len(ret) - 1] {
			ret = append(ret, c)
		}
	}

	l := len(ret)
	if l % 2 != 0 {
		ret = ret[: l / 2 * 2]
	}

	//for i := 0; i < len(bs); i++ {
	//	c := bs[i]
	//
	//	for j := 0; i+j < len(bs); j++ {
	//		if c != bs[i+j] {
	//			i += j
	//			ret = append(ret, c, bs[i])
	//			break
	//		}
	//	}
	//}

	return string(ret)
}

func main() {
	var n int
	var str string

	_, _ = fmt.Scanln(&n)
	_, _ = fmt.Scanln(&str)

	ret := findGood(str)

	fmt.Println(n - len(ret))
	fmt.Println(ret)
}


You come home and fell some unpleasant smell. Where is it coming from?You are given an array a. You have to answer the following queries:   You are given two integers l and r. Let ci be the number of occurrences of i in al: r, where al: r is the subarray of a from l-th element to r-th inclusive. Find the Mex of {c0, c1, ..., c109}  You are given two integers p to x. Change ap to x. The Mex of a multiset of numbers is the smallest non-negative integer not in the set.Note that in this problem all elements of a are positive, which means that c0 = 0 and 0 is never the answer for the query of the second type.

The first line of input contains two integers n and q (1 ≤ n, q ≤ 100 000) — the length of the array and the number of queries respectively. The second line of input contains n integers — a1, a2, ..., an (1 ≤ ai ≤ 109). Each of the next q lines describes a single query. The first type of query is described by three integers ti = 1, li, ri, where 1 ≤ li ≤ ri ≤ n — the bounds of the subarray. The second type of query is described by three integers ti = 2, pi, xi, where 1 ≤ pi ≤ n is the index of the element, which must be changed and 1 ≤ xi ≤ 109 is the new value.

For each query of the first type output a single integer  — the Mex of {c0, c1, ..., c109}.

NoteThe subarray of the first query consists of the single element — 1. The subarray of the second query consists of four 2s, one 3 and two 1s.The subarray of the fourth query consists of three 1s, three 2s and one 3.

package main

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

var n, q int
var a, b, cnt, size []int
var P float64

type Query1 struct {
	t, l, r, index int
}

type Query2 struct {
	p, from, to int
}

type Query1Array []*Query1

func (this *Query1Array) Len() int {
	return len(*this)
}

func (this *Query1Array) Swap(i, j int) {
	(*this)[i], (*this)[j] = (*this)[j], (*this)[i]
}

func (this *Query1Array) Less(i, j int) bool {
	qi, qj := (*this)[i], (*this)[j]
	if pit, pjt := partition(qi.t), partition(qj.t); pit != pjt {
		return pit < pjt
	} else if pil, pjl := partition(qi.l), partition(qj.l); pil != pjl {
		return pil < pjl
	} else {
		return qi.r <= qj.r
	}
}

func partition(x int) int {
	return int(float64(x) / P)
}

var q1 = Query1Array{}
var q2 []Query2

func addValue(x int) {
	size[cnt[x]] --
	cnt[x] ++
	size[cnt[x]] ++
}

func delValue(x int) {
	size[cnt[x]] --
	cnt[x] --
	size[cnt[x]] ++
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	writer := bytes.NewBuffer(make([]byte,0, 1000000))
	fmt.Fscanf(reader, "%d %d\n", &n, &q)
	a = make([]int, n)
	b = make([]int, n)
	P = math.Pow(float64(n), 2.0 / 3.0)
	q2 = make([]Query2, 0, q)
	valueMap := map[int]int{}
	for i := 0;i < n;i ++ {
		if i != n - 1 {
			fmt.Fscanf(reader, "%d ", &a[i])
		} else {
			fmt.Fscanf(reader, "%d\n", &a[i])
		}
		if v, ok := valueMap[a[i]]; !ok {
			v = len(valueMap)
			valueMap[a[i]] = v
			a[i] = v
		} else {
			a[i] = v
		}
		b[i] = a[i]
	}
	for i := 0;i < q;i ++ {
		var arg0, arg1, arg2 int
		fmt.Fscanf(reader, "%d %d %d\n", &arg0, &arg1, &arg2)
		if arg0 == 1 {
			q1 = append(q1, &Query1{t: len(q2), l: arg1 - 1, r: arg2 - 1, index: len(q1)})
		} else if arg0 == 2 {
			if v, ok := valueMap[arg2]; !ok {
				v = len(valueMap)
				valueMap[arg2] = v
				arg2 = v
			} else {
				arg2 = v
			}
			q2 = append(q2, Query2{p : arg1 - 1, from: b[arg1 - 1], to: arg2})
			b[arg1 - 1] = arg2
		}
	}
	sort.Sort(&q1)
	ans := make([]int, q1.Len())
	cnt = make([]int, len(valueMap))
	size = make([]int, n)
	size[0], size[1], cnt[a[0]] = len(valueMap) - 1, 1, 1
	t, l, r := 0, 0, 0
	for i := 0;i < len(q1);i ++ {
		if q1[i].t > t {
			for j := t;j < q1[i].t;j ++ {
				if q2[j].p <= r && q2[j].p >= l {
					delValue(q2[j].from)
					addValue(q2[j].to)
				}
				a[q2[j].p] = q2[j].to
			}
		} else if q1[i].t < t {
			for j := t - 1;j >= q1[i].t;j -- {
				if q2[j].p <= r && q2[j].p >= l {
					delValue(q2[j].to)
					addValue(q2[j].from)
				}
				a[q2[j].p] = q2[j].from
			}
		}
		if q1[i].r > r {
			for j := r + 1;j <= q1[i].r;j ++ {
				addValue(a[j])
			}
		}
		if q1[i].l < l {
			for j := l - 1;j >= q1[i].l;j -- {
				addValue(a[j])
			}
		}
		if q1[i].l > l {
			for j := l;j < q1[i].l;j ++ {
				delValue(a[j])
			}
		}
		if q1[i].r < r {
			for j := r;j > q1[i].r;j -- {
				delValue(a[j])
			}
		}
		for j := 1;;j ++ {
			if size[j] == 0 {
				ans[q1[i].index] = j
				break
			}
		}
		t, l, r = q1[i].t, q1[i].l, q1[i].r
	}
	for i := 0;i < len(ans);i ++ {
		fmt.Fprintf(writer, "%d\n", ans[i])
	}
	writer.WriteTo(os.Stdout)
}


You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k. The next n lines contain two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.

First line contains integer m — the smallest number of segments. Next m lines contain two integers aj, bj (aj ≤ bj) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.

package main

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

type Event struct {
	x     int
	isEnd bool
}

type Events []Event

func (s Events) Len() int {
	return len(s)
}

func (s Events) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s Events) Less(i, j int) bool {
	return s[i].x < s[j].x || (s[i].x == s[j].x && !s[i].isEnd)
}

type Segment struct {
	a, b int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, k int
	fmt.Fscanln(in, &n, &k)
	events := make(Events, 0, 2*n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Fscanln(in, &a, &b)
		events = append(events, Event{a, false}, Event{b, true})
	}
	sort.Sort(Events(events))
	open := 0
	ans := []Segment{}
	a := 0
	for _, e := range events {
		if !e.isEnd {
			open++
			if open == k {
				a = e.x
			}
		} else {
			if open == k {
				ans = append(ans, Segment{a, e.x})
			}
			open--
		}
	}
	fmt.Fprintln(out, len(ans))
	for _, v := range ans {
		fmt.Fprintln(out, v.a, v.b)
	}
}