Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.A string is 1-palindrome if and only if it reads the same backward as forward.A string is k-palindrome (k > 1) if and only if:   Its left half equals to its right half.  Its left and right halfs are non-empty (k - 1)-palindromes. The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string t divided by 2, rounded down.Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.

The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.

Print |s| integers — palindromic characteristics of string s.

NoteIn the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	N := len(S)

	P := MakeIntMatrix(N, N)
	for c := 0; c < N; c++ {
		P[c][c] = 1
		for lo, hi := c - 1, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 1
			} else {
				break
			}
		}
		for lo, hi := c, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 1
			} else {
				break
			}
		}
	}

	for len := 2; len <= N; len++ {
		half := len >> 1
		for i := 0; i + len <= N; i++ {
			if prev := P[i][i + half - 1]; prev > 0 && S[i : i+half] == S[i+len-half : i+len] {
				P[i][i + len - 1] = 1 + prev
			}
		}
	}

	freq := make([]int, N + 1)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			freq[P[i][j]]++
		}
	}
	for i := N - 2; i >= 0; i-- {
		freq[i] += freq[i + 1]
	}

	for i := 1; i <= N; i++ {
		io.Printf("%d ", freq[i])
	}
	io.Println("")
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	N := len(S)

	P := MakeIntMatrix(N, N)
	for c := 0; c < N; c++ {
		P[c][c] |= (1 << 1)
		for lo, hi := c - 1, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] |= (1 << 1)
			} else {
				break
			}
		}
		for lo, hi := c, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] |= (1 << 1)
			} else {
				break
			}
		}
	}

	for len := 2; len <= N; len++ {
		half := len >> 1
		for i := 0; i + len <= N; i++ {
			if S[i : i+half] == S[i+len-half : i+len] {
				for b := (1 << 1); b < (1 << 16); b <<= 1 {
					if (P[i][i + half - 1] & b) > 0 && (P[i + len - half][i + len - 1] & b) > 0 {
						P[i][i + len - 1] |= (b << 1)
					}
				}
			}
		}
	}

	freq := make([]int, N + 1)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			for k := uint(1); k < 16; k++ {
				b := (1 << k)
				if P[i][j] & b > 0 {
					freq[k]++
				}
			}
		}
	}

	for i := 1; i <= N; i++ {
		io.Printf("%d ", freq[i])
	}
	io.Println("")
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

import "fmt"

const MAXN = 5001

var (
	input          string
	n              int
	isPalindrome   [MAXN][MAXN]int
	palindromeType [MAXN]int
)

func init() {
	for i := 0; i < MAXN; i++ {
		for j := 0; j < MAXN; j++ {
			isPalindrome[i][j] = -1
		}
	}
}

func computeIsPalindrome(inclusiveStart, inclusiveEnd int) int {
	switch {
	case isPalindrome[inclusiveStart][inclusiveEnd] != -1:
	case inclusiveStart == inclusiveEnd:
		isPalindrome[inclusiveStart][inclusiveEnd] = 1
	case input[inclusiveStart] != input[inclusiveEnd]:
		isPalindrome[inclusiveStart][inclusiveEnd] = 0
	case inclusiveStart == inclusiveEnd-1:
		isPalindrome[inclusiveStart][inclusiveEnd] = 1
	default:
		isPalindrome[inclusiveStart][inclusiveEnd] = computeIsPalindrome(inclusiveStart+1, inclusiveEnd-1)
	}
	return isPalindrome[inclusiveStart][inclusiveEnd]
}

func getPalindromeType(start, length int) int {
	switch end := start + length - 1; {
	case end-start == 0:
		return 1
	case isPalindrome[start][end] == 1:
		return 1 + getPalindromeType(start, length/2)
	default:
		return 0
	}
}

