You are given $$$n$$$ of integers $$$a_1, a_2, \ldots, a_n$$$. Process $$$q$$$ queries of two types: query of the form "0 $$$x_j$$$": add the value $$$x_j$$$ to all even elements of the array $$$a$$$, query of the form "1 $$$x_j$$$": add the value $$$x_j$$$ to all odd elements of the array $$$a$$$.Note that when processing the query, we look specifically at the odd/even value of $$$a_i$$$, not its index.After processing each query, print the sum of the elements of the array $$$a$$$.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

The first line of the input contains an integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n$$$, $$$q \leq 10^5$$$) — the length of array $$$a$$$ and the number of queries. The second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. The following $$$q$$$ lines contain queries as two integers $$$type_j$$$ and $$$x_j$$$ $$$(0 \leq type_j \leq 1$$$, $$$1 \leq x_j \leq 10^4$$$). It is guaranteed that the sum of values $$$n$$$ over all test cases in a test does not exceed $$$10^5$$$. Similarly, the sum of values $$$q$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print $$$q$$$ numbers: the sum of the elements of the array $$$a$$$ after processing a query.

package main

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

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

func (in *CF1744B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1744B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**

Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}
		var buff strings.Builder
		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
		fmt.Print(buff.String())
	}

}

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

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

package main

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

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

func (in *CF1744B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1744B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**

Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	var buff strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
	}
	fmt.Print(buff.String())
}

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

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

package main

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

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

func (in *CF1744B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1744B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	var buff strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			arr[i] = val
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			buff.WriteString(fmt.Sprintf("%v\n", sum))
		}
	}
	fmt.Print(buff.String())
}

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

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

package main

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

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

func (in *CF1744B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1744B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1744B
Date: 10/22/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/B
Problem: CF1744B
**/
func (in *CF1744B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, q := in.NextInt(), in.NextInt()
		sum := int64(0)
		odd, even := 0, 0
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			val := in.NextInt64()
			arr[i] = val
			if val%2 == 0 {
				even++
			} else {
				odd++
			}
			sum += val
		}

		for i := 0; i < q; i++ {
			ty, val := in.NextInt(), in.NextInt64()
			if ty == 0 {
				sum += val * int64(even)
				if val%2 != 0 {
					odd += even
					even = 0
				}
			} else {
				sum += val * int64(odd)
				if val%2 != 0 {
					even += odd
					odd = 0
				}
			}
			fmt.Println(sum)
		}

	}
}

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

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

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,l,sum,o,e int
		fmt.Fscan(in,&n,&l)
		for j:=0;j<n;j++{
			var holder int
			fmt.Fscan(in,&holder)
			sum += holder
			if holder & 1 == 1 {
				o++
			} else {
				e++
			}
		}
		for j:=0;j<l;j++{
			var b,x int
			fmt.Fscan(in,&b,&x)
			if b == 1 { // going after all the odds
				sum += (o * x)
				if x & 1 == 1 { // odds + odds
					e += o
					o = 0
				}
			} else { // going after all the evens
				sum += (e * x)
				if x & 1 == 1 { // evens + odds
					o += e
					e = 0
				}
			}
			fmt.Fprintln(out,sum)
		}
	}
}
// take input -> if odd++ else, even++
// if b odd, if x odd : else if x even:

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.Replace(text, "\r\n", "", -1)
	t, _ := strconv.Atoi(text)
	for i := 0; i < t; i++ {
		text, _ = reader.ReadString('\n')
		text = strings.Replace(text, "\r\n", "", -1)
		n, _ := strconv.Atoi(strings.Split(text, " ")[1])

		text, _ := reader.ReadString('\n')
		text = strings.Replace(text, "\r\n", "", -1)
		rawArr := strings.Split(text, " ")
		evenCount := 0
		notEvenCount := 0
		evenIsEven := true
		notEvenIsEven := false
		evenSum := 0
		notEvenSum := 0
		for _, s := range rawArr {
			num, _ := strconv.Atoi(s)
			if num%2 == 0 {
				evenSum = evenSum + num
				evenCount++
			} else {
				notEvenSum = notEvenSum + num
				notEvenCount++
			}
		}
		for j := 0; j < n; j++ {
			text, _ = reader.ReadString('\n')
			text = strings.Replace(text, "\r\n", "", -1)
			val, _ := strconv.Atoi(strings.Split(text, " ")[1])
			if strings.Split(text, " ")[0] == "0" {
				if evenIsEven {
					evenSum = evenSum + val*evenCount
					if val%2 != 0 {
						evenIsEven = false
					}
				}
				if notEvenIsEven {
					notEvenSum = notEvenSum + val*notEvenCount
					if val%2 != 0 {
						notEvenIsEven = false
					}
				}
			} else {
				if !evenIsEven {
					evenSum = evenSum + val*evenCount
					if val%2 == 1 {
						evenIsEven = true
					}
				}
				if !notEvenIsEven {
					notEvenSum = notEvenSum + val*notEvenCount
					if val%2 == 1 {
						notEvenIsEven = true
					}
				}
			}
			fmt.Println(evenSum + notEvenSum)
		}
	}
}

