package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.lr[1] == nil {
			return o.lr[0]
		}
		if o.lr[0] == nil {
			return o.lr[1]
		}
		d = 0
		if o.lr[0].priority > o.lr[1].priority {
			d = 1
		}
		o = o.rotate(d)
		o.lr[d] = t._delete(o.lr[d], key)
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return
}

func (t *treap) next(key int) (next *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return
}

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

	var T, n, m, id, d int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		t := &treap{rd: 1}
		mi := a[0] + 1
		for i, v := range a {
			if v < mi {
				ans++
				t.put(i)
				mi = v
			}
		}
		for ; m > 0; m-- {
			Fscan(in, &id, &d)
			id--
			v := a[id] - d
			if o := t.prev(id); o != nil && a[id] >= a[o.key] && v < a[o.key] {
				ans++
				t.put(id)
			}
			for o := t.next(id); o != nil && a[o.key] >= v; o = t.next(id) {
				ans--
				t.delete(o.key)
			}
			a[id] = v
			Fprint(out, ans, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

var (
	n, m, k, d int64
	a, b       [1e5 + 5]int64
	s          [4e5 + 5]struct{ l, r, res, lnum, rnum, bj int64 }
)

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

func build(p, l, r int64) {
	s[p].l = l
	s[p].r = r
	s[p].bj = -1
	if l == r {
		s[p].res = 1
		s[p].lnum = b[l]
		s[p].rnum = b[l]
		return
	}
	mid := (l + r) >> 1
	build(p<<1, l, mid)
	build(p<<1|1, mid+1, r)
	pushup(p)
}

func pushup(p int64) {
	ls, rs := p<<1, p<<1|1
	s[p].res = s[ls].res + s[rs].res
	if s[ls].rnum == s[rs].lnum {
		s[p].res--
	}
	s[p].lnum = s[ls].lnum
	s[p].rnum = s[rs].rnum
}

func pushdown(p int64) {
	if s[p].bj != -1 {
		ls, rs := p<<1, p<<1|1
		s[ls].lnum = s[p].bj
		s[ls].rnum = s[p].bj
		s[ls].bj = s[p].bj

		s[rs].lnum = s[p].bj
		s[rs].rnum = s[p].bj
		s[rs].bj = s[p].bj

		s[ls].res = 1
		s[rs].res = 1

		s[p].bj = -1
	}
}

func update(p, l, r, val int64) {
	if s[p].l > r || s[p].r < l {
		return
	}
	if s[p].l >= l && s[p].r <= r {
		s[p].res = 1
		s[p].bj = val
		s[p].lnum = val
		s[p].rnum = val
		return
	}
	pushdown(p)
	update(p<<1, l, r, val)
	update(p<<1|1, l, r, val)
	pushup(p)
}

func query(x, y int64) int64 {
	if s[x].l == s[x].r {
		return s[x].lnum
	}
	pushdown(x)
	mid := (s[x].l + s[x].r) >> 1
	if y <= mid {
		return query(x<<1, y)
	}
	return query(x<<1|1, y)
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int64) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int64(b&15)
		}
		return
	}
	a[0] = 1<<63 - 1
	b[0] = 1<<63 - 1
	for T := read(); T > 0; T-- {
		n, m = read(), read()
		for i := int64(1); i <= n; i++ {
			a[i] = read()
			b[i] = min(a[i], b[i-1])
		}
		build(1, 1, n)
		for j := int64(1); j <= m; j++ {
			k, d = read(), read()
			a[k] -= d
			x := min(a[k], query(1, k-1))
			l, r := k+1, n
			p := n + 1
			for l <= r {
				mid := (l + r) >> 1
				if query(1, mid) <= x {
					p = mid
					r = mid - 1
				} else {
					l = mid + 1
				}
			}
			update(1, k, p-1, x)
			Fprintf(out, "%d%c", s[1].res, " \n"[j/m])
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type node struct {
	lr       [2]*node
	priority uint
	key      int
}

func (o *node) cmp(b int) int {
	switch {
	case b < o.key:
		return 0
	case b > o.key:
		return 1
	default:
		return -1
	}
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	rd   uint
	root *node
}

func (t *treap) fastRand() uint {
	t.rd ^= t.rd << 13
	t.rd ^= t.rd >> 17
	t.rd ^= t.rd << 5
	return t.rd
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: t.fastRand(), key: key}
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._put(o.lr[d], key)
		if o.lr[d].priority > o.priority {
			o = o.rotate(d ^ 1)
		}
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if d := o.cmp(key); d >= 0 {
		o.lr[d] = t._delete(o.lr[d], key)
	} else {
		if o.lr[1] == nil {
			return o.lr[0]
		}
		if o.lr[0] == nil {
			return o.lr[1]
		}
		d = 0
		if o.lr[0].priority > o.lr[1].priority {
			d = 1
		}
		o = o.rotate(d)
		o.lr[d] = t._delete(o.lr[d], key)
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) prev(key int) (prev *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) <= 0 {
			o = o.lr[0]
		} else {
			prev = o
			o = o.lr[1]
		}
	}
	return
}