func main() {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			computeIsPalindrome(i, j)
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i+j <= n; j++ {
			palindromeType[getPalindromeType(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeType[i-1] += palindromeType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeType[i])
	}
}

package main

import "fmt"

const (
	MOD  =  982451653  // some large prime
	MULTI = 13758397 // another large prime
	MULTI2 = 13756541 // another large prime
)

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	var buff int64
	buff = int64(accumulated) * MULTI + int64(int(val) - int('a')) * MULTI2
	return int(buff % MOD)
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	N := len(S)

	P := MakeIntMatrix(N, N)
	for c := 0; c < N; c++ {
		P[c][c] = 1
		for lo, hi := c - 1, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 1
			} else {
				break
			}
		}
		for lo, hi := c, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 1
			} else {
				break
			}
		}
	}

	for len := 2; len <= N; len++ {
		half := len >> 1
		for i := 0; i + len <= N; i++ {
			if S[i : i+half] == S[i+len-half : i+len] {
				P[i][i + len - 1] = 1 + P[i][i + half - 1]
			}
		}
	}

	freq := make([]int, N + 1)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			freq[P[i][j]]++
		}
	}
	for i := N - 2; i >= 0; i-- {
		freq[i] += freq[i + 1]
	}

	for i := 1; i <= N; i++ {
		io.Printf("%d ", freq[i])
	}
	io.Println("")
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	N := len(S)

	P := MakeIntMatrix(N, N)
	for c := 0; c < N; c++ {
		P[c][c] = 1
		for lo, hi := c - 1, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 1
			} else {
				break
			}
		}
		for lo, hi := c, c + 1; lo >= 0 && hi < N; lo, hi = lo - 1, hi + 1 {
			if S[lo] == S[hi] {
				P[lo][hi] = 2
			} else {
				break
			}
		}
	}

	for len := 3; len <= N; len++ {
		half := len >> 1
		for i := 0; i + len <= N; i++ {
			if S[i : i+half] == S[i+len-half : i+len] {
				P[i][i + len - 1] = 1 + P[i][i + half - 1]
			}
		}
	}

	freq := make([]int, N + 1)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			freq[P[i][j]]++
		}
	}
	for i := N - 2; i >= 0; i-- {
		freq[i] += freq[i + 1]
	}

	for i := 1; i <= N; i++ {
		io.Printf("%d ", freq[i])
	}
	io.Println("")
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

import "fmt"

const MOD  =  179424691  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated + int(val) + accumulated * 7 + (int(val) - int('a')) * 3) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  160481219  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated * 7 + (int(val) - int('a')) * 3) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  179424691  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated * 7 + (int(val) - int('a')) * 3) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  982451653  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return ((accumulated+1) * ((accumulated + int(val)) % 2) + int(val) - int('a')) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  982451653  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated % 17 + accumulated + (int(val) - int('a')) * 3) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  982451653  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated * ((accumulated + int(val)) % 2) + int(val) - int('a')) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}

package main

import "fmt"

const MOD  =  13757927  // some large prime

var (
	forwardHash [5001][5001] int
	reverseHash [5001][5001] int
	palindromeOfType [5001] int
	input string
	n int
)

func computeHash(accumulated int, val byte) int {
	return (accumulated * 7 + (int(val) - int('a')) * 3) % MOD
}

func getTypeOfPalindrome(start, length int) int {
	end := start + length - 1

	if length == 1 {
		return 1
	}
	if forwardHash[start][length] == reverseHash[end][length] {
		return 1 + getTypeOfPalindrome(start, length / 2)
	}
	return 0
}