func add(arr []int, even bool, val int) {
	for i := 0; i < len(arr); i++ {
		if even {
			if arr[i]%2 == 0 {
				arr[i] = arr[i] + val
			}
		} else {
			if arr[i]%2 != 0 {
				arr[i] = arr[i] + val
			}
		}
	}
}

func replaceAtIndex(in string, r rune, i int) string {
	out := []rune(in)
	out[i] = r
	return string(out)
}

func arrayToString(A []int, delim string) string {
	var buffer bytes.Buffer
	for i := 0; i < len(A); i++ {
		buffer.WriteString(strconv.Itoa(A[i]))
		if i != len(A)-1 {
			buffer.WriteString(delim)
		}
	}
	return buffer.String()
}

package main

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

var reader = bufio.NewReader(os.Stdin)

var n, m int

func solve(typ, x int) {
	if x%2 == 0 {
		// will not change the odd even
		if typ == 0 { // even
			sum += even * x
		} else {
			sum += odd * x
		}
	} else { // will change the odd even, x is odd number
		if typ == 0 { // operating even number
			sum += even * x
			odd += even
			even = 0
		} else { // operating odd number
			sum += odd * x
			even += odd
			odd = 0
		}
	}
	fmt.Println(sum)
}

var odd, even, sum int

func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		odd, sum, even = 0, 0, 0
		var q, n int
		fmt.Fscan(reader, &n, &q)
		a := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a)
			if (a % 2) == 0 {
				even++
			} else {
				odd++
			}
			sum += a
		}

		for i := 0; i < q; i++ {
			var q1, q2 int
			fmt.Fscan(reader, &q1, &q2)
			solve(q1, q2)
		}
	}
}

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

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

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

		var n, q int
		fmt.Fscan(reader, &n, &q)

		arr := make([]int, n)
		// queries := make([][]int, q)
		sum := 0
		evenCnt, oddCnt := 0, 0
		for i := 0; i < n; i++ {
			var e int
			fmt.Fscan(reader, &e)
			arr[i] = e
			sum += e

			if e%2 == 0 {
				evenCnt++
			} else {
				oddCnt++
			}
		}

		output := make([]int, q)
		for i := 0; i < q; i++ {
			var tp, value int

			// queries[i] = make([]int, 2)
			fmt.Fscan(reader, &tp, &value)
			// queries[i][0] = tp
			// queries[i][1] = value
			if tp == 0 {
				sum += evenCnt * value
				if value%2 != 0 {
					evenCnt = 0
					oddCnt = n
				}
			} else {
				sum += oddCnt * value
				if value%2 != 0 {
					oddCnt = 0
					evenCnt = n
				}
			}
			output[i] = sum
		}

		// output := solve(&arr, &queries, n, q)

		for _, v := range output {

			fmt.Fprintln(writer, v)
		}
	}
}

