← Home
package main

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

const MOD int64 = 998244353
const MAXN = 1000000

type FastScanner struct {
	r *bufio.Reader
}

func NewFastScanner() *FastScanner {
	return &FastScanner{r: bufio.NewReaderSize(os.Stdin, 1<<20)}
}

func (fs *FastScanner) NextInt() int {
	sign, val := 1, 0
	c, err := fs.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, err = fs.r.ReadByte()
		if err != nil {
			return 0
		}
	}
	if c == '-' {
		sign = -1
		c, _ = fs.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int(c-'0')
		c, err = fs.r.ReadByte()
		if err != nil {
			break
		}
	}
	if err == nil {
		_ = fs.r.UnreadByte()
	}
	return sign * val
}

func main() {
	fs := NewFastScanner()

	fact := make([]int64, MAXN+1)
	fact[0] = 1
	for i := 1; i <= MAXN; i++ {
		fact[i] = fact[i-1] * int64(i) % MOD
	}

	t := fs.NextInt()
	var out bytes.Buffer

	for ; t > 0; t-- {
		n := fs.NextInt()
		k := fs.NextInt()
		m := n - k

		ans := fact[k]
		ok := true

		for i := 1; i <= n; i++ {
			x := fs.NextInt()
			if i <= m {
				if x == -1 {
					ans = ans * int64(i+k) % MOD
				} else if x == 0 {
					ans = ans * int64(k+1) % MOD
				} else if x > 0 && x <= i-1 {
				} else {
					ok = false
				}
			} else {
				if x == -1 || x == 0 {
				} else {
					ok = false
				}
			}
		}

		if !ok {
			ans = 0
		}
		out.WriteString(int64ToString(ans))
		out.WriteByte('\n')
	}

	os.Stdout.Write(out.Bytes())
}

func int64ToString(x int64) string {
	if x == 0 {
		return "0"
	}
	var buf [32]byte
	i := len(buf)
	for x > 0 {
		i--
		buf[i] = byte('0' + x%10)
		x /= 10
	}
	return string(buf[i:])
}