package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		a := make([]int32, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([][2]int, m)
		for i := range b {
			fmt.Fscan(r, &b[i][0], &b[i][1])
		}
		w1 := do(n, m, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, a []int32, b [][2]int) int32 {
	topo := func() ([]int, map[int][]int) {
		g := make(map[int][]int)
		in := make([]int, n)
		for _, e := range b {
			e[0]--
			e[1]--
			g[e[0]] = append(g[e[0]], e[1])
			in[e[1]]++
		}
		q := []int{}
		for x := range in {
			if in[x] == 0 {
				q = append(q, x)
			}
		}
		for i := 0; i < len(q); i++ {
			x := q[i]
			for _, y := range g[x] {
				in[y]--
				if in[y] == 0 {
					q = append(q, y)
				}
			}
		}
		return q, g
	}
	var mod int32 = 998244353
	upd := func(x int, v int32) {
		a[x] = ((a[x])%mod + v) % mod
	}
	// inc := func(x int) {
	// 	upd(x, 1)
	// }
	// dec := func(x int) {
	// 	upd(x, -1)
	// }
	q, g := topo()
	var k int32 = 0
	for k < int32(n) {
		end := true
		for i := len(q) - 1; i >= 0; i-- {
			x := q[i]
			if a[x] <= 0 {
				continue
			}
			end = false
			a[x]--
			// dec(x)
			for _, y := range g[x] {
				a[y]++
				// inc(y)
			}
		}
		if end {
			return k
		}
		k++
	}
	for _, x := range q {
		for _, y := range g[x] {
			upd(y, a[x])
		}
	}
	return (k + a[q[len(q)-1]]) % mod
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		A := readNNums(reader, n)
		edges := make([][]int, m)
		for i := 0; i < m; i++ {
			edges[i] = readNNums(reader, 2)
		}
		res := solve(n, edges, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

const M = 998244353

func solve(n int, edges [][]int, a []int) int {
	g := make([][]int, n+1)
	z := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		g[i] = make([]int, 0, 2)
		z[i] = make([]int, 0, 2)
	}

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

	for _, edge := range edges {
		u, v := edge[0], edge[1]
		g[u] = append(g[u], v)
		z[v] = append(z[v], u)
		D[u]++
	}
	A := make([]int, n+1)
	copy(A[1:], a)
	B := make([]int, n+1)
	copy(B, A)

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

	for i := 1; i <= n; i++ {
		var flow bool
		for j := 1; j <= n; j++ {
			if B[j] > 0 {
				flow = true
				break
			}
		}
		if !flow {
			return i - 1
		}

		for u := 1; u <= n; u++ {
			if B[u] > 0 {
				// C[j] 可能被其他的j增加，所以不能直接等于
				C[u] += B[u] - 1
				for _, v := range g[u] {
					C[v]++
				}
			}
		}

		for u := 1; u <= n; u++ {
			if C[u] >= M {
				// 如果C[u] = M, B[u] = 0, 将得到错误的结果
				B[u] = C[u]%M + M
			} else {
				B[u] = C[u] % M
			}
			C[u] = 0
		}
	}

	// not ending before n iterations
	que := make([]int, n+1)
	var end int
	for u := 1; u <= n; u++ {
		if D[u] == 0 {
			end++
			que[end] = u
		}
	}

	s := make([]int, n+1)
	s[que[end]] = 1

	for i := 1; i <= end; i++ {
		s[que[i]] %= M
		for _, v := range z[que[i]] {
			D[v]--
			s[v] += s[que[i]]
			if D[v] == 0 {
				end++
				que[end] = v
			}
		}
	}

	var ans int64 = int64(n)

	for i := 1; i <= n; i++ {
		ans = (ans + int64(B[i])*int64(s[i])%M) % M
	}

	return int(ans)
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		a := make([]int32, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([][2]int, m)
		for i := range b {
			fmt.Fscan(r, &b[i][0], &b[i][1])
		}
		w1 := do(n, m, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, a []int32, b [][2]int) int32 {
	topo := func() ([]int, map[int][]int) {
		g := make(map[int][]int)
		in := make([]int, n)
		for _, e := range b {
			e[0]--
			e[1]--
			g[e[0]] = append(g[e[0]], e[1])
			in[e[1]]++
		}
		q := []int{}
		for x := range in {
			if in[x] == 0 {
				q = append(q, x)
			}
		}
		for i := 0; i < len(q); i++ {
			x := q[i]
			for _, y := range g[x] {
				in[y]--
				if in[y] == 0 {
					q = append(q, y)
				}
			}
		}
		return q, g
	}
	var mod int32 = 998244353
	upd := func(x int, v int32) {
		a[x] = ((a[x]+v)%mod + mod) % mod
	}
	inc := func(x int) {
		upd(x, 1)
	}
	dec := func(x int) {
		upd(x, -1)
	}
	q, g := topo()
	var k int32 = 0
	for k < int32(n) {
		end := true
		for i := len(q) - 1; i >= 0; i-- {
			x := q[i]
			if a[x] <= 0 {
				continue
			}
			end = false
			dec(x)
			for _, y := range g[x] {
				inc(y)
			}
		}
		if end {
			return k % mod
		}
		k++
	}
	for _, x := range q {
		for _, y := range g[x] {
			upd(y, a[x])
		}
	}
	return (k + a[q[len(q)-1]]) % mod
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		b := make([][2]int, m)
		for i := range b {
			fmt.Fscan(r, &b[i][0], &b[i][1])
		}
		w1 := do(n, m, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, a []int, b [][2]int) int {
	topo := func() ([]int, map[int][]int) {
		g := make(map[int][]int)
		in := make([]int, n)
		for _, e := range b {
			e[0]--
			e[1]--
			g[e[0]] = append(g[e[0]], e[1])
			in[e[1]]++
		}
		q := []int{}
		for x := range in {
			if in[x] == 0 {
				q = append(q, x)
			}
		}
		for i := 0; i < len(q); i++ {
			x := q[i]
			for _, y := range g[x] {
				in[y]--
				if in[y] == 0 {
					q = append(q, y)
				}
			}
		}
		return q, g
	}
	mod := 998244353
	upd := func(x, v int) {
		a[x] = (a[x] + mod + v) % mod
	}
	inc := func(x int) {
		upd(x, 1)
	}
	dec := func(x int) {
		upd(x, -1)
	}
	q, g := topo()
	k := 0
	for k < n {
		end := true
		for i := len(q) - 1; i >= 0; i-- {
			x := q[i]
			if a[x] <= 0 {
				continue
			}
			end = false
			dec(x)
			for _, y := range g[x] {
				inc(y)
			}
		}
		if end {
			return k % mod
		}
		k++
	}
	for _, x := range q {
		for _, y := range g[x] {
			upd(y, a[x])
		}
	}
	return (k + a[q[len(q)-1]]) % mod
}


package main

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

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

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

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

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

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

		for i := 0; i < q; i++ {
			var v int
			fmt.Fscan(in, &v)
			x := sort.Search(n, func(i int) bool { return int(g[i]) >= v })
			x++
			if x > n {
				x = -1
			}
			fmt.Fprintln(out, x)
		}
	}
}

package main

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

func main() {
	r := readerStdin()
	t := readInt(r)

	for t != 0 {
		t--

		dataCandies, candies := readSliceInt(r), readSliceInt(r)

		n, q := dataCandies[0], dataCandies[1]

		sort.Ints(candies)

		prefixSum := make([]int, len(candies))
		prefixSum[0] = candies[n-1]
		for i := 1; i < n; i++ {
			prefixSum[i] = prefixSum[i-1] + candies[n-i-1]
		}

		for q != 0 {
			q--

			sugar := readInt(r)

			quantity := sort.SearchInts(prefixSum, sugar)
			if quantity == n {
				fmt.Println(-1)
			} else {
				fmt.Println(quantity + 1)
			}
		}
	}
}

func readerStdin() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

func readString(r *bufio.Reader) (s string) {
	s, _ = r.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return
}

func readInt(r *bufio.Reader) (i int) {
	str := readString(r)
	i, _ = strconv.Atoi(str)
	return
}

func readSliceInt(r *bufio.Reader) []int {
	str := readString(r)
	slice := strings.Split(str, " ")

	var result = make([]int, len(slice))
	for i, v := range slice {
		x, _ := strconv.Atoi(v)
		result[i] = x
	}

	return result
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T,N,M,A,max int

	//num := make(map[int]int)

	fmt.Fscan(in, &T)
	for i := 0;i < T;i++{
		fmt.Fscan(in, &N,&M)
		list := make([]int,N)
		for j := 0;j < N;j++{
			fmt.Fscan(in, &A)
			list[j] = A
			max += A
		}
		sort.Sort(sort.Reverse(sort.IntSlice(list)))

		for j := 1;j < N;j++{
			list[j] += list[j-1]
		}
		for j := 0;j < M;j++{
			fmt.Fscan(in, &A)
			if max < A{
				fmt.Println(-1)
			}else{
				fmt.Println(sort.SearchInts(list,A)+1)
			}
		}
		max = 0
	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for k := 0; k < t; k++ {
		n, q := 0, 0
		fmt.Fscan(in, &n, &q)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		presum := make([]int, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + a[i-1]
		}
		for i := 0; i < q; i++ {
			qq := 0
			fmt.Fscan(in, &qq)
			x := sort.Search(n+1, func(j int) bool {
				return presum[j] >= qq
			})
			if x == n+1 {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, x)
			}
		}
	}
}

// Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT.
//go:generate bundle -o output.go -prefix  .

package main

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

// Signed is a constraint that permits any signed integer type.
// If future releases of Go add new predeclared signed integer types,
// this constraint will be modified to include them.
type constraints_Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

// Unsigned is a constraint that permits any unsigned integer type.
// If future releases of Go add new predeclared unsigned integer types,
// this constraint will be modified to include them.
type constraints_Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

// Integer is a constraint that permits any integer type.
// If future releases of Go add new predeclared integer types,
// this constraint will be modified to include them.
type constraints_Integer interface {
	constraints_Signed | constraints_Unsigned
}

// Float is a constraint that permits any floating-point type.
// If future releases of Go add new predeclared floating-point types,
// this constraint will be modified to include them.
type constraints_Float interface {
	~float32 | ~float64
}

// Complex is a constraint that permits any complex numeric type.
// If future releases of Go add new predeclared complex numeric types,
// this constraint will be modified to include them.
type constraints_Complex interface {
	~complex64 | ~complex128
}

// Ordered is a constraint that permits any ordered type: any type
// that supports the operators < <= >= >.
// If future releases of Go add new ordered types,
// this constraint will be modified to include them.
type constraints_Ordered interface {
	constraints_Integer | constraints_Float | ~string
}

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

	n := readInt(in)
	for i := 0; i < n; i++ {
		solution(in, out)
	}
}

func solution(in *bufio.Reader, out *bufio.Writer) {
	v := readArrInt(in)
	q := v[1]

	arr := readArrInt(in)
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	tm := treemap_New[int, int]()
	sum := 0
	for i, v := range arr {
		sum += v
		tm.Set(sum, i)
	}

	for i := 0; i < q; i++ {
		// find first higher then
		val := readInt(in)
		if val > sum {
			out.WriteString("-1\n")
			continue
		}
		ans := tm.LowerBound(val).Value() + 1
		out.WriteString(strconv.Itoa(ans) + "\n")
	}
}

func Max(sum int, sum2 int) int {
	if sum > sum2 {
		return sum
	}
	return sum2

}

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

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 readLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

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
}

// TreeMap is the generic red-black tree based map
type treemap_TreeMap[Key, Value any] struct {
	endNode    *treemap_node[Key, Value]
	beginNode  *treemap_node[Key, Value]
	count      int
	keyCompare func(a Key, b Key) bool
}

type treemap_node[Key, Value any] struct {
	right   *treemap_node[Key, Value]
	left    *treemap_node[Key, Value]
	parent  *treemap_node[Key, Value]
	isBlack bool
	key     Key
	value   Value
}

// New creates and returns new TreeMap.
func treemap_New[Key constraints_Ordered, Value any]() *treemap_TreeMap[Key, Value] {
	endNode := &treemap_node[Key, Value]{isBlack: true}
	return &treemap_TreeMap[Key, Value]{beginNode: endNode, endNode: endNode, keyCompare: treemap_defaultKeyCompare[Key]}
}

// NewWithKeyCompare creates and returns new TreeMap with the specified key compare function.
// Parameter keyCompare is a function returning a < b.
func treemap_NewWithKeyCompare[Key, Value any](
	keyCompare func(a, b Key) bool,
) *treemap_TreeMap[Key, Value] {
	endNode := &treemap_node[Key, Value]{isBlack: true}
	return &treemap_TreeMap[Key, Value]{beginNode: endNode, endNode: endNode, keyCompare: keyCompare}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *treemap_TreeMap[Key, Value]) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) Set(key Key, value Value) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.keyCompare(key, current.key):
			current = current.left
			less = true
		case t.keyCompare(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &treemap_node[Key, Value]{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) Del(key Key) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	treemap_removeNode(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *treemap_TreeMap[Key, Value]) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) Get(id Key) (Value, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *treemap_TreeMap[Key, Value]) Contains(id Key) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) Range(from, to Key) (treemap_ForwardIterator[Key, Value], treemap_ForwardIterator[Key, Value]) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) LowerBound(key Key) treemap_ForwardIterator[Key, Value] {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return treemap_ForwardIterator[Key, Value]{tree: t, node: t.endNode}
	}
	for {
		if t.keyCompare(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return treemap_ForwardIterator[Key, Value]{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return treemap_ForwardIterator[Key, Value]{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *treemap_TreeMap[Key, Value]) UpperBound(key Key) treemap_ForwardIterator[Key, Value] {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return treemap_ForwardIterator[Key, Value]{tree: t, node: t.endNode}
	}
	for {
		if !t.keyCompare(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return treemap_ForwardIterator[Key, Value]{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return treemap_ForwardIterator[Key, Value]{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *treemap_TreeMap[Key, Value]) Iterator() treemap_ForwardIterator[Key, Value] {
	return treemap_ForwardIterator[Key, Value]{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *treemap_TreeMap[Key, Value]) Reverse() treemap_ReverseIterator[Key, Value] {
	node := t.endNode.left
	if node != nil {
		node = treemap_mostRight(node)
	}
	return treemap_ReverseIterator[Key, Value]{tree: t, node: node}
}

func treemap_defaultKeyCompare[Key constraints_Ordered](
	a, b Key,
) bool {
	return a < b
}

func (t *treemap_TreeMap[Key, Value]) findNode(id Key) *treemap_node[Key, Value] {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.keyCompare(id, current.key):
			current = current.left
		case t.keyCompare(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func treemap_mostLeft[Key, Value any](
	x *treemap_node[Key, Value],
) *treemap_node[Key, Value] {
	for x.left != nil {
		x = x.left
	}
	return x
}

func treemap_mostRight[Key, Value any](
	x *treemap_node[Key, Value],
) *treemap_node[Key, Value] {
	for x.right != nil {
		x = x.right
	}
	return x
}

func treemap_successor[Key, Value any](
	x *treemap_node[Key, Value],
) *treemap_node[Key, Value] {
	if x.right != nil {
		return treemap_mostLeft(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func treemap_predecessor[Key, Value any](
	x *treemap_node[Key, Value],
) *treemap_node[Key, Value] {
	if x.left != nil {
		return treemap_mostRight(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func treemap_rotateLeft[Key, Value any](
	x *treemap_node[Key, Value],
) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func treemap_rotateRight[Key, Value any](
	x *treemap_node[Key, Value],
) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *treemap_TreeMap[Key, Value]) insertFixup(x *treemap_node[Key, Value]) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					treemap_rotateLeft(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				treemap_rotateRight(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					treemap_rotateRight(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				treemap_rotateLeft(x)
				break
			}
		}
	}
}

//nolint:gocyclo
//noinspection GoNilness
func treemap_removeNode[Key, Value any](
	root, z *treemap_node[Key, Value],
) {
	var y *treemap_node[Key, Value]
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = treemap_successor(z)
	}
	var x *treemap_node[Key, Value]
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *treemap_node[Key, Value]
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						treemap_rotateLeft(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							treemap_rotateRight(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						treemap_rotateLeft(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						treemap_rotateRight(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							treemap_rotateLeft(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						treemap_rotateRight(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type treemap_ForwardIterator[Key, Value any] struct {
	tree *treemap_TreeMap[Key, Value]
	node *treemap_node[Key, Value]
}

// Valid reports if the iterator position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i treemap_ForwardIterator[Key, Value]) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if it goes out of bounds.
func (i *treemap_ForwardIterator[Key, Value]) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = treemap_successor(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if it goes out of bounds.
func (i *treemap_ForwardIterator[Key, Value]) Prev() {
	i.node = treemap_predecessor(i.node)
	if i.node == nil {
		panic("out of bound iteration")
	}
}

// Key returns a key at the iterator position
func (i treemap_ForwardIterator[Key, Value]) Key() Key { return i.node.key }

// Value returns a value at the iterator position
func (i treemap_ForwardIterator[Key, Value]) Value() Value { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type treemap_ReverseIterator[Key, Value any] struct {
	tree *treemap_TreeMap[Key, Value]
	node *treemap_node[Key, Value]
}

// Valid reports if the iterator position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i treemap_ReverseIterator[Key, Value]) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if it goes out of bounds.
func (i *treemap_ReverseIterator[Key, Value]) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = treemap_predecessor(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if it goes out of bounds.
func (i *treemap_ReverseIterator[Key, Value]) Prev() {
	if i.node != nil {
		i.node = treemap_successor(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at the iterator position
func (i treemap_ReverseIterator[Key, Value]) Key() Key { return i.node.key }

// Value returns a value at the iterator position
func (i treemap_ReverseIterator[Key, Value]) Value() Value { return i.node.value }

package main

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

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

	var T int
	for fmt.Fscan(in, &T); T > 0; T-- {
		var n, q int
		fmt.Fscan(in, &n, &q)
		a := make([]int, n)
		for i := 0;i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		for i := 1;i < n; i++ {
			a[i] += a[i - 1]
		}

		for i := 0;i < q; i++ {
			var x int
			fmt.Fscan(in, &x)
			index := sort.Search(len(a), func(i int) bool {
				return a[i] >= x
			})
			if index == n {
				index = -2
			}
			fmt.Fprintln(out, index + 1)
		}
	}
}

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

package main

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

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

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

	var T int
	var n int
	var m int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &m)

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

		a := make([]int, n)
		sum :=0
		for i := n - 1; i >= 0; i-- {
			sum += r[i]
			a[n-1-i] = sum
		}

		for j := 0; j < m; j++ {
			Fscan(in, &x)
			ans := sort.SearchInts(a, x)
			if ans == n {
				Fprintln(out, -1)
			} else {
				Fprintln(out, ans+1)
			}
		}
	}
}

package main

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

//func max(a, b int) int {if a > b {return a} else {return b}}
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n, q int
	fmt.Fscan(r, &n, &q)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	sort.Ints(nums)
	prefix := make([]int, n+1)
	for i := n-1; i >=0 ; i-- {
		prefix[n-i] = prefix[n-i-1] + nums[i]
	}
	for i := 0; i < q; i++ {
		var tar int
		fmt.Fscan(r, &tar)
		j := sort.Search(n, func(j int) bool {
			return prefix[j+1] >= tar
		})
		if j >= n {
			fmt.Fprintln(w, -1)
		} else {
			fmt.Fprintln(w, j+1)
		}
	}
}

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

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func maxFloat(a float64, nums ...float64) float64 {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(arr)))

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

		for i := 0; i < m; i++ {
			var cur int
			fmt.Fscan(in, &cur)
			res := sort.SearchInts(cnt, cur) + 1
			if res > n {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, res)
			}
		}
	}
}

package main

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

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

	solve := func(curCase int) {
		var n,q int
		Fscan(in, &n,&q)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		sum := make([]int, n+1)
		for i, v := range a {
			sum[i+1] = sum[i] + v
		}

		for qi := 0; qi < q; qi++ {
			var x int
			Fscan(in, &x)
			i := sort.SearchInts(sum, x)
			if i == n+1 {
				i = -1
			}
			Fprintln(out, i)
		}

	}

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

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

}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

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

	t, _ := strconv.Atoi(line)

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

		strList = strings.Split(line, " ")
		n, _ := strconv.Atoi(strList[0])
		q, _ := strconv.Atoi(strList[1])

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

		strList = strings.Split(line, " ")

		list := make([]int64, n)
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
		}

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

		sum := make([]int64, n)
		for i := 0; i < n; i++ {
			var prev int
			if i == 0 {
				prev = 0
			} else {
				prev = i - 1
			}

			sum[i] = sum[prev] + list[i]
		}

		for i := 0; i < q; i++ {
			var quantityString string
			var quantity int64
			if scanner.Scan() {
				quantityString = scanner.Text()
				quantity, _ = strconv.ParseInt(quantityString, 10, 64)
			}

			candies := -1
			left := 1
			right := n
			for left <= right {
				mid := (left + right) / 2
				if sum[mid-1] >= quantity {
					candies = mid
					right = mid - 1
				} else {
					left = mid + 1
				}
			}

			fmt.Println(candies)
		}
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main(){
	defer writer.Flush()
	var t int
	scanf("%d\n",&t)
	for i := 0; i < t; i++ {
		var n, q int
		scanf("%d %d\n", &n, &q)
		v := make([]int, n)
		pref := make([]int, n+1)
		for i :=0; i < n; i++ {
			scanf("%d", &v[i])
		}
		scanf("\n")

		sort.Slice(v, func(i, j int) bool {
			return v[i] > v[j]
		})
		for i := 1; i <= n; i++ {
			pref[i] = pref[i-1] + v[i-1]
		}
		for i :=0; i < q; i++ {
			var x int
			scanf("%d\n", &x)
			l := -1
			r := n+1
			for l+1 < r {
				m := (l+r)/2
				if(pref[m] >= x) {
					r=m
				} else {
					l=m
				}
			}
			if(r != n+1) {
				printf("%d \n", r)
			} else {
				printf("%d \n", -1)
			}

		}

	}

}

package main

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

func binary_search(val int, x []int) int {
	l := 0
	h := len(x) - 1
	//m := m = (l + h) / 2
	for l <= h {
		m := (l + h) / 2
		if val > x[m] {
			l = m + 1
		} else {
			h = m - 1
		}
	}
	return h
}

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		n, _ := strconv.Atoi(ninps[0])
		q, _ := strconv.Atoi(ninps[1])

		x := make([]int, n)

		text, _ = reader.ReadString('\n')
		ninps = strings.Fields(text)
		for i, val := range ninps {
			x[i], _ = strconv.Atoi(val)
		}

		sort.Sort(sort.Reverse(sort.IntSlice(x)))

		sum := 0
		for i := 0; i < n; i++ {
			sum += x[i]
			x[i] = sum
		}

		for i := 0; i < q; i++ {
			text, _ = reader.ReadString('\n')
			ninps = strings.Fields(text)
			query, _ := strconv.Atoi(ninps[0])
			if query <= sum {
				ans := binary_search(query, x) + 2
				fmt.Println(ans)
			} else {
                                fmt.Println(-1)
			}
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

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

	t, _ := strconv.Atoi(line)

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

		strList = strings.Split(line, " ")
		n, _ := strconv.Atoi(strList[0])
		q, _ := strconv.Atoi(strList[1])

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

		strList = strings.Split(line, " ")

		list := make([]int64, n)
		var sum int64
		sum = 0
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
			sum += list[i]
		}

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

		for i := 0; i < q; i++ {
			var quantityString string
			var quantity int64
			if scanner.Scan() {
				quantityString = scanner.Text()
				quantity, _ = strconv.ParseInt(quantityString, 10, 64)
			}

			if quantity > sum {
				fmt.Println("-1")
				continue
			}

			if quantity == sum {
				fmt.Println(n)
				continue
			}

			var current int64
			current = 0
			diff := sum - quantity
			if n < 10 || diff >= sum/2 {
				for j := 0; j < n; j++ {
					current += list[j]
					if current >= quantity {
						fmt.Println(j + 1)
						break
					}
				}
			} else {
				for j := n - 1; j >= 0; j-- {
					current += list[j]
					if current >= diff {
						fmt.Println(j)
						break
					}
				}
			}
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

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

	t, _ := strconv.Atoi(line)

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

		strList = strings.Split(line, " ")
		n, _ := strconv.Atoi(strList[0])
		q, _ := strconv.Atoi(strList[1])

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

		strList = strings.Split(line, " ")

		list := make([]int64, n)
		var sum int64
		sum = 0
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
			sum += list[i]
		}

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

		for i := 0; i < q; i++ {
			var quantityString string
			var quantity int64
			if scanner.Scan() {
				quantityString = scanner.Text()
				quantity, _ = strconv.ParseInt(quantityString, 10, 64)
			}

			if quantity > sum {
				fmt.Println("-1")
				continue
			}

			if quantity == sum {
				fmt.Println(n)
				continue
			}

			var current int64
			current = 0
			diff := sum - quantity
			if diff >= sum/2 {
				for j := 0; j < n; j++ {
					current += list[j]
					if current >= quantity {
						fmt.Println(j + 1)
						break
					}
				}
			} else {
				for j := n - 1; j >= 0; j-- {
					current += list[j]
					if current >= diff {
						fmt.Println(j)
						break
					}
				}
			}
		}
	}
}

package main

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

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

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

		var n, q int
		fmt.Scanf("%d %d\n", &n, &q)

		var line string
		scanner := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 0, 13*200000)
		scanner.Buffer(buf, 13*200000)

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

		strList := strings.Split(line, " ")

		list := make([]int64, n)
		var sum int64
		sum = 0
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
			sum += list[i]
		}

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

		for i := 0; i < q; i++ {
			var quantityString string
			var quantity int64
			if scanner.Scan() {
				quantityString = scanner.Text()
				quantity, _ = strconv.ParseInt(quantityString, 10, 64)
			}

			if quantity > sum {
				fmt.Println("-1")
				continue
			}

			var current int64
			current = 0
			for j := 0; j < n; j++ {
				current += list[j]
				if current >= quantity {
					fmt.Println(j + 1)
					break
				}
			}
		}
	}
}

package main

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

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

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

		var n, q int
		fmt.Scanf("%d %d\n", &n, &q)

		var line string
		scanner := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 0, 13*200000)
		scanner.Buffer(buf, 13*200000)

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

		strList := strings.Split(line, " ")

		list := make([]int64, n)
		var sum int64
		sum = 0
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
			sum += list[i]
		}

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

		for i := 0; i < q; i++ {
			var quantity int64
			fmt.Scanln(&quantity)

			if quantity > sum {
				fmt.Println("-1")
				continue
			}

			var current int64
			current = 0
			for j := 0; j < n; j++ {
				current += list[j]
				fmt.Printf("%d %d %d", list[1], current, quantity)
				if current >= quantity {
					fmt.Println(j + 1)
					break
				}
			}
		}
	}
}

package main

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

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

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

		var n, q int
		fmt.Scanf("%d %d\n", &n, &q)

		var line string
		scanner := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 0, 13*200000)
		scanner.Buffer(buf, 13*200000)

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

		strList := strings.Split(line, " ")

		list := make([]int64, n)
		var sum int64
		sum = 0
		for i := 0; i < n; i++ {
			list[i], _ = strconv.ParseInt(strList[i], 10, 64)
			sum += list[i]
		}

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

		for i := 0; i < q; i++ {
			var quantity int64
			fmt.Scanln(&quantity)

			if quantity > sum {
				fmt.Println("-1")
				continue
			}

			var current int64
			current = 0
			for j := 0; j < n; j++ {
				current += list[j]
				if current >= quantity {
					fmt.Println(j + 1)
					break
				}
			}
		}
	}
}

package main

import(
	"fmt"
	"sort"
)

func main(){
	var t int
	fmt.Scanf("%d",&t)
	for i := 0; i < t; i++ {
		var n, q int
		fmt.Scanf("%d %d", &n, &q)
		v := make([]int, n)
		pref := make([]int, n+1)
		for i :=0; i < n; i++ {
			fmt.Scanf("%d", &v[i])
		}
		sort.Slice(v, func(i, j int) bool {
			return v[i] > v[j]
		})
		for i := 1; i <= n; i++ {
			pref[i] = pref[i-1] + v[i-1]
		}

		for i :=0; i < q; i++ {
			var x int
			fmt.Scanf("%d", &x)
			l := -1
			r := n+1
			for l+1 < r {
				m := (l+r)/2
				if(pref[m] >= x) {
					r=m
				} else {
					l=m
				}
			}
			if(r != n+1) {
				fmt.Printf("%d \n", r)
			} else {
				fmt.Printf("%d \n", -1)
			}

		}

	}

}

package main

import(
	"fmt"
	"sort"
)

func main(){
	var t int
	fmt.Scanf("%d",&t)
	for i := 0; i < t; i++ {
		var n, q int
		fmt.Scanf("%d %d", &n, &q)
		v := make([]int, n)
		pref := make([]int, n+1)
		for i :=0; i < n; i++ {
			fmt.Scanf("%d", &v[i])
		}
		sort.Slice(v, func(i, j int) bool {
			return v[i] > v[j]
		})
		for i := 1; i <= n; i++ {
			pref[i] = pref[i-1] + v[i-1]
		}
		fmt.Println(v)
		fmt.Println(pref)

		for i :=0; i < q; i++ {
			var x int
			fmt.Scanf("%d", &x)
			l := -1
			r := n+1
			for l+1 < r {
				m := (l+r)/2
				if(pref[m] >= x) {
					r=m
				} else {
					l=m
				}
			}
			if(r != n+1) {
				fmt.Printf("%d \n", r)
			} else {
				fmt.Printf("%d \n", -1)
			}

		}

	}

}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	for k := 0; k < t; k++ {
		n, q := 0, 0
		fmt.Fscan(in, &n, &q)
		fmt.Println(n, q)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		presum := make([]int, n+1)
		for i := 1; i <= n; i++ {
			presum[i] = presum[i-1] + a[i-1]
		}
		for i := 0; i < q; i++ {
			qq := 0
			fmt.Fscan(in, &qq)
			x := sort.Search(n+1, func(j int) bool {
				return presum[j] >= qq
			})
			if x == n+1 {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, x)
			}
		}
	}
}