func solve(arr *[]int, queries *[][]int, n, q int) []int {
	sum := make([]int, q)

	for i := 0; i < q; i++ {
		tp := (*queries)[i][0]

		if tp == 0 {
			for j := 0; j < n; j++ {
				if (*arr)[j]%2 == 0 {
					(*arr)[j] += (*queries)[i][1]
				}
				sum[i] += (*arr)[j]
			}
		} else {
			for j := 0; j < n; j++ {
				if (*arr)[j]%2 != 0 {
					(*arr)[j] += (*queries)[i][1]
				}
				sum[i] += (*arr)[j]
			}
		}
	}

	return sum
}

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n, q int
    scan(&n, &q)
    a := make([]int, n, n)
    var sum, o, e int
    for i := range a {
      scan(&a[i])
      if a[i] % 2 == 0 {
        e++
      } else {
        o++
      }
      sum += a[i]
    }
    for i := 0; i < q; i ++ {
      var t, x int
      scan(&t, &x)
      if t == 0 {
        sum += x * e
      } else {
        sum += x * o
      }
      pf("%d\n", sum)
      switch {
        case x % 2 == 1 && t == 0:
          o += e
          e = 0
        case x % 2 == 1 && t == 1:
          e += o
          o = 0
      }
    }
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }

package main

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

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

func sum(nums []int) (int, int, int) {
  sum := 0
  even := 0
  for i := 0; i < len(nums); i++ {
    if nums[i] % 2 == 0 {
      even++
    }
    sum += nums[i]
  }

  return sum, even, len(nums) - even
}

func main() {
  writer.Flush()
  var test int
  fmt.Fscanf(reader, "%d\n", &test)

  for test > 0 {
    var n, q int
    fmt.Fscanf(reader, "%d %d\n", &n, &q)
    nums := make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Fscanf(reader, "%d",&nums[i])
    }

    initSum, even, odd := sum(nums)

    fmt.Fscanf(reader, "\n")
    for i := 0; i < q; i++ {
      var x, val int
      fmt.Fscanf(reader, "%d %d\n", &x, &val)
      if x == 1 {
        initSum += odd * val
        if val % 2 == 1 {
          even += odd
          odd = 0
        }
      } else {
        initSum += even *val
        if val % 2 == 1 {
          odd += even
          even = 0
        }
      }

      fmt.Println(initSum)
    }
    test--
  }
}

package main

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

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

	var T int

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

		a := make([]int, n)

		var evenSum, oddSum, evenCount, oddCount int64

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])

			if a[i]%2 == 0 {
				evenCount++
				evenSum += int64(a[i])
			} else {
				oddCount++
				oddSum += int64(a[i])
			}
		}

		for i := 1; i <= q; i++ {
			var x, y int
			fmt.Fscan(r, &x, &y)

			if x == 0 {
				if y%2 == 0 {
					evenSum += evenCount * int64(y)
				} else {
					oddSum += evenSum + evenCount*int64(y)
					oddCount += evenCount
					evenCount = 0
					evenSum = 0
				}
			} else { //Add to odd numbers
				if y%2 == 0 {
					oddSum += oddCount * int64(y)
				} else {
					evenSum += oddSum + oddCount*int64(y)
					evenCount += oddCount
					oddCount = 0
					oddSum = 0
				}
			}

			fmt.Fprintln(w, oddSum+evenSum)
		}
	}
}

package main

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

const (
	N = 1e5 + 10
)

var (
	t, n, q, op       int
	x, ans, even, odd int64
	a                 []int64
)

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

	fmt.Fscan(r, &t)
	a = make([]int64, N)
	for ; t != 0; t-- {
		fmt.Fscan(r, &n, &q)
		even, odd, ans = 0, 0, 0
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
			ans += a[i]
			if a[i]%2 == 0 {
				even++
			} else {
				odd++
			}
		}
		for i := 0; i < q; i++ {
			fmt.Fscan(r, &op, &x)
			if op == 0 {
				ans += x * even
				if x%2 == 1 {
					odd += even
					even = 0
				}
			} else {
				ans += x * odd
				if x%2 == 1 {
					even += odd
					odd = 0
				}
			}
			fmt.Fprintln(w, ans)
		}

	}
}

package main

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

func trim(s string) string {
	return s[:len(s)-2]
}

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

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

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func checkNumberPowerOfTwo(n int) int {
	return n & (n - 1)
}

func sliceStr2Int(arr []string) []int {
	var arrInt []int
	for _, i := range arr {
		num, _ := strconv.Atoi(i)
		arrInt = append(arrInt, num)
	}

	return arrInt
}