func main()  {
	fmt.Scan(&input)
	n = len(input)

	for i := 0; i < n; i++ {
		var fhash, rhash = computeHash(0, byte(input[i])), computeHash(0, byte(input[i]))
		forwardHash[i][1] = fhash
		reverseHash[i][1] = rhash

		for j := 1; ; j++ {
			computedHashes := 0
			if i + j < n {
				fhash = computeHash(fhash, byte(input[i+j]))
				forwardHash[i][j + 1] = fhash
				computedHashes += 1
			}
			if i - j >= 0 {
				rhash = computeHash(rhash, byte(input[i-j]))
				reverseHash[i][j + 1] = rhash
				computedHashes += 1
			}
			if computedHashes == 0 {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 1; i + j <= n; j++ {
			palindromeOfType[getTypeOfPalindrome(i, j)]++
		}
	}

	for i := n; i >= 1; i-- {
		palindromeOfType[i - 1] += palindromeOfType[i]
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d ", palindromeOfType[i])
	}
	fmt.Println()
}


There are $$$n$$$ of independent carriages on the rails. The carriages are numbered from left to right from $$$1$$$ to $$$n$$$. The carriages are not connected to each other. The carriages move to the left, so that the carriage with number $$$1$$$ moves ahead of all of them.The $$$i$$$-th carriage has its own engine, which can accelerate the carriage to $$$a_i$$$ km/h, but the carriage cannot go faster than the carriage in front of it. See example for explanation.All carriages start moving to the left at the same time, and they naturally form trains. We will call trains — consecutive moving carriages having the same speed.For example, we have $$$n=5$$$ carriages and array $$$a = [10, 13, 5, 2, 6]$$$. Then the final speeds of the carriages will be $$$[10, 10, 5, 2, 2]$$$. Respectively, $$$3$$$ of the train will be formed.There are also messages saying that some engine has been corrupted:  message "k d" means that the speed of the $$$k$$$-th carriage has decreased by $$$d$$$ (that is, there has been a change in the maximum speed of the carriage $$$a_k = a_k - d$$$).  Messages arrive sequentially, the processing of the next message takes into account the changes from all previous messages.After each message determine the number of formed trains.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of input test cases. This is followed by descriptions of the test cases. The first line of each test case is empty. The second line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$) —the number of carriages and the number of messages to slow down the carriage, respectively. The third line contains $$$n$$$ integers: $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number $$$a_i$$$ means that the carriage with number $$$i$$$ can reach a speed of $$$a_i$$$ km/h.  The next $$$m$$$ lines contain two integers $$$k_j$$$ and $$$d_j$$$ ($$$1 \le k_j \le n$$$, $$$0 \le d_j \le a_{k_j}$$$) —this is the message that the speed of the carriage with number $$$k_j$$$ has decreased by $$$d_j$$$. In other words, there has been a change in its maximum speed $$$a_{k_j} = a_{k_j} - d_j$$$. Note that at any time the speed of each carriage is non-negative. In other words, $$$a_i \ge s_i$$$, where $$$s_i$$$ —is the sum of such $$$d_j$$$ that $$$k_j=i$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$. Similarly, it is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$10^5$$$.

Print $$$t$$$ lines. On each line print the answer for the corresponding test case. For each test case print $$$m$$$ numbers: the number of trains formed after each message.

NoteFor the first test case:  Initially array $$$a = [6, 2, 3, 7]$$$.  After the first message, the array $$$a = [6, 2, 1, 7]$$$. Accordingly, the speeds of the carriages are $$$[6, 2, 1, 1]$$$ and will form $$$3$$$ of the train.  After the second message the array $$$a = [6, 2, 1, 0]$$$. Accordingly, the speeds of the carriages are $$$[6, 2, 1, 0]$$$, and $$$4$$$ of the train will be formed. For the second test case:  Initially, the array $$$a = [10, 13, 5, 2, 6]$$$.  After the first message, the array $$$a = [10, 9, 5, 2, 6]$$$. Accordingly, the speeds of the carriages are equal: $$$[10, 9, 5, 2, 2]$$$, and $$$4$$$ of the train will be formed.  After the second message the array $$$a = [10, 9, 5, 2, 4]$$$. Accordingly, the speeds of the carriages are $$$[10, 9, 5, 2, 2]$$$, and $$$4$$$ of the train will be formed.  After the third message the array $$$a = [5, 9, 5, 2, 4]$$$. Accordingly, the speeds of the carriages are $$$[5, 5, 5, 2, 2]$$$, and $$$2$$$ of the train will be formed.  After the fourth message the array $$$a = [5, 9, 3, 2, 4]$$$. Accordingly, the speeds of the carriages are $$$[5, 5, 3, 2, 2]$$$, and $$$3$$$ of the train will be formed.

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"
)

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