func (t *treap) next(key int) (next *node) {
	for o := t.root; o != nil; {
		if o.cmp(key) == 0 {
			next = o
			o = o.lr[0]
		} else {
			o = o.lr[1]
		}
	}
	return
}

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

	var T, n, m, id, d int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		t := &treap{rd: 1}
		mi := a[0] + 1
		for i, v := range a {
			if v < mi {
				ans++
				t.put(i)
				mi = v
			}
		}
		for ; m > 0; m-- {
			Fscan(in, &id, &d)
			id--
			v := a[id] - d
			if o := t.prev(id); o != nil && a[id] >= a[o.key] && v < a[o.key] {
				ans++
				t.put(id)
			}
			for o := t.next(id); o != nil && a[o.key] >= v; o = t.next(id) {
				ans--
				t.delete(o.key)
			}
			a[id] = v
			Fprint(out, ans, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

var (
	n, m, k, d int64
	a, b       [1e5 + 5]int64
	s          [4e5 + 5]struct{ l, r, res, lnum, rnum, bj int64 }
)

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

func build(p, l, r int64) {
	s[p].l = l
	s[p].r = r
	s[p].bj = -1
	if l == r {
		s[p].res = 1
		s[p].lnum = b[l]
		s[p].rnum = b[l]
		return
	}
	mid := (l + r) >> 1
	build(p<<1, l, mid)
	build(p<<1|1, mid+1, r)
	pushup(p)
}

func pushup(p int64) {
	ls, rs := p<<1, p<<1|1
	s[p].res = s[ls].res + s[rs].res
	if s[ls].rnum == s[rs].lnum {
		s[p].res--
	}
	s[p].lnum = s[ls].lnum
	s[p].rnum = s[rs].rnum
}

func pushdown(p int64) {
	if s[p].bj != -1 {
		ls, rs := p<<1, p<<1|1
		s[ls].lnum = s[p].bj
		s[ls].rnum = s[p].bj
		s[ls].bj = s[p].bj

		s[rs].lnum = s[p].bj
		s[rs].rnum = s[p].bj
		s[rs].bj = s[p].bj

		s[ls].res = 1
		s[rs].res = 1

		s[p].bj = -1
	}
}

func update(p, l, r, val int64) {
	if s[p].l > r || s[p].r < l {
		return
	}
	if s[p].l >= l && s[p].r <= r {
		s[p].res = 1
		s[p].lnum = val
		s[p].rnum = val
		return
	}
	pushdown(p)
	update(p<<1, l, r, val)
	update(p<<1|1, l, r, val)
	pushup(p)
}

func query(x, y int64) int64 {
	if s[x].l == s[x].r {
		return s[x].lnum
	}
	pushdown(x)
	mid := (s[x].l + s[x].r) >> 1
	if y <= mid {
		return query(x<<1, y)
	}
	return query(x<<1|1, y)
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int64) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int64(b&15)
		}
		return
	}
	a[0] = 1<<63 - 1
	b[0] = 1<<63 - 1
	for T := read(); T > 0; T-- {
		n, m = read(), read()
		for i := int64(1); i <= n; i++ {
			a[i] = read()
			b[i] = min(a[i], b[i-1])
		}
		build(1, 1, n)
		for j := int64(1); j <= m; j++ {
			k, d = read(), read()
			a[k] -= d
			x := min(a[k], query(1, k-1))
			l, r := k+1, n
			p := n + 1
			for l <= r {
				mid := (l + r) >> 1
				if query(1, mid) <= x {
					p = mid
					r = mid - 1
				} else {
					l = mid + 1
				}
			}
			update(1, k, p-1, x)
			Fprintf(out, "%d%c", s[1].res, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok && x > res {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			if T == 10000-1640 {
				Fprint(out, "[", k, d, "] ")
			} else {
				Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
			}
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			if T == 10000-1640 {
				Fprint(out, k, d, " \n"[j/m])
			} else {
				Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
			}
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			if T == 10000-1640 {
				Fprint(out, k, d, " ")
			} else {
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
			}
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			if T == 10000-1640 {
				Fprint(out, k, d, " ")
			}
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 10000-1640 {
			Fprintln(out, n, m, s[1:n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		if T == 10000-1640 {
			Fprintln(out, n, m)
		}
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	cnt3 := 0
	cnt4 := 0
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			if len(mp)-2 == 3 {
				cnt3++
			}
			if len(mp)-2 == 4 {
				cnt4++
			}
			if cnt3 == 3 && cnt4 == 4 {
				Fprintln(out, s[1:n+1])
			} else {
				Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
			}
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	cnt := 0
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			cnt++
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	cnt := 0
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			cnt++
			if cnt == 1641 {
			    Fprintln(out,s[1:n+1])
			} else {
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
			}
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	cnt := 0
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			cnt++
			if cnt == 1641 {
			    Fprintln(out,s[1:n+1])
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	cnt := 0
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			cnt++
			if cnt == 1641 {
			    Println(s[1:n+1])
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8161 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8165 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8170 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8160 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8100 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8200 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8250 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8000 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 7000 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8300 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func upper_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		if T == 8360 {
			Println(s[1 : n+1])
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := upper_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	mp map[int]int
	s  [1e5 + 5]int
)

func lower_bound(l, r int, mp map[int]int, x int) (res int) {
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if _, ok := mp[mid]; ok {
			res = mid
		}
		if mid <= x {
			res = mid
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	res--
	for {
		_, ok := mp[res]
		if ok {
			break
		}
		res--
	}
	return
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		mp = make(map[int]int)
		mp[0] = 1e9 + 1
		mp[n+1] = -1
		for i, pre := 1, int(1e6+1); i <= n; i++ {
			s[i] = read()
			if pre > s[i] {
				pre = s[i]
				mp[i] = pre
			}
		}
		for j := 1; j <= m; j++ {
			k, d := read(), read()
			s[k] -= d
			idx := lower_bound(0, n+1, mp, k)
			if mp[idx] > s[k] {
				if idx != k {
					mp[k] = mp[idx]
				}
				for i, v := range mp {
					if i >= k && v >= s[k] {
						delete(mp, i)
					}
				}
				mp[k] = s[k]
			}
			Fprintf(out, "%d%c", len(mp)-2, " \n"[j/m])
		}
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9 + 1)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				l, r := 1, len(t)-1
				for l <= r {
					mid := int(uint(l+r) >> 1)
					if t[mid].l < k {
						l = mid + 1
					} else if t[mid].l > k {
						r = mid - 1
					} else {
						idx = mid
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				if k < t[tlen].l {
					t = append(t[:idx], append(odt{{k, s[k]}}, t[idx:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9 + 1)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				l, r := 1, tlen
				for l <= r {
					mid := int(uint(l+r) >> 1)
					if t[mid].l < k {
						l = mid + 1
					} else if t[mid].l > k {
						r = mid - 1
					} else {
						idx = mid
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				if k < t[tlen].l {
					t = append(t[:idx], append(odt{{k, s[k]}}, t[idx:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9 + 1)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				l, r := 1, tlen
				for l < r {
					mid := int(uint(l+r) >> 1)
					if t[mid].l < k {
						l = mid + 1
					} else if t[mid].l > k {
						r = mid
					} else {
						idx = mid
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				if k < t[tlen].l {
					t = append(t[:idx], append(odt{{k, s[k]}}, t[idx:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 && s[2] == 0 {
			flag = true
		}

		for ; m > 0; m-- {
			k, d := read(), read()
			if flag && T == 997 {
			    flag = false
				Fprintln(out, k, d)
			}
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 && s[2] == 0 {
			flag = true
		}

		for ; m > 0; m-- {
			k, d := read(), read()
			if flag && T == 997 {
			    flag = false
				Println(k, d)
			}
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 && s[2] == 0 {
			flag = true
		}

		for ; m > 0; m-- {
			k, d := read(), read()
			if flag && T == 997 {
				Println(k, d)
			}
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 {
			flag = true
		}

		for ; m > 0; m-- {
			k, d := read(), read()
			if flag && T == 997 {
				Println(k, d)
			}
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 && s[2] == 0 {
			flag = true
		}
		if flag && T == 997 {
			Println(s[:n+1])
		}
		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	flag := false
	for T := read(); T > 0; T-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})
		if n == 100 && m == 100 {
			flag = true
		}
		if flag && T == 997 {
			Println(s[:n+1])
		}
		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})

		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				idx = upper_bound(t, k)
				idx--
				if k < t[tlen].l {
					t = append(t[:idx+1], append(odt{{k, s[k]}}, t[idx+1:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l <= r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})

		for ; m > 0; m-- {
			k, d := read(), read()
			if d > s[k] {
				s[k] = 0
			} else {
				s[k] -= d
			}
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				if k < t[tlen].l {
					t = append(t[:idx], append(odt{{k, s[k]}}, t[idx:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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

package main

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

var (
	s  [1e5 + 5]int
	ln = []byte{'\n'}
)

type odtBlock struct {
	l, val int
}

type odt []odtBlock

func newODT(arr []int) odt {
	n := len(arr) - 1
	t := make(odt, 0, n+1)
	t = append(t, odtBlock{0, 1e9})
	pre := int(1e9)
	for i := 1; i <= n; i++ {
		if pre > arr[i] {
			pre = arr[i]
			t = append(t, odtBlock{i, arr[i]})
		}
	}
	return t
}

func upper_bound(arr odt, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := int(uint(l+r) >> 1)
		if arr[mid].l <= target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n, m := read(), read()
		for i := 1; i <= n; i++ {
			s[i] = read()
		}
		t := newODT(s[:n+1])
		t = append(t, odtBlock{n + 1, -1})

		for ; m > 0; m-- {
			k, d := read(), read()
			s[k] -= d
			tlen := len(t) - 1
			idx := upper_bound(t, k)
			idx--
			if t[idx].val > s[k] {
				if idx != k {
					if k < t[tlen].l {
						t = append(t[:idx+1], append(odt{{k, t[idx].val}}, t[idx+1:]...)...)
					} else {
						t = append(t[:tlen], append(odt{{k, t[idx].val}}, t[tlen:]...)...)
					}
				}
				for i := range t {
					if t[i].l == k {
						idx = i
						break
					}
				}
				tmp := idx
				for t[tmp].val >= s[k] {
					tmp++
				}
				t = append(t[:idx], t[tmp:]...)
				tlen = len(t) - 1
				if k < t[tlen].l {
					t = append(t[:idx], append(odt{{k, s[k]}}, t[idx:]...)...)
				} else {
					t = append(t[:tlen], append(odt{{k, s[k]}}, t[tlen:]...)...)
				}
			}
			Fprint(out, len(t)-2, " ")
		}
		out.Write(ln)
	}
}

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


package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

const N = 300300

var tr [3][N]int64

func add(tr []int64, p, x int) {
	for p < N {
		tr[p] += int64(x)
		p |= p + 1
	}
}

func get(tr []int64, p int) int64 {
	r := int64(0)
	for p >= 0 {
		r += int64(tr[p])
		p = p&(p+1) - 1
	}
	return r
}

func sum(tr []int64, l, r int) int64 {
	return get(tr, r) - get(tr, l-1)
}

func main() {
	defer out.Flush()
	n := Read()
	s := int64(0)
	for i := 0; i < n; i++ {
		x := Read()
		k := get(tr[0][:], x)
		s += (int64(i) - k) * int64(x)
		s += get(tr[1][:], x)
		s += k*int64(x) - get(tr[2][:], x)
		for j := x; j < N; j += x {
			r := j + x
			if r >= N {
				r = N - 1
			}
			s += sum(tr[1][:], j, r-1) - sum(tr[0][:], j, r-1)*int64(j)
			add(tr[2][:], j, j)
			add(tr[2][:], r, -j)
		}
		add(tr[0][:], x, 1)
		add(tr[1][:], x, x)
		Fprint(out, s, " ")
	}
	Fprintln(out)
}

package main
import "fmt"
import "bufio"
import "os"

var n int
var a[200005] int
var tree[300005] int
var tree2[300005] int

func update(x, y int){
  for x <= 300000 {
    tree[x] += y
    x += (x & -x)
  }
}

func get(x int) int{
  var res = 0
  for x >= 1 {
    res += tree[x]
    x -= (x & -x)
  }
  return res
}

func update2(x, y int){
  for x <= 300000 {
    tree2[x] += y
    x += (x & -x)
  }
}

func get2(x int) int{
  var res = 0
  for x >= 1 {
    res += tree2[x]
    x -= (x & -x)
  }
  return res
}

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

func solve(){
  var ans = 0
  var sum = 0
  for i := 1; i <= n; i++ {
    ans += a[i] * (i - 1) + sum - get2(a[i])
    sum += a[i]
    for j := a[i]; j <= 300000; j += a[i] {
      var num = get(min(300000, j + a[i] - 1)) - get(j - 1)
      ans -= num * j
      update2(j, a[i])
    }
    update(a[i], 1)
    fmt.Print(ans, " ")
  }
}

func main(){
  in := bufio.NewReader(os.Stdin)
  fmt.Fscan(in, &n);
  for i := 1; i <= n; i++ {
    fmt.Fscan(in, &a[i])
  }
  solve()
}


package main

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

func Abs(x int) int {
	switch {
	case x < 0:
		return -x
	case x == 0:
		return 0
	}
	return x
}

func Scan(args ...interface{}) (e error)             { _, e = fmt.Fscan(in, args...); return }
func Scanf(ft string, args ...interface{}) (e error) { _, e = fmt.Fscanf(in, ft, args...); return }
func Scanln(args ...interface{}) (e error)           { _, e = fmt.Fscanln(in, args...); return }
func Print(args ...interface{})                      { out.WriteString(fmt.Sprint(args...)) }
func Printf(ft string, args ...interface{})          { out.WriteString(fmt.Sprintf(ft, args...)) }
func Println(args ...interface{})                    { out.WriteString(fmt.Sprintln(args...)) }

var (
	//dataIn = "data.in"
	in     = bufio.NewReader(os.Stdin)
	//in, _ = os.Open(dataIn)
	out = bufio.NewWriter(os.Stdout)
)

var n, a, b int

func solve() {
	if a*b < n {
		Println(-1)
	} else {
		cur := 1
		for i := 0; i < a; i++ {
			for j := 0; j < b; j++ {
				if j > 0 {
					Print(" ")
				}
				if cur <= n {
					Print(cur)
				} else {
					Print(0)
				}
				if b&1 == 0 && i&1 == 1 {
					cur--
				} else {
					cur++
				}
			}
			if b&1 == 0 {
				cur += b
				if i&1 == 1 {
					cur++
				} else {
					cur--
				}
			}
			Println()
		}
	}
	return
}

func main() {
	defer out.Flush()
	for Scan(&n, &a, &b) != io.EOF {
		solve()
	}
	return
}

package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scanf("%d%d%d", &n, &a, &b)
	if n > a*b {
		fmt.Printf("-1")
		return
	}
	num := 1
	for i := 1; i <= a; i++ {
		if i%2 == 1 {
			for j := 1; j <= b; j++ {
				if num > n {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("%d ", num)
					num++
				}
			}
		} else {
			if num+b-1 <= n {
				num += b - 1
				for j := 1; j <= b; j++ {
					fmt.Printf("%d ", num+1-j)
				}
				num++
			} else {
				t := num + b - 1 - n
				for j := 0; j < t; j++ {
					fmt.Printf("0 ")
				}
				num = num + b - 1 - t
				for j := 0; j < b-t; j++ {
					fmt.Printf("%d ", num-j)
				}
				num++
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    var q []int = make([]int, a*b)
    current := 1
    for i := 0; i < a; i += 2 {
        for j := 0; j < b; j++ {
            q[b*i+j] = current
            current += 1
        }
        if i+1 < a {
            for j := b-1; j >= 0; j-- {
                q[b*(i+1)+j] = current
                current += 1
            }
        }
    }
    if current < n {
        fmt.Printf("-1")
        return
    }
    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if q[b*i+j] <= n {
                fmt.Printf("%d ", q[b*i+j])
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }
}

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    var q []int = make([]int, a*b)
    current := 1
    for i := 0; i < a; i += 2 {
        for j := 0; j < b; j++ {
            q[b*i+j] = current
            current += 1
        }
        if i+1 < a {
            for j := b-1; j >= 0; j-- {
                q[b*(i+1)+j] = current
                current += 1
            }
        }
    }

    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if q[b*i+j] <= n {
                fmt.Printf("%d ", q[b*i+j])
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
)

func main() {
	defer func() {
		r := recover()
		if r != nil {
			fmt.Println(-1)
		}
	}()

	n := 0
	a := 0
	b := 0
	_, err := fmt.Scan(&n, &a, &b)
	if err != nil {
		fmt.Println(err)
		return
	}
	if n > a*b {
		fmt.Println(-1)
		return
	}
	even := (b % 2) == 0
	num := 1
	for i := 0; i < a; i++ {
		if even && i%2 > 0 {
			for j := num + b - 1; j >= num; j-- {
				if j > n {
					fmt.Print(0, " ")
				} else {
					fmt.Print(j, " ")
				}
			}
		} else {
			for j := num; j < num+b; j++ {
				if j > n {
					fmt.Print(0, " ")
				} else {
					fmt.Print(j, " ")
				}
			}
		}
		num = num + b
		fmt.Println()
	}
}

package main
import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	place := make([][]int, a)
	for i := range place{
		place[i] = make([]int, b)
	}
	maxeven := (n/2)*2

	if a*b < n {
		fmt.Printf("%d",-1)
	}else{
		count := 1
		for i := 0; (i < a)&&(count <= n); i+=2{
			for j := 0; (j < b)&&(count <= n); j+=2 {
				place[i][j] = count
				count += 2
			}
		}
		for i := 1; (i < b)&&(count <= n); i+=2{
			for j := 1; (j < a)&&(count <= n); j+=2 {
				place[j][i] = count
				count += 2
			}
		}
		count = 2
		for i := 0; (i < a)&&(count <= maxeven); i+=2{
			for j := 1; (j < b)&&(count <= maxeven); j+=2 {
				place[i][j] = count
				count += 2
			}
		}
		for i := 0; (i < b)&&(count <= maxeven); i+=2{
			for j := 1; (j < a)&&(count <= maxeven); j+=2 {
				place[j][i] = count
				count += 2
			}
		}
		for _ ,r:= range place{
			for _, m := range r{
				fmt.Printf("%d ", m)
			}
			fmt.Printf("\n")
		}
	}
}

package main

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

func ReadInt32(scanner *bufio.Scanner) int {
  scanner.Scan()
  ans, _ := strconv.Atoi(scanner.Text())
  return ans
}

func ReadString(scanner *bufio.Scanner) string {
  scanner.Scan()
  ans := scanner.Text()
  return ans
}

func PrintInt(writer *bufio.Writer, value int) {
  writer.WriteString(strconv.Itoa(value))
  writer.WriteByte(' ')
}

func PrintInts(writer *bufio.Writer, ints ...int) {
  for _, value := range ints {
    writer.WriteString(strconv.Itoa(value))
    writer.WriteByte(' ')
  }
  writer.WriteByte('\n')
}

func main() {
  // fi, err := os.Open("./input.txt")
  // if err != nil {
  //   fmt.Println("Can open file.")
  //   return
  // }

  // defer fi.Close()
  var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
  var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()
  scanner.Split(bufio.ScanWords)

  var n, a, b int = ReadInt32(scanner), ReadInt32(scanner), ReadInt32(scanner)
  if a * b < n {
    PrintInts(writer, -1)
    return
  }

  for i := 0; i < a; i++ {
    md := i % 2
    k := n - i * b - md * (b-1)
    for j := 0; j < b; j++ {
      if k < 0 {
        PrintInt(writer, 0)
      } else {
        PrintInt(writer, k)
      }
      if md == 0 {
        k--
      } else {
        k++
      }
    }
    writer.WriteByte('\n')
  }
  // writer.WriteByte('\n')
}

package main

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

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)

	var n, a, b int = readInt(), readInt(), readInt()
	f := func(x int) int {
		return x/2 + x%2
	}
	pplh, plch := f(n), f(a*b)
	if pplh > plch {
		printInts(-1)
		println()
	} else if b%2 == 1 {
		for i, k := 0, 1; i < a; i++ {
			for j := 0; j < b; j++ {
				if k <= n {
					printInts(k)
					k++
				} else {
					printInts(0)
				}
			}
			println()
		}
	} else {
		is := true
		var m, off int
		for i, k := 0, 1; i < a; i++ {
			if is {
				m, off = i*b+1, 1
			} else {
				m, off = (i+1)*b, -1
			}
			for j := 0; j < b; j++ {
				if k > n || m > n {
					printInts(0)
					m--
				} else {
					printInts(m)
					m += off
					k++
				}
			}
			is = !is
			println()
		}
	}
}

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	wr *bufio.Writer  = bufio.NewWriter(os.Stdout)
)

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

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

func printInts(ints ...int) {
	for _, v := range ints {
		wr.WriteString(strconv.Itoa(v))
		wr.WriteByte(' ')
	}
}
func printInt64s(ints ...int64) {
	for _, v := range ints {
		wr.WriteString(strconv.FormatInt(v, 10))
		wr.WriteByte(' ')
	}
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

func println() {
	wr.WriteByte('\n')
}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		fmt.Fprintln(os.Stderr, runtime.GOMAXPROCS(0))
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}

package main

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

var (
	n, a, b int
	field   [][]int
)

func main() {
	defer out.Flush()
	fmt.Fscan(in, &n, &a, &b)
	for first := 0; first <= 1; first++ {
		field = make([][]int, a)
		for i := range field {
			field[i] = make([]int, b)
		}
		switch first {
		case 0:
			put(2)
			put(1)
		case 1:
			put(1)
			put(2)
		}
		if check() {
			for i := range field {
				for j := range field[i] {
					if j != 0 {
						fmt.Fprint(out, " ")
					}
					fmt.Fprint(out, field[i][j])
				}
				fmt.Fprintln(out)
			}
			return
		}
	}
	fmt.Fprintln(out, -1)
}

func eq(a, b int) bool {
	if a == 0 || b == 0 {
		return false
	}
	return a%2 == b%2
}

func canPut(i, j, x int) bool {
	if field[i][j] != 0 {
		return false
	}
	if i-1 >= 0 && eq(field[i-1][j], x) {
		return false
	}
	if j-1 >= 0 && eq(field[i][j-1], x) {
		return false
	}
	if i+1 < a && eq(field[i+1][j], x) {
		return false
	}
	if j+1 < b && eq(field[i][j+1], x) {
		return false
	}
	return true
}

func put(first int) {
	next := first
	for i := 0; i < a && next <= n; i++ {
		for j := 0; j < b && next <= n; j++ {
			if canPut(i, j, next) {
				field[i][j] = next
				next += 2
			}
		}
	}
}

func check() bool {
	seen := make([]bool, n)
	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			if field[i][j] != 0 {
				seen[field[i][j]-1] = true
			}
		}
	}
	for i := range seen {
		if !seen[i] {
			return false
		}
	}
	return true
}

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

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if b*i+j < n {
                fmt.Printf("%d ", b*i + j + 1)
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }

}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-runtime.GOMAXPROCS(0))
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}


package main

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

func main() {
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Buffer(make([]byte, 10000), 1000000)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	r.Scan()
	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		r.Scan()
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			r.Scan()
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	in := scanInt()
	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n*2)

		sort.Ints(a)

		fmt.Println(a[n]-a[n-1])

	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    capacity := 5000 * 1024
    scanner.Buffer(make([]byte, capacity), capacity)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])

        scanner.Scan()
        line = scanner.Text()
        //~ fmt.Println(scanner.Text())
        parts = strings.Split(line, " ")
        a := make([]int, 2 * n)
        //~ fmt.Println(line)
        //~ fmt.Println(parts)
        for j := 0; j < 2 * n; j++ {
            //~ fmt.Println(j, len(a), len(parts))
            a[j], _ = strconv.Atoi(parts[j]);
        }
        sort.Ints(a);
        //~ fmt.Println(a);
        v1, v2 := a[n - 1], a[n]
        var abs_diff int
        if v1 < v2 {
            abs_diff = v2 - v1
        } else {
            abs_diff = v1 - v2
        }
        fmt.Println(abs_diff)
    }
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		printf("%d\n", a[n]-a[n-1])
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	in := scanInt()
	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n*2)

		sort.Ints(a)

		fmt.Println(a[n]-a[n-1])
		fmt.Println(a)

	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		if n%2 == 0 {
			printf("%d\n", a[n-1]-a[n-2])
		} else {
			printf("%d\n", a[n]-a[n-1])
		}
	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		if n%2 == 0 {
			printf("%d\n", a[n]-a[n-2])
		} else {
			printf("%d\n", a[n]-a[n-1])
		}
	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var tests int
	scanf("%d\n", &tests)

	for t := 0; t < tests; t++ {
		var n int
		scanf("%d\n", &n)

		sum := 0
		count := 0
		for i := 0; i < n; i++ {
			var a int
			scanf("%d", &a)
			if a == 0 {
				a++
				count++
			}
			sum += a
		}

		if sum == 0 {
			count++
		}

		scanf("\n")

		printf("%d\n", count)
	}
}

package main

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

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

	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		var x, y int
		var b, c int
		for _, e := range a {
			if x > y {
				y += e
				c++
			} else {
				x += e
				b++
			}
		}
		if b%2 != 0 {
			ans[i] = fmt.Sprint(int(math.Abs(float64(x - y))))
		} else {
			ans[i] = fmt.Sprint(int(math.Abs(float64(x-y))) + 2*a[len(a)-1])
		}

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		var x, y int
		var b, c int
		for _, e := range a {
			if x > y {
				y += e
				c++
			} else {
				x += e
				b++
			}
		}
		abs := int(math.Abs(float64(x - y)))
		if b%2 != 0 {
			ans[i] = fmt.Sprint(abs)
		}
		// else {
		//	ans[i] = fmt.Sprint(abs + 2*a[len(a)-1])
		//}

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

func main() {
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Buffer(make([]byte, 10000), 1000000)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}