func sliceIntFromConsole() []int {
	arrLine, _ := reader.ReadString('\n')
	return sliceStr2Int(strings.Split(trim(arrLine), " "))
}

func numberFromConsole() int {
	numberLine, _ := reader.ReadString('\n')
	number, _ := strconv.Atoi(trim(numberLine))
	return number
}

var reader = bufio.NewReader(os.Stdin)

func main() {
	test := numberFromConsole()
	for t := 0; t < test; t++ {
		nq := sliceIntFromConsole()
		q := nq[1]

		a := sliceIntFromConsole()
		var sum int
		nums := make([]int, 2)
		// first element -- amount of even numbers in a slice
		// second element -- amount of odd numbers in a slice

		for _, v := range a {
			sum += v
			nums[v%2]++
		}

		for request := 0; request < q; request++ {
			req := sliceIntFromConsole()
			sum += nums[req[0]] * req[1]
			fmt.Println(sum)

			if req[1]%2 == 1 {
				nums[abs(req[0]-1)] += nums[req[0]]
				nums[req[0]] = 0
			}
		}
	}
}

package main

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

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

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

		var n, q, evens, odds, res int
		fmt.Fscan(r, &n, &q)

		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(r, &a)
			odds += a%2
			res += a
		}
		evens = n - odds

		for i := 0; i < q; i++ {
			var t, x int
			fmt.Fscan(r, &t, &x)

			if t == 0 {
				res += evens*x
				if x % 2 == 1 {
					evens = 0
					odds = n
				}
			} else {
				res += odds*x
				if x % 2 == 1 {
					odds = 0
					evens = n
				}
			}

			fmt.Fprintln(w, res)
		}
	}

}

package main

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

func solution_1(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr int
		_, err := fmt.Fscanf(in, "%d\n", &narr)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")
		var s string
		_, err = fmt.Fscanf(in, "%s\n", &s)
		fmt.Fprintln(output, numberReplacement(arr, s))
	}
}

func solution_2(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr, q int
		_, err := fmt.Fscanf(in, "%d %d\n", &narr, &q)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")

		nOdd := 0
		nEven := 0
		sum := 0

		for _, n := range arr {
			sum += n
			if n%2 == 0 {
				nEven++
			} else {
				nOdd++
			}
		}
		for j := 0; j < q; j++ {
			var a, b int
			fmt.Fscanf(in, "%d %d\n", &a, &b)
			if a == 0 {
				sum += nEven * b
				if b%2 != 0 {
					nOdd += nEven
					nEven = 0
				}
			}

			if a == 1 {
				sum += nOdd * b
				if b%2 != 0 {
					nEven += nOdd
					nOdd = 0
				}
			}
			fmt.Fprintln(output, sum)
		}

	}
}

func numberReplacement(arr []int, s string) string {
	if len(arr) != len(s) {
		return "NO"
	}

	someMap := make(map[int]byte)
	for i, n := range arr {
		if v, ok := someMap[n]; !ok {
			someMap[n] = s[i]
		} else {
			if v != s[i] {
				return "NO"
			}
		}
	}

	return "YES"
}

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

package main

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

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

//func solve() {
//	var v0, v1 = make([]int, 0), make([]int, 0)
//	n, q := _readInt(), _readInt()
//	for i := 0; i < n; i++ {
//		x := _readInt()
//		if x%2 == 0 {
//			v0 = append(v0, x)
//		} else {
//			v1 = append(v1, x)
//		}
//	}
//
//	for i := 0; i < q; i++ {
//		var tar, dest []int
//		t, x := _readInt(), _readInt()
//		if t == 0 {
//			tar, dest = v0, v1
//		} else {
//			tar, dest = v1, v0
//		}
//
//		for j := range tar {
//			tar[j] += x
//		}
//	}
//
//}

func solve() {
	n, q := _readInt(), _readInt()
	var s0, n0, s1, n1 int64
	var res int64

	for i := 0; i < n; i++ {
		x := int64(_readInt())
		if x%2 == 0 {
			n0++
			s0 += x
		} else {
			n1++
			s1 += x
		}
		res += x
	}

	for i := 0; i < q; i++ {
		t, x := _readInt(), int64(_readInt())
		if t == 0 {
			res += n0 * x
		} else {
			res += n1 * x
		}
		if x%2 != 0 {
			if t == 0 {
				n1 += n0
				n0 = 0
			} else {
				n0 += n1
				n1 = 0
			}
		}
		_print(res)
	}

}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr() (int, []int) {
	var n int
	fmt.Fscan(in, &n)
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func _min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}