package main

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

const N = 200005
var n int
var a[N] int
var b[N] int
var minMark[N] bool
var maxMark[N] bool

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

	for i := 1; i <= n; i++ {

		if minMark[i] {
			continue
		}

		if a[i] > 0 && minMark[i - 1] {
			continue
		}

		if a[i] > 0 {
			minMark[i+1] = true
		}
	}

	for i := 0; i <= n + 1; i++ {
		if maxMark[i] {
			if a[i] > 0 {
				maxMark[i + 1] = true
			}
			continue
		}

		if a[i] > 0 {
			maxMark[i] = true
			if a[i] > 1 {
				maxMark[i + 1] = true
			}
			continue
		}

		if a[i + 1] > 0 {
			a[i + 1]--
			maxMark[i] = true
		}
	}

	var minHall = 0
	var maxHall = 0

	for i := 0; i <= n + 1; i++ {
		if minMark[i] {
			minHall++
		}
		if maxMark[i] {
			maxHall++
		}
	}

	fmt.Fprintf(writer, "%d %d", minHall, maxHall)
}

package main

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

var writer *bufio.Writer
var reader *bufio.Reader

func get_min(x []int) int {
    var ans int
    for ptr_l := 1; ptr_l < len(x); ans++ {
        var ptr_r = ptr_l
        for ; ptr_r + 1 < len(x) && x[ptr_r + 1] - x[ptr_l] <= 2; ptr_r++ {
        }
        ptr_l = ptr_r + 1
    }
    return ans
}

func get_max(x []int) int {
    var ans int
    var last = -1
    for i := 1; i < len(x); i++ {
        if x[i] - 1 > last {
            last = x[i] - 1
            ans++
        } else if x[i] > last {
            last = x[i]
            ans++
        } else if x[i] + 1 > last {
            last = x[i] + 1
            ans++
        }
    }
    return ans
}

func solve() {
    var n int
    fmt.Fscanf(reader, "%d\n", &n)
    x := make([]int, n + 1, n + 1)
    for i := 1; i <= n; i++ {
        fmt.Fscanf(reader, "%d ", &x[i])
    }
    sort.Ints(x)
    fmt.Fprintf(writer, "%d %d\n", get_min(x), get_max(x))
}

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