package main

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

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

func solve() {
    var n, q int
    Fscan(in, &n, &q)

    var sum int = 0
    even := 0
    odd := 0
    a := make([]int, n)
    for i := 0; i < n; i++ {
        Fscan(in, &a[i])
        sum += a[i]
        if a[i] % 2 == 1 {
            odd++
        } else {
            even++
        }
    }

    for ; q > 0; q-- {
        var op, x int
        Fscan(in, &op, &x)

        if op == 1 {
            sum += x * odd

            if x % 2 == 1 {
                even = n
                odd = 0
            }
        } else {
            sum += x * even

            if x % 2 == 1 {
                odd = n
                even = 0
            }
        }

        Fprintln(out, sum)
    }
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

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

		var sum int64
		var e, o int
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			sum += v
			if v%2 == 0 {
				e++
			} else {
				o++
			}
		}

		for i := 0; i < q; i++ {
			var d, x int64
			fmt.Fscan(in, &d, &x)
			if d == 0 {
				sum += int64(e) * x
				if x%2 != 0 {
					o += e
					e = 0
				}
			} else {
				sum += int64(o) * x
				if x%2 != 0 {
					e += o
					o = 0
				}
			}
			fmt.Fprintln(out, sum)
		}
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n, q := nextInt(), nextInt()
		a := make([]int, n)
		sum := int64(0)
		odd, even := int64(0), int64(0)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
			sum += int64(a[i])
			if a[i]%2 == 0 {
				even++
			}
		}
		odd = int64(n) - even
		for q > 0 {
			q--
			t, x := nextInt(), nextInt()
			if t == 0 {
				sum += even * int64(x)
				if x%2 == 1 {
					odd += even
					even = 0
				}
			} else {
				sum += odd * int64(x)
				if x%2 == 1 {
					even += odd
					odd = 0
				}
			}
			fmt.Println(sum)
		}
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

package main

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

const cf = true

func solve() {
	var n, q int
	fmt.Fscan(in, &n, &q)
	even, odd := 0, 0
	evenCnt, oddCnt := 0, 0
	var num int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		if num%2 == 0 {
			even += num
			evenCnt++
		} else {
			odd += num
			oddCnt++
		}
	}
	var tp, val int
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &tp, &val)
		if tp == 0 {
			even += evenCnt * val
			if val%2 == 1 {
				odd += even
				even = 0
				oddCnt += evenCnt
				evenCnt = 0
			}
		} else {
			odd += oddCnt * val
			if val%2 == 1 {
				even += odd
				odd = 0
				evenCnt += oddCnt
				oddCnt = 0
			}
		}
		fmt.Fprintln(out, even+odd)
	}
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n, q int
    scan(&n, &q)
    a := make([]int, n, n)
    var sum, o, e int
    for i := range a {
      scan(&a[i])
      if a[i] % 2 == 0 {
        e++
      } else {
        o++
      }
      sum += a[i]
    }
    for i := 0; i < q; i ++ {
      var t, x int
      scan(&t, &x)
      if t == 0 {
        sum += x * e
      } else {
        sum += x * o
      }
      pf("Test #%d: %d\n", T, sum)
      switch {
        case x % 2 == 1 && t == 0:
          o += e
          e = 0
        case x % 2 == 1 && t == 1:
          e += o
          o = 0
      }
    }
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }


The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns in the table. Each cell of the table contains a haystack. The height in meters of the hay located in the i-th row and the j-th column is equal to an integer ai, j and coincides with the number of cubic meters of hay in the haystack, because all cells have the size of the base 1 × 1. Polycarp has decided to tidy up in the warehouse by removing an arbitrary integer amount of cubic meters of hay from the top of each stack. You can take different amounts of hay from different haystacks. Besides, it is allowed not to touch a stack at all, or, on the contrary, to remove it completely. If a stack is completely removed, the corresponding cell becomes empty and no longer contains the stack.Polycarp wants the following requirements to hold after the reorganization:  the total amount of hay remaining in the warehouse must be equal to k,  the heights of all stacks (i.e., cells containing a non-zero amount of hay) should be the same,  the height of at least one stack must remain the same as it was,  for the stability of the remaining structure all the stacks should form one connected region. The two stacks are considered adjacent if they share a side in the table. The area is called connected if from any of the stack in the area you can get to any other stack in this area, moving only to adjacent stacks. In this case two adjacent stacks necessarily belong to the same area.Help Polycarp complete this challenging task or inform that it is impossible.

The first line of the input contains three integers n, m (1 ≤ n, m ≤ 1000) and k (1 ≤ k ≤ 1018) — the number of rows and columns of the rectangular table where heaps of hay are lain and the required total number cubic meters of hay after the reorganization.  Then n lines follow, each containing m positive integers ai, j (1 ≤ ai, j ≤ 109), where ai, j is equal to the number of cubic meters of hay making the hay stack on the i-th row and j-th column of the table.

In the first line print "YES" (without quotes), if Polycarpus can perform the reorganisation and "NO" (without quotes) otherwise. If the answer is "YES" (without quotes), then in next n lines print m numbers — the heights of the remaining hay stacks. All the remaining non-zero values should be equal, represent a connected area and at least one of these values shouldn't be altered. If there are multiple answers, print any of them.

NoteIn the first sample non-zero values make up a connected area, their values do not exceed the initial heights of hay stacks. All the non-zero values equal 7, and their number is 5, so the total volume of the remaining hay equals the required value k = 7·5 = 35. At that the stack that is on the second line and third row remained unaltered.

// Codeforces 659 F graphs
package main

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

var n,m int
var k int64
var di = [4]int{0,1,0,-1}
var dj = [4]int{1,0,-1,0}
var a = [][]int64{}
var g = [][]int{}

// find group elements using dfs
func clearGroups() {
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            g[i][j] = 0
        }
    }
}
func fillGroupLim(gr int, i,j int, kk int64, lim int) int64 {
    //fmt.Println("fillGroupLim gr,i,j,kk,lim=", gr,i,j,kk,lim)
    if lim==0 {
        return 0
    }
    g[i][j] = gr
    cnt := int64(1)
    lim--
    for d:=0; d<4; d++ {
        ii := i + di[d]
        jj := j + dj[d]
        if ii>=0 && ii<n && jj>=0 && jj<m && g[ii][jj]==0 && a[ii][jj]>=kk {
            c := fillGroupLim(gr,ii,jj, kk, lim)
            cnt += c
            lim -= int(c)
        }
    }
    return cnt
}

func attempt(kk int64) (bool, int, int) {
    //fmt.Printf("attempt kk= %d\n", kk)
    mine := k / kk;
    clearGroups()
    gg := 1
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            //fmt.Println("loop,aij,kk=",a[i][j],kk)
            if g[i][j]==0 && a[i][j]==kk {
                cnt := fillGroupLim(gg,i,j,kk, n*m)
                if cnt >= mine {
                    return true,i,j
                }
                gg++
            }
        }
    }
    // counting groups
    return false,0,0
}

func fillA(kk int64,i,j int) {
    nk := int(k / kk)
    clearGroups()
    fillGroupLim(1,i,j,kk,nk)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            if g[i][j] == 1 {
                a[i][j] = kk
            } else {
                a[i][j] = 0
            }
        }
    }
}

func main() {
	// reading n,m,k
 	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
	m, err = strconv.Atoi(ss[1])
	if err != nil {
		fmt.Println("m atoi failure", err)
		return
	}
	k, err = strconv.ParseInt(ss[2], 10, 64)
	if err != nil {
		fmt.Println("k atoi failure", err)
		return
	}
    // reading a
    for i:=0; i<n; i++ {
        a = append(a, make([]int64, m))
        g = append(g, make([]int, m))
        s, err = in.ReadString('\n')
        if err != nil {
            fmt.Println("read failure", err)
            return
        }
        ss = strings.Split(strings.Trim(s, " \n\r"), " ")
        for j:=0; j<m; j++ {
            aa,err := strconv.ParseInt(ss[j], 10, 64)
            if err != nil {
                fmt.Println("aa conv failed", err)
                return
            }
            a[i][j] = aa
        }
    }
    // loking for suitable dividers
    divs := make(map[int64] bool)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            aa := a[i][j]
            if k%aa==0 {
                divs[aa] = true
                //fmt.Println("added to divs", aa)
            }
        }
    }

    // checking
    canDo := false
    kkk:=int64(0)
    for kk := range(divs) {
        ok,i,j := attempt(kk)
        if ok {
            fillA(kk, i, j)
            kkk = kk
            canDo = true
            break
        }
    }
    // print result
    if canDo {
        fmt.Println("YES")
        s0 := "0"
        skk := strconv.FormatInt(int64(kkk),10)
        for i:=0; i<n; i++ {
            var buf bytes.Buffer
            for j:=0; j<m; j++ {
                if a[i][j] == 0 {
                    buf.WriteString(s0)
                } else {
                    buf.WriteString(skk)
                }
                 if j<m-1 {
                    buf.WriteString(" ")
                }
            }
            fmt.Println(buf.String())
        }
    } else {
        fmt.Println("NO")
    }
}

// Codeforces 659 F graphs
package main

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

var n,m int
var k int64
var di = [4]int{0,1,0,-1}
var dj = [4]int{1,0,-1,0}
var a = [][]int64{}
var g = [][]int{}

// find group elements using dfs
func clearGroups() {
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            g[i][j] = 0
        }
    }
}
func fillGroupLim(gr int, i,j int, kk int64, lim int) int {
    //fmt.Println("fillGroupLim gr,i,j,kk,lim=", gr,i,j,kk,lim)
    if lim==0 {
        return 0
    }
    g[i][j] = gr
    cnt := 1
    for d:=0; d<4; d++ {
        ii := i + di[d]
        jj := j + dj[d]
        if ii>=0 && ii<n && jj>=0 && jj<m && g[ii][jj]==0 && a[ii][jj]>=kk {
            lim--
            cnt += fillGroupLim(gr,ii,jj, kk, lim)
        }
    }
    return cnt
}

func attempt(kk int64) (bool, int, int) {
    //fmt.Printf("attempt kk= %d\n", kk)
    mine := int(k / kk);
    clearGroups()
    gg := 1
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            //fmt.Println("loop,aij,kk=",a[i][j],kk)
            if g[i][j]==0 && a[i][j]==kk {
                cnt := fillGroupLim(gg,i,j,kk, n*m)
                if cnt >= mine {
                    return true,i,j
                }
                gg++
            }
        }
    }
    // counting groups
    return false,0,0
}

func fillA(kk int64,i,j int) {
    nk := int(k / kk)
    clearGroups()
    fillGroupLim(1,i,j,kk,nk)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            if g[i][j] == 1 {
                a[i][j] = kk
            } else {
                a[i][j] = 0
            }
        }
    }
}

func main() {
	// reading n,m,k
 	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
	m, err = strconv.Atoi(ss[1])
	if err != nil {
		fmt.Println("m atoi failure", err)
		return
	}
	k, err = strconv.ParseInt(ss[2], 10, 64)
	if err != nil {
		fmt.Println("k atoi failure", err)
		return
	}
    // reading a
    for i:=0; i<n; i++ {
        a = append(a, make([]int64, m))
        g = append(g, make([]int, m))
        s, err = in.ReadString('\n')
        if err != nil {
            fmt.Println("read failure", err)
            return
        }
        ss = strings.Split(strings.Trim(s, " \n\r"), " ")
        for j:=0; j<m; j++ {
            aa,err := strconv.ParseInt(ss[j], 10, 64)
            if err != nil {
                fmt.Println("aa conv failed", err)
                return
            }
            a[i][j] = aa
        }
    }
    // loking for suitable dividers
    divs := make(map[int64] bool)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            aa := a[i][j]
            if k%aa==0 {
                divs[aa] = true
                //fmt.Println("added to divs", aa)
            }
        }
    }

    // checking
    canDo := false
    kkk:=int64(0)
    for kk := range(divs) {
        ok,i,j := attempt(kk)
        if ok {
            fillA(kk, i, j)
            kkk = kk
            canDo = true
            break
        }
    }
    // print result
    if canDo {
        fmt.Println("YES")
        s0 := "0"
        skk := strconv.FormatInt(int64(kkk),10)
        for i:=0; i<n; i++ {
            var buf bytes.Buffer
            for j:=0; j<m; j++ {
                if a[i][j] == 0 {
                    buf.WriteString(s0)
                } else {
                    buf.WriteString(skk)
                }
                 if j<m-1 {
                    buf.WriteString(" ")
                }
            }
            fmt.Println(buf.String())
        }
    } else {
        fmt.Println("NO")
    }
}

// Codeforces 659 F graphs
package main

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

var n,m,k int
var di = [4]int{0,1,0,-1}
var dj = [4]int{1,0,-1,0}
var a = [][]int{}
var g = [][]int{}

// find group elements using dfs
func clearGroups() {
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            g[i][j] = 0
        }
    }
}
func fillGroupLim(gr int, i,j,kk,lim int) int {
    //fmt.Println("fillGroupLim gr,i,j,kk,lim=", gr,i,j,kk,lim)
    if lim==0 {
        return 0
    }
    g[i][j] = gr
    cnt := 1
    for d:=0; d<4; d++ {
        ii := i + di[d]
        jj := j + dj[d]
        if ii>=0 && ii<n && jj>=0 && jj<m && g[ii][jj]==0 && a[ii][jj]>=kk {
            lim--
            cnt += fillGroupLim(gr,ii,jj, kk, lim)
        }
    }
    return cnt
}

func attempt(kk int) (bool, int, int) {
    //fmt.Printf("attempt kk= %d\n", kk)
    mine := k / kk;
    clearGroups()
    gg := 1
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            //fmt.Println("loop,aij,kk=",a[i][j],kk)
            if g[i][j]==0 && a[i][j]==kk {
                cnt := fillGroupLim(gg,i,j,kk, n*m)
                if cnt >= mine {
                    return true,i,j
                }
                gg++
            }
        }
    }
    // counting groups
    return false,0,0
}

func fillA(kk,i,j int) {
    nk := k / kk
    clearGroups()
    fillGroupLim(1,i,j,kk,nk)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            if g[i][j] == 1 {
                a[i][j] = kk
            } else {
                a[i][j] = 0
            }
        }
    }
}

func main() {
	// reading n,m,k
 	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
	m, err = strconv.Atoi(ss[1])
	if err != nil {
		fmt.Println("m atoi failure", err)
		return
	}
	k, err = strconv.Atoi(ss[2])
	if err != nil {
		fmt.Println("k atoi failure", err)
		return
	}
    // reading a
    for i:=0; i<n; i++ {
        a = append(a, make([]int, m))
        g = append(g, make([]int, m))
        s, err = in.ReadString('\n')
        if err != nil {
            fmt.Println("read failure", err)
            return
        }
        ss = strings.Split(strings.Trim(s, " \n\r"), " ")
        for j:=0; j<m; j++ {
            aa,err := strconv.Atoi(ss[j])
            if err != nil {
                fmt.Println("aa conv failed", err)
                return
            }
            a[i][j] = aa
        }
    }
    // loking for suitable dividers
    divs := make(map[int] bool)
    for i:=0; i<n; i++ {
        for j:=0; j<m; j++ {
            aa := a[i][j]
            if k%aa==0 {
                divs[aa] = true
                //fmt.Println("added to divs", aa)
            }
        }
    }

    // checking
    canDo := false
    kkk:=0
    for kk := range(divs) {
        ok,i,j := attempt(kk)
        if ok {
            fillA(kk, i, j)
            kkk = kk
            canDo = true
            break
        }
    }
    // print result
    if canDo {
        fmt.Println("YES")
        s0 := "0"
        skk := strconv.FormatInt(int64(kkk),10)
        for i:=0; i<n; i++ {
            var buf bytes.Buffer
            for j:=0; j<m; j++ {
                if a[i][j] == 0 {
                    buf.WriteString(s0)
                } else {
                    buf.WriteString(skk)
                }
                 if j<m-1 {
                    buf.WriteString(" ")
                }
            }
            fmt.Println(buf.String())
        }
    } else {
        fmt.Println("NO")
    }
}