package main

import "fmt"

func main() {
    var n,k int
    var s string
    fmt.Scan(&n,&k)
    ans := 0
    for i := 0; i < n; i++ {
        fmt.Scan(&s)
        digit, ok := [10]bool{}, true
        for _, v := range s { digit[v-'0'] = true }
        for i := 0; i <= k; i++ {
            if !digit[i] { ok = false; break }
        }
        if ok { ans++ }
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	var c [10]int

	fmt.Scan(&n,&k)
	t:=0
	for i:=0;i<n;i++ {
		fmt.Scan(&s)
		b:=1
		for j:=0;j<10;j++ {
			c[j]=0
		}
		for k:=0;k<len(s);k++ {
			c[s[k]-'0']=1
		}
		for j:=0;j<=k;j++ {
			if c[j]==0 {
				b=0
				break
			}
		}
		t+=b
	}
	fmt.Println(t)
}

// http://codeforces.com/problemset/problem/365/A
// A. Good Number

package main

import (
	"fmt"
)

var (
	frek [11]byte
)

func isGood(x string, k int32) bool {
	var i int32
	for i = 0; i < 10; i++ {
		frek[i] = 0
	}
	for _, xi := range x {
		frek[xi-'0']++
	}
	for i = 0; frek[i] > 0; i++ {
	}
	return i > k
}

func main() {
	var (
		n, k, ng, i int32
		x           string
	)

	fmt.Scan(&n)
	fmt.Scan(&k)
	for i = 0; i < n; i++ {
		fmt.Scan(&x)
		if isGood(x, k) {
			ng++
		}
	}
	fmt.Println(ng)

}

package main

import (
    "fmt"
)

func is_k(v, k int) bool {
    var has [11]int
    for ;; {
        var idx int
        idx = v % 10
        v /= 10
        //if idx > k { return false}
        has[idx] = 1
        if (v == 0) { break }

    }

    for i := 0; i <= k;i++ {
        if (has[i] == 0) { return false }
    }
    return true
}

func main() {
    var n, k, ans int
    fmt.Scan(&n, &k)

    for i := 0; i < n;i++ {
        var v int
        fmt.Scan(&v)

        if is_k(v, k) { ans++ }
    }

    fmt.Printf("%d\n", ans)
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

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

func next() string { sc.Scan(); return sc.Text() }

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

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

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, k := ni32(), uint(ni32())
	ans := 0
	goodmask := int(1<<(k+1) - 1)

	good := func(n int) bool {
		mask := 0
		for ; n > 0; n /= 10 {
			mask |= 1 << uint(n%10)
		}
		return mask&goodmask == goodmask
	}

	for i := 0; i < n; i++ {
		if good(ni32()) {
			ans++
		}
	}
	pri32(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	var c [10]int

	fmt.Scan(&n,&k)
	t:=0
	for i:=0;i<n;i++ {
		fmt.Scan(&s)
		b:=1
		for j:=0;j<10;j++ {
			c[j]=0
		}
		for k,_ =range s {
			c[s[k]-'0']=1
		}
		for j:=0;j<=k;j++ {
			if c[j]==0 {
				b=0
				break
			}
		}
		t+=b
	}
	fmt.Println(t)
}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	var c [10]int

	fmt.Scan(&n,&k)
	t:=0
	for i:=0;i<n;i++ {
		fmt.Scan(&s)
		b:=1
		for j:=0;j<10;j++ {
			c[j]=0
		}
		for k,_ =range s {
			c[s[k]-'0']=1
		}
		for j:=0;j<=k;j++ {
			if c[j]!=0 {
				b=0
				break
			}
		}
		t+=b
	}
	fmt.Println(t)
}

package main

import (
    "fmt"
)

func is_k(v, k int) bool {
    var has [11]int
    for ;; {
        var idx int
        idx = v % 10
        v /= 10
        if idx > k { return false}
        has[idx] = 1
        if (v == 0) { break }

    }

    for i := 0; i <= k;i++ {
        if (has[i] == 0) { return false }
    }
    return true
}

func main() {
    var n, k, ans int
    fmt.Scan(&n, &k)

    for i := 0; i < n;i++ {
        var v int
        fmt.Scan(&v)

        if is_k(v, k) { ans++ }
    }

    fmt.Printf("%d\n", ans)
}

package main

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

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

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

func next() string { sc.Scan(); return sc.Text() }

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

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

func pri32(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		sp()
	}
}
func pri64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		sp()
	}
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()
	n, k := ni32(), uint(ni32())
	ans := 0
	goodmask := int(1<<(k+1) - 1)

	good := func(n int) bool {
		mask := 0
		for ; n > 0; n /= 10 {
			mask |= 1 << uint(n%10)
		}
		return mask == goodmask
	}

	for i := 0; i < n; i++ {
		if good(ni32()) {
			ans++
		}
	}
	pri32(ans)
}


package main

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

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	var x string
	fmt.Scan(&x)
	s := []byte(x)
	n := len(s)
	i := 0
	for (i < n) && (s[i] == 'a') {
		i++
	}
	if i >= n {
		s[i-1] = 'z'
	} else {
		for (i < n) && (s[i] != 'a') {
			s[i]--
			i++
		}
	}
	r := string(s)
	fmt.Print(r)
}

// Heap
type Node struct {
	name  int
	value int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

// Int64Slice Sort
type Int64Slice []int64

func (s Int64Slice) Len() int               { return len(s) }
func (s Int64Slice) Less(i int, j int) bool { return s[i] < s[j] }
func (s Int64Slice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

// Input and Output
var in *bufio.Scanner
var out *bufio.Writer

func readString() string {
	in.Scan()
	return in.Text()
}

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

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

func readFloat64() float64 {
	in.Scan()
	val, _ := strconv.ParseFloat(in.Text(), 64)
	return val
}

func write(args ...interface{}) {
	for i, e := range args {
		switch e.(type) {
		case string:
			out.WriteString(e.(string))
		case int:
			out.WriteString(strconv.Itoa(e.(int)))
		case int64:
			out.WriteString(strconv.FormatInt(e.(int64), 10))
		case float64:
			out.WriteString(strconv.FormatFloat(e.(float64), 'f', -1, 64))
		case []string:
			a := e.([]string)
			for j, x := range a {
				out.WriteString(x)
				if j+1 < len(a) {
					out.WriteByte(' ')
				}
			}
		case []int:
			a := e.([]int)
			for j, x := range a {
				out.WriteString(strconv.Itoa(x))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []int64:
			a := e.([]int64)
			for j, x := range a {
				out.WriteString(strconv.FormatInt(x, 10))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		case []float64:
			a := e.([]float64)
			for j, x := range a {
				out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
				if j+1 < len(a) {
					out.WriteByte(' ')
				}

			}
		default:
			out.WriteString("###")
		}
		if i+1 < len(args) {
			out.WriteByte(' ')
		}
	}
	out.WriteByte('\n')
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)

	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		start := false
		stop := false

		for i := 0; i < len(s); i++ {
			if !start && i == len(s)-1 {
				p := s[i] - 1
				if p < 'a' {
					p = 'z'
				}
				fmt.Printf("%c", p)
				break
			}
			if stop {
				fmt.Printf("%c", s[i])
				continue
			}
			p := s[i] - 1
			if p < 'a' {
				p = s[i]
				if start {
					stop = true
				}
			} else {
				start = true
			}
			fmt.Printf("%c", p)
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
)

func main() {
	defer out.Flush()

	var x string
	read(&x)

	s := []byte(x)
	n := len(s)

	i := 0
	for (i < n) && (s[i] == 'a') {
		i++
	}

	if i >= n {
		s[i-1] = 'z'
	} else {
		for (i < n) && (s[i] != 'a') {
			s[i]--
			i++
		}
	}

	r := string(s)
	writeln(r)
}

// Heap
type Node struct {
	name  int
	value int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

// Sort
type Int64Slice []int64

func (s Int64Slice) Len() int               { return len(s) }
func (s Int64Slice) Less(i int, j int) bool { return s[i] < s[j] }
func (s Int64Slice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

// Input output
var out *bufio.Writer
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isLine(c byte) bool {
	return (c == '\n') || (c == '\r')
}

func isSpace(c byte) bool {
	return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r')
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readByte(v *byte) bool {
	if iPointer >= nPointer {
		return false
	}
	*v = iBuffer[iPointer]
	iPointer++
	return true
}

func readString(v *string) bool {
	for (iPointer < nPointer) && isSpace(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isSpace(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	return true
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readInt64(v *int64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int64
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int64(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readFloat64(v *float64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		if iBuffer[iPointer] != '.' {
			neg = (iBuffer[iPointer] == '-')
		}
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	if neg {
		a = append(a, '-')
	}
	if iPointer > 0 && iBuffer[iPointer-1] == '.' {
		a = append(a, '.')
	} else {
		for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
		if (iPointer < nPointer) && (iBuffer[iPointer] == '.') {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
	}
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	var ok error
	*v, ok = strconv.ParseFloat(string(a), 64)
	return ok == nil
}

func readln(v *string) bool {
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isLine(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	return true
}

func read(arg interface{}) bool {
	switch v := arg.(type) {
	case *byte:
		return readByte(v)
	case *string:
		return readString(v)
	case *int:
		return readInt(v)
	case *int64:
		return readInt64(v)
	case *float64:
		return readFloat64(v)
	default:
		return false
	}
}

func writeBool(v bool) {
	if v {
		out.WriteString("true")
	} else {
		out.WriteString("false")
	}
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeString(v string) {
	out.WriteString(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}

func writeInt64(v int64) {
	out.WriteString(strconv.FormatInt(v, 10))
}

func writeFloat64(v float64) {
	out.WriteString(strconv.FormatFloat(v, 'f', -1, 64))
}

func writeln(args ...interface{}) {
	write(args...)
	out.WriteByte('\n')
}

func write(args ...interface{}) {
	for _, a := range args {
		switch v := a.(type) {
		case bool:
			writeBool(v)
		case byte:
			writeByte(v)
		case rune:
			writeByte(byte(v))
		case string:
			writeString(v)
		case int:
			writeInt(v)
		case int64:
			writeInt64(v)
		case float64:
			writeFloat64(v)
		default:
			out.WriteString("###")
		}
	}
}

package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
	"time"
)

func main() {
	defer out.Flush()
	defer writeln(">>> " + time.Since(startTime).String())

	var x string
	read(&x)

	s := []byte(x)
	n := len(s)

	i := 0
	for (i < n) && (s[i] == 'a') {
		i++
	}

	if i >= n {
		s[i-1] = 'z'
	} else {
		for (i < n) && (s[i] != 'a') {
			s[i]--
			i++
		}
	}

	r := string(s)
	writeln(r)
}

// Heap
type Node struct {
	name  int
	value int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

// Sort
type Int64Slice []int64

func (s Int64Slice) Len() int               { return len(s) }
func (s Int64Slice) Less(i int, j int) bool { return s[i] < s[j] }
func (s Int64Slice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

// Input output
var out *bufio.Writer
var startTime time.Time
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	startTime = time.Now()
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isLine(c byte) bool {
	return (c == '\n') || (c == '\r')
}

func isSpace(c byte) bool {
	return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r')
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readByte(v *byte) bool {
	if iPointer >= nPointer {
		return false
	}
	*v = iBuffer[iPointer]
	iPointer++
	return true
}

func readString(v *string) bool {
	for (iPointer < nPointer) && isSpace(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isSpace(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	return true
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readInt64(v *int64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int64
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int64(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readFloat64(v *float64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		if iBuffer[iPointer] != '.' {
			neg = (iBuffer[iPointer] == '-')
		}
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	if neg {
		a = append(a, '-')
	}
	if iPointer > 0 && iBuffer[iPointer-1] == '.' {
		a = append(a, '.')
	} else {
		for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
		if (iPointer < nPointer) && (iBuffer[iPointer] == '.') {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
	}
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	var ok error
	*v, ok = strconv.ParseFloat(string(a), 64)
	return ok == nil
}

func readln(v *string) bool {
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isLine(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	return true
}

func read(arg interface{}) bool {
	switch v := arg.(type) {
	case *byte:
		return readByte(v)
	case *string:
		return readString(v)
	case *int:
		return readInt(v)
	case *int64:
		return readInt64(v)
	case *float64:
		return readFloat64(v)
	default:
		return false
	}
}

func writeBool(v bool) {
	if v {
		out.WriteString("true")
	} else {
		out.WriteString("false")
	}
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeString(v string) {
	out.WriteString(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}

func writeInt64(v int64) {
	out.WriteString(strconv.FormatInt(v, 10))
}

func writeFloat64(v float64) {
	out.WriteString(strconv.FormatFloat(v, 'f', -1, 64))
}

func writeln(arg interface{}) {
	write(arg)
	out.WriteByte('\n')
}

func write(arg interface{}) {
	switch v := arg.(type) {
	case bool:
		writeBool(v)
	case byte:
		writeByte(v)
	case string:
		writeString(v)
	case int:
		writeInt(v)
	case int64:
		writeInt64(v)
	case float64:
		writeFloat64(v)
	default:
		out.WriteString("###")
	}
}


/*
URL:
https://codeforces.com/contest/1389/problem/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n, k, z int64
	A       []int64
)

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, k, z = ReadInt64_3()
		A = ReadInt64Slice(int(n))

		solve()
	}
}

func solve() {
	dp := [][]int64{}
	for i := int64(0); i < n+10; i++ {
		row := make([]int64, 8)
		dp = append(dp, row)
	}

	for i := int64(0); i < n; i++ {
		for j := int64(0); j <= z; j++ {
			dp[i][j] = -INF_BIT60
		}
	}

	dp[0][0] = A[0]
	for i := int64(0); i < n-1; i++ {
		for j := int64(0); j <= z; j++ {
			total := i + 2*j

			if total >= k {
				continue
			}

			// 右
			ChMax(&dp[i+1][j], dp[i][j]+A[i+1])

			// 右左右
			if k-total >= 3 {
				ChMax(&dp[i+1][j+1], dp[i][j]+A[i]+2*A[i+1])
			}

			// 右左
			if k-total >= 2 {
				ChMax(&dp[i][j+1], dp[i][j]+A[i]+A[i+1])
			}
		}
	}

	ans := int64(0)
	for i := int64(0); i < n; i++ {
		for j := int64(0); j <= z; j++ {
			ChMax(&ans, dp[i][j])
		}
	}
	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func solve() {
	n, k, z := readInt64(), readInt64(), readInt64()
	array := make([]int64, n)
	for i := range array {
		array[i] = readInt64()
	}

	var ans, i int64
	for i = 0; i <= z; i++ {
		if i > k/2 {
			continue
		}

		var tmp, maxGain, j int64
		tmp = array[0]
		for j = 1; j <= k-i*2; j++ {
			maxGain = maxInt64(maxGain, array[j-1]+array[j])
			tmp += array[j]
		}

		if k-i*2+1 < n {
			maxGain = maxInt64(maxGain, array[k-i*2]+array[k-i*2+1])
		}
		tmp += maxGain * i
		ans = maxInt64(ans, tmp)
		// println(i, j, maxGain, ans)
	}
	fmt.Println(ans)
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

var rw = newFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	nTest := 1
	nTest = rw.nextInt()
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.nextInt()
	k := rw.nextInt()
	z := rw.nextInt()
	a := rw.nextInts(n)
	ans := 0
	for t := 0; t <= z; t++ {
		max := 0
		cur := 0
		for i := 0; i <= k-t*2; i++ {
			cur += a[i]
			if i+1 < n && a[i]+a[i+1] > max {
				max = a[i] + a[i+1]
			}
		}
		val := cur + max*t
		if val > ans {
			ans = val
		}
	}
	rw.println(ans)
}

// @meooow template uwu
type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		z := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, z, a))
	}
}

func sol(n, k, z int64, a []int64) int64 {
	if k-(z*2) >= n || len(a) == 0 {
		panic("") // should not happen
	}
	prefSums := make([]int64, len(a)+1)
	for i := 1; i < len(prefSums); i++ {
		prefSums[i] = prefSums[i-1] + a[i-1]
	}
	// printf("%v\n", prefSums)
	ret := int64(0)
	base := a[0]
	for osc := int64(1); osc < n; osc++ {
		base += a[osc]
		curr := base
		remainSteps := k - osc
		if remainSteps < 0 {
			break
		}
		// printf("remainsteps %d\n", remainSteps)
		// if we can oscillate and end
		if z*2 >= remainSteps {
			if remainSteps&1 == 0 {
				curr += a[osc-1] * (remainSteps / 2)
				curr += a[osc] * (remainSteps / 2)
				ret = max(ret, curr)
				// printf("even osc %d %d\n", osc, curr)
				continue
			}
			curr += a[osc-1] * (remainSteps/2 + 1)
			curr += a[osc] * (remainSteps / 2)
			ret = max(ret, curr)
			// printf("odd osc %d %d\n", osc, curr)
			continue
		}
		// oscillate and fill up remaining steps
		curr += a[osc-1] * z
		curr += a[osc] * z
		remainSteps -= z * 2
		// printf("pref = %d %d\n", osc, remainSteps)
		curr += prefSums[osc+1+remainSteps] - prefSums[osc+1]
		// printf("remain osc %d %d\n", osc, curr)
		ret = max(ret, curr)
	}
	return ret
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,k, z int
		Fscan(in, &n,&k,&z);
		a:=make([]int,n)
		for i:=0;i<n;i++{
			Fscan(in,&a[i])
		}

		ans:=0
		for l:=0;l<=z;l++{
			cnt,mx:=0,0
			for r:=0;r<=k-2*l;r++{
				cnt+=a[r]
				if r+1<n && mx < a[r]+a[r+1]{
					mx=a[r]+a[r+1]
				}
			}
			cnt+=l*mx
			if(cnt>ans){
				ans=cnt
			}
		}
		Fprintln(out,ans)
	}
}

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

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n, k, z := io.nextInt(), io.nextInt(), io.nextInt()
		a := io.nextInts(n)

		ans := 0
		for zz := 0; zz <= z; zz++ {
			s, mx := 0, 0
			for i := 0; i <= k-2*zz; i++ {
				s += a[i]
				if i+1 < n && a[i]+a[i+1] > mx {
					mx = a[i] + a[i+1]
				}
			}
			s += zz * mx
			if s > ans {
				ans = s
			}
		}

		io.println(ans)
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

type elem struct {
	score, pos int
	prevleft   bool
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 4*1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	for t := input(); t > 0; t-- {
		n, k, z := input(), input(), input()

		a := make([]int, n)

		for i := range a {
			a[i] = input()
		}

		dp := make([][]elem, k+1)
		for i := range dp {
			dp[i] = make([]elem, z+1)
		}

		dp[k][z].pos = 0
		dp[k][z].score = a[0]
		dp[k][z].prevleft = true

		for i := k; i > 0; i-- {
			for j := z; j >= 0 && j >= z-k+i; j-- {
				pos := dp[i][j].pos
				newScore := dp[i][j].score + a[pos+1]
				if newScore > dp[i-1][j].score {
					dp[i-1][j].score = newScore
					dp[i-1][j].pos = pos + 1
					dp[i-1][j].prevleft = false
				}

				if j != 0 && pos != 0 && !dp[i][j].prevleft {
					newScore = dp[i][j].score + a[pos-1]
					if newScore > dp[i-1][j-1].score {
						dp[i-1][j-1].score = newScore
						dp[i-1][j-1].prevleft = true
						dp[i-1][j-1].pos = pos - 1
					}
				}
			}
		}

		max := dp[0][0].score

		for _, e := range dp[0] {
			if e.score > max {
				max = e.score
			}
		}

		fmt.Println(max)
	}

}

package main

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

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

var n, z, k, cs int
var ara[100005] int
var dp[100005][7][3] int
var visit[100005][7][3] int

func F(pos int, lft int, flag int) int {
    mv := pos - 1 + 2 * (z - lft)
    if mv == k {
        return ara[pos];
    }

    if visit[pos][lft][flag] == cs {
        return dp[pos][lft][flag]
    }

    ret := F(pos + 1, lft, 0)
    if pos > 1 && lft > 0 && flag == 0 {
        ret = max(ret, F(pos - 1, lft - 1, 1))
    }

    visit[pos][lft][flag] = cs
    dp[pos][lft][flag] = ara[pos] + ret
    return dp[pos][lft][flag]
}

func main() {
    input := bufio.NewReader(os.Stdin)
	var T int;
    fmt.Fscan(input, &T)
	for t := 0; t < T; t++ {
        fmt.Fscan(input, &n)
        fmt.Fscan(input, &k)
        fmt.Fscan(input, &z)
		for i := 1; i <= n; i++ {
            fmt.Fscan(input, &ara[i])
		}
		cs++
		ret := F(1, z, 0)
		fmt.Printf("%d\n", ret)
	}
}

package main

import (
	"fmt"
	"os"
)

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

var n, z, k, cs int;
var ara[100005] int;
var dp[100005][7][3] int;
var visit[100005][7][3] int;

func F(pos int, lft int, flag int) int {
    mv := pos - 1 + 2 * (z - lft);
    if mv == k {
        os.Exit(0);
        return ara[pos];
    }

    if visit[pos][lft][flag] == cs {
        return dp[pos][lft][flag];
    }

    ret := F(pos + 1, lft, 0);
    if pos > 1 && lft > 0 && flag == 0 {
        ret = max(ret, F(pos - 1, lft - 1, 1));
    }

    visit[pos][lft][flag] = cs;
    dp[pos][lft][flag] = ara[pos] + ret;
    return dp[pos][lft][flag];
}

func main() {
	var T int;
	fmt.Scanf("%d\n", &T);
	for t := 0; t < T; t++ {
		fmt.Scanf("%d %d %d\n", &n, &k, &z);
		for i := 1; i <= n; i++ {
			if i < n {
			    fmt.Scanf("%d", &ara[i]);
			} else {
			    fmt.Scanf("%d\n", &ara[i]);
			}
		}
		cs++;
		ret := F(1, z, 0);
		fmt.Printf("%d\n", ret);
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func solve() {
	n, k, z := readInt64(), readInt64(), readInt64()
	array := make([]int64, n)
	for i := range array {
		array[i] = readInt64()
	}

	var ans, i int64
	for i = 0; i <= z; i++ {
		var tmp, maxGain, j int64
		tmp = array[0]
		for j = 1; j <= k-i*2; j++ {
			maxGain = maxInt64(maxGain, array[j-1]+array[j])
			tmp += array[j]
		}
		tmp += maxGain * i
		ans = maxInt64(ans, tmp)
	}
	fmt.Println(ans)
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		z := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, z, a))
	}
}

func sol(n, k, z int64, a []int64) int64 {
	if k-(z*2) >= n || len(a) == 0 {
		panic("") // should not happen
	}
	prefSums := make([]int64, len(a)+1)
	for i := 1; i < len(prefSums); i++ {
		prefSums[i] = prefSums[i] + a[i-1]
	}
	ret := int64(0)
	base := a[0]
	for end := int64(1); end < int64(len(a)); end++ {
		base += a[end]
		remainSteps := k - end
		if remainSteps < 0 {
			break
		}
		nback := z
		if remainSteps%2 == 1 {
			nback = min(nback, remainSteps/2+1)
		} else {
			nback = min(nback, remainSteps/2)
		}
		nfront := min(nback, remainSteps-nback)
		curr := base + (nback * a[end-1]) + (nfront * a[end])
		if nfront+nback+end < k {
			remain := k - end - nfront - nback
			realEnd := end + remain
			if realEnd < n {
				curr += prefSums[realEnd+1] - prefSums[end+1]
			}
		}
		ret = max(ret, curr)
	}
	return ret
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		z := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, z, a))
	}
}

func sol(n, k, z int64, a []int64) int64 {
	if k-(z*2) >= n || len(a) == 0 {
		panic("") // should not happen
	}
	prefSums := make([]int64, len(a)+1)
	for i := 1; i < len(prefSums); i++ {
		prefSums[i] = prefSums[i-1] + a[i-1]
	}
	// printf("%v\n", prefSums)
	ret := int64(0)
	base := a[0]
	for osc := int64(1); osc < n; osc++ {
		base += a[osc]
		curr := base
		remainSteps := k - osc
		if remainSteps < 0 {
			continue
		}
		if z*2 >= remainSteps {
			// we can oscillate and end
			if remainSteps & 1 == 0 {
				curr += a[osc-1] * remainSteps / 2
				curr += a[osc] * remainSteps / 2
				ret = max(ret, curr)
				continue
			}
			curr += a[osc-1] * (remainSteps / 2 + 1)
			curr += a[osc-1] * (remainSteps / 2)
			ret = max(ret, curr)
			continue
		}
		// oscillate and fill up remaining steps
		curr += a[osc-1] * z
		curr += a[osc] * z
		remainSteps -= z*2
		// printf("pref = %d %d\n", osc, remainSteps)
		curr += prefSums[osc+1+remainSteps] - prefSums[osc+1]
		ret = max(ret, curr)
	}
	return ret
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		z := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, z, a))
	}
}

func sol(n, k, z int64, a []int64) int64 {
	if k - (z*2) >= n || len(a) == 0 {
		panic("") // should not happen
	}
	ret := int64(0)
	base := a[0]
	for end := int64(1); end < int64(len(a)); end++ {
		base += a[end]
		remainSteps := k - end
		if remainSteps < 0 {
			break
		}
		var nback int64
		if remainSteps % 2 == 1 {
			nback = remainSteps / 2 + 1
		} else {
			nback = remainSteps / 2
		}
		if nback > z {
			continue
		}
		nfront := remainSteps / 2
		curr := base + (nback * a[end-1]) + (nfront * a[end])
		ret = max(ret, curr)
	}
	return ret
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		z := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, z, a))
	}
}

func sol(n, k, z int64, a []int64) int64 {
	if k-(z*2) >= n || len(a) == 0 {
		panic("") // should not happen
	}
	prefSums := make([]int64, len(a)+1)
	for i := 1; i < len(prefSums); i++ {
		prefSums[i] = prefSums[i-1] + a[i-1]
	}
	// printf("%v\n", prefSums)
	ret := int64(0)
	base := a[0]
	for osc := int64(1); osc < n; osc++ {
		base += a[osc]
		curr := base
		remainSteps := k - osc
		if remainSteps < 0 {
			break
		}
		if z*2 >= remainSteps {
			// we can oscillate and end
			if remainSteps & 1 == 0 {
				curr += a[osc-1] * remainSteps / 2
				curr += a[osc] * remainSteps / 2
				ret = max(ret, curr)
				continue
			}
			curr += a[osc-1] * (remainSteps / 2 + 1)
			curr += a[osc-1] * (remainSteps / 2)
			continue
		}
		// oscillate and fill up remaining steps
		curr += a[osc-1] * z
		curr += a[osc] * z
		remainSteps -= z*2
		// printf("pref = %d %d\n", osc, remainSteps)
		curr += prefSums[osc+1+remainSteps] - prefSums[osc+1]
		ret = max(ret, curr)
	}
	return ret
}


package main

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

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

	var T, n, m, w int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		pa := make([]int, n+1)
		pb := make([][]int, n+1)
		for i, v := range a {
			if Fscan(in, &w); w == v {
				pa[w] = i + 1
			} else {
				pb[w] = append(pb[w], i+1)
			}
		}
		c := make([]int, m)
		for i := range c {
			Fscan(in, &c[i])
		}
		ans := make([]interface{}, m)
		for i := m - 1; i >= 0; i-- {
			if v := c[i]; len(pb[v]) > 0 {
				ans[i] = pb[v][0]
				pb[v] = pb[v][1:]
			} else if i < m-1 {
				ans[i] = ans[m-1]
			} else if pa[v] > 0 {
				ans[i] = pa[v]
			} else {
				Fprintln(out, "NO")
				continue o
			}
		}
		for _, p := range pb {
			if len(p) > 0 {
				Fprintln(out, "NO")
				continue o
			}
		}
		Fprintln(out, "YES")
		Fprintln(out, ans...)
	}
}

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

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		C := readNNums(reader, m)
		ok, res := solve(n, m, A, B, C)
		if !ok {
			buf.WriteString("NO\n")
		} else {
			buf.WriteString("YES\n")
			for i := 0; i < len(res); i++ {
				buf.WriteString(fmt.Sprintf("%d ", res[i]))
			}
			buf.WriteByte('\n')
		}
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, m int, A []int, B []int, C []int) (bool, []int) {
	// 对于颜色x, cntb[x] >= cntc[x]
	diff := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		diff[i] = make([]int, 0, 2)
	}

	for i := 0; i < n; i++ {
		if A[i] != B[i] {
			b := B[i]
			diff[b] = append(diff[b], i+1)
		}
	}
	x := C[m-1]
	y := -1

	if len(diff[x]) > 0 {
		y = diff[x][len(diff[x])-1]
	} else {
		for i := n - 1; i >= 0; i-- {
			if B[i] == x {
				y = i + 1
				diff[x] = append(diff[x], i+1)
				break
			}
		}
	}

	if y < 0 {
		return false, nil
	}

	pos := make([]int, n+1)
	// then we always has a solution
	res := make([]int, m)
	for i := 0; i < m; i++ {
		c := C[i]
		if pos[c] >= len(diff[c]) {
			res[i] = y
		} else {
			res[i] = diff[c][pos[c]]
			pos[c]++
		}
	}

	for i := 0; i <= n; i++ {
		if pos[i] < len(diff[i]) {
			return false, nil
		}
	}

	return true, res
}

package main

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

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		fix := map[int][]int{}
		bPos := make([]int, n+1)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
			if b[i] != a[i] {
				fix[b[i]] = append(fix[b[i]], i+1)
				bPos[b[i]] = i + 1
			}
			if bPos[b[i]] == 0 {
				bPos[b[i]] = i + 1
			}
		}
		cc := make([]int, m)
		leftcc := make([]int, n+1)
		leftI := 1
		for i := range cc {
			Fscan(in, &cc[i])
			if bPos[cc[i]] > 0 {
				leftcc[cc[i]]++
			}
		}
		ans := make([]int, m)
		//badPos := -1
		for i, c := range cc {
			if len(fix[c]) > 0 {
				ans[i] = fix[c][0]
				fix[c] = fix[c][1:]
				if len(fix[c]) == 0 {
					delete(fix, c)
				}
				//badPos = -1
			} else if bPos[c] > 0 {
				ans[i] = bPos[c]
			} else {
				if len(fix) == 0 {
					for ; leftI <= n && leftcc[leftI] <= 0; leftI++ {
					}
					if leftI > n {
						Fprintln(out, "NO")
						return
					}
					fix[leftI] = append(fix[leftI], bPos[leftI])
					ans[i] = bPos[leftI]
					//badPos = 1
				} else {
					for _, vs := range fix {
						ans[i] = vs[0]
						break
					}
				}
			}
			leftcc[c]--
		}
		for _, f := range fix {
			if len(f) > 0 {
				Fprintln(out, "NO")
				return
			}
		}
		Fprintln(out, "YES")
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

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

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

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64sl(n int64) []int64 {
	sl := make([]int64, n)
	for i := range sl {
		sl[i] = sint64()
	}
	return sl
}

func suint64() uint64 {
	s := sstring()
	i := uint64(0)
	for _, r := range s {
		i *= 10
		i += uint64(r - '0')
	}
	return i
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		m := sint64()
		a := sint64sl(n)
		b := sint64sl(n)
		c := sint64sl(m)
		res := sol(n, m, a, b, c)
		if res == nil {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
		// judge(n, m, a, b, c, res)
	}
}

func sol(n, m int64, a, b, c []int64) []int64 {
	diff := map[int64][]int64{} // desiredcolor: []position
	for i := range a {
		if a[i] == b[i] {
			continue
		}
		diff[b[i]] = append(diff[b[i]], int64(i))
	}
	if len(diff) == 0 {
		return solSame(n, m, a, b, c)
	}
	// printf("diff=%v\n", diff)
	return solDiff(n, m, a, b, c, diff)
}

func solSame(n, m int64, a, b, c []int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i) + 1
	}
	// printf("set=%v\n", set)
	res := make([]int64, m)
	if v, ok := set[c[len(c)-1]]; !ok {
		return nil
	} else {
		for i := range res {
			res[i] = v
		}
	}
	return res
}

func solDiff(n, m int64, a, b, c []int64, diff map[int64][]int64) []int64 {
	set := map[int64]int64{}
	for i := range b {
		set[b[i]] = int64(i)
	}
	res := make([]int64, m)
	for i := len(c) - 1; i >= 0; i-- {
		if len(diff[c[i]]) == 0 {
			if i == len(c)-1 {
				if pos, ok := set[c[i]]; !ok {
					return nil
				} else {
					res[i] = pos + 1 // paint any plank of same desired color
				}
				continue
			}
			res[i] = res[len(res)-1] // paint last painter's plank, for it to be repainted later
			continue
		}
		res[i] = diff[c[i]][len(diff[c[i]])-1] + 1
		diff[c[i]] = diff[c[i]][:len(diff[c[i]])-1]
		if len(diff[c[i]]) == 0 {
			delete(diff, c[i])
		}
	}
	// printf("diff2=%v\n", diff)
	if len(diff) != 0 {
		return nil
	}
	return res
}

func judge(n, m int64, a, b, c, res []int64) {
	o := make([]int64, n)
	copy(o, a)
	for i := range res {
		pos := res[i] - 1
		col := c[i]
		a[pos] = col
	}
	for i := range a {
		if a[i] != b[i] {
			panic(fmt.Sprintf("unexpected sol:\no=%v\na=%v\nb=%v\nc=%v\n", o, a, b, c))
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		a := make([]int,n+5)
		b := make([]int,n+5)
		c := make([]int,m+5)
		ned := map[int][]int{}
		des := map[int]int{}
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
			if des[a[i]]==0{
				des[a[i]]=i
			}
		}
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&b[i])
			if b[i]!=a[i]{
				ned[b[i]] = append(ned[b[i]],i)
			}
		}
		for i:=1;i<=m;i++{
			fmt.Fscan(in,&c[i])
		}
		flag := true
		ops := []int{}
		er := []int{}
		for i:=1;i<=m;i++{
			if len(ned[c[i]])>0{
				tar := ned[c[i]][0]
				ned[c[i]] = ned[c[i]][1:]
				if len(er)>0{
					for j:=0;j<len(er);j++{
						ops = append(ops,tar)
					}
					er = []int{}
				}
				a[tar]=c[i]
				ops = append(ops,tar)
			}else{
				er = append(er,c[i])
			}
		}
		for _,v := range ned{
			if len(v)>0{
				flag = false
			}
		}
		if len(er)>0{
			fin := map[int]int{}
			for i:=1;i<=n;i++{
				fin[a[i]]=i
			}
			nol := []int{}
			for i:=0;i<len(er);i++ {
				if fin[er[i]]==0{
					nol = append(nol,er[i])
				}else{
					if len(nol)>0{
						for j:=0;j<len(nol);j++{
							ops = append(ops,fin[er[i]])
						}
						nol = []int{}
					}
					ops = append(ops,fin[er[i]])
				}
			}
			if len(nol)>0{
				flag = false
			}
		}
		if flag{
			fmt.Fprintln(out,"YES")
			for i:=0;i<len(ops);i++{
				fmt.Fprintf(out,"%d ",ops[i])
			}
			fmt.Fprintln(out)
		}else{
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

func solve(a, b, c []int) {
	hasColor := make(map[int]int, 0)
	needColor := make(map[int][]int, 0)
	totalNeed := 0
	ans := []int{}

	for i := range a {
		hasColor[b[i]] = i + 1
		if a[i] != b[i] {
			if len(needColor[b[i]]) == 0 {
				totalNeed++
			}
			needColor[b[i]] = append(needColor[b[i]], i)
		}
	}

	for i := range c {
		if totalNeed == 0 {
			if hasColor[c[len(c)-1]] > 0 {
				idx := hasColor[c[len(c)-1]]
				printf("yes\n")
				for _, x := range ans {
					printf("%d ", x+1)
				}
				for j := i; j < len(c); j++ {
					printf("%d ", idx)
				}
				printf("\n")
			} else {
				printf("no\n")
			}
			return
		}

		if len(needColor[c[i]]) > 0 {
			ans = append(ans, needColor[c[i]][len(needColor[c[i]])-1])
			needColor[c[i]] = needColor[c[i]][:len(needColor[c[i]])-1]
			if len(needColor[c[i]]) == 0 {
				totalNeed--
			}
		} else {
			v := -1
		L:
			for _, val := range needColor {
				for _, x := range val {
					v = x
					break L
				}
			}
			ans = append(ans, v)
		}
	}

	if totalNeed == 0 {
		printf("yes\n")
		for _, x := range ans {
			printf("%d ", x+1)
		}
		printf("\n")
	} else {
		printf("no\n")
	}
}

func main() {
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var n, m int
		scan(&n, &m)

		var a, b, c []int
		a = make([]int, n)
		b = make([]int, n)
		c = make([]int, m)
		for i := range a {
			scan(&a[i])
		}
		for i := range b {
			scan(&b[i])
		}
		for i := range c {
			scan(&c[i])
		}

		solve(a, b, c)
	}

	writer.Flush()
}

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

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func RedirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

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

var n, m int
var color [100005][]int
var a, b, c, same, ans, cnt [100005]int
var colored int

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		fmt.Fscan(in, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &b[i])
			if a[i] == b[i] {
				same[a[i]] = i
			} else {
				color[b[i]] = append(color[b[i]], i)
				cnt[b[i]]++
			}
		}
		for i := 1; i <= m; i++ {
			fmt.Fscan(in, &c[i])
		}
		no := false
		colored = 0
		for i := m; i >= 1; i-- {
			x := c[i]
			if cnt[x] > 0 {
				pos := color[x][cnt[x]-1]
				ans[i] = pos
				a[pos] = x
				cnt[x]--
				colored = pos
			} else if same[x] != 0 {
				// fmt.Println("same", same[x])
				ans[i] = same[x]
				colored = same[x]
			} else if colored != 0 {
				ans[i] = colored
			} else {
				no = true
				break
			}
			// fmt.Print(i, " ", ans[i], "|")
		}
		for i := 1; i <= n; i++ {
			if a[i] != b[i] {
				no = true
			}
		}

		if no {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			for i := 1; i <= m; i++ {
				fmt.Fprint(out, ans[i], " ")
			}
			fmt.Fprintln(out)
		}
		for i := 1; i <= n; i++ {
			same[a[i]] = 0
			cnt[b[i]] = 0
			color[b[i]] = nil
		}
		// out.Flush()
	}
	out.Flush()
}

package main

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

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

	var t, n, m int
	fmt.Fscan(in, &t)

MainLoop:
	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
		}
		c := make([]int, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &c[i])
		}

		changedCnt := make([]int, n+1)
		for i := range b {
			if a[i] != b[i] {
				changedCnt[b[i]]++
			}
		}
		changed := make([][]int, n+1)
		for i := 0; i < n+1; i++ {
			if changedCnt[i] > 0 {
				changed[i] = make([]int, 0, changedCnt[i])
			}
		}
		notChanged := make([]int, n+1)
		for i := range notChanged {
			notChanged[i] = -1
		}
		for i := range b {
			if a[i] == b[i] {
				notChanged[b[i]] = i + 1
			} else {
				changed[b[i]] = append(changed[b[i]], i+1)
			}
		}

		work := make([]int, m)
		if notChanged[c[m-1]] < 0 && changedCnt[c[m-1]] == 0 {
			fmt.Fprintln(out, "NO")
			out.Flush()
			continue
		}
		for i := m - 1; i >= 0; i-- {
			if changedCnt[c[i]] > 0 {
				work[i] = changed[c[i]][changedCnt[c[i]]-1]
				if changedCnt[c[i]] > 1 {
					changed[c[i]] = changed[c[i]][:changedCnt[c[i]]-1]
				} else {
					changed[c[i]] = nil
				}
				changedCnt[c[i]]--
			} else if notChanged[c[i]] > 0 {
				work[i] = notChanged[c[i]]
			} else {
				work[i] = work[i+1]
			}
		}

		for i := range changedCnt {
			if changedCnt[i] > 0 {
				fmt.Fprintln(out, "NO")
				out.Flush()
				continue MainLoop
			}
		}
		fmt.Fprintln(out, "YES")
		for i := 0; i < m-1; i++ {
			fmt.Fprint(out, work[i], " ")
		}
		fmt.Fprintln(out, work[m-1])
		out.Flush()
	}
}

package main

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

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

	var T, n, m, w int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		pa := make([]int, n+1)
		pb := make([][]int, n+1)
		for i, v := range a {
			if Fscan(in, &w); w == v {
				pa[w] = i + 1
			} else {
				pb[w] = append(pb[w], i+1)
			}
		}
		c := make([]int, m)
		for i := range c {
			Fscan(in, &c[i])
		}
		ans := make([]interface{}, m)
		for i := m - 1; i >= 0; i-- {
			if v := c[i]; len(pb[v]) > 0 {
				ans[i] = pb[v][0]
				pb[v] = pb[v][1:]
			} else if i < m-1 {
				ans[i] = ans[m-1]
			} else if pa[v] > 0 {
				ans[i] = pa[v]
			} else {
				Fprintln(out, "NO")
				continue o
			}
		}
		Fprintln(out, "YES")
		Fprintln(out, ans...)
	}
}

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

package main

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

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		fix := make([][]int, n+1)
		bPos := make([]int, n+1)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
			if b[i] != a[i] {
				fix[b[i]] = append(fix[b[i]], i+1)
				bPos[b[i]] = i + 1
			}
			if bPos[b[i]] == 0 {
				bPos[b[i]] = i + 1
			}
		}
		fixI := 1
		cc := make([]int, m)
		leftcc := make([]int, n+1)
		for i := range cc {
			Fscan(in, &cc[i])
			if bPos[cc[i]] > 0 {
				leftcc[cc[i]]++
			}
		}
		leftI := 1
		ans := make([]int, m)
		//badPos := -1
		for i, c := range cc {
			if len(fix[c]) > 0 {
				ans[i] = fix[c][0]
				fix[c] = fix[c][1:]
				//badPos = -1
			} else if bPos[c] > 0 {
				ans[i] = bPos[c]
			} else {
				for ; fixI <= n && len(fix[fixI]) == 0; fixI++ {
				}
				if fixI > n {
					for ; leftI <= n && leftcc[leftI] <= 0; leftI++ {
					}
					if leftI > n {
						Fprintln(out, "NO")
						return
					}
					fix[leftI] = append(fix[leftI], bPos[leftI])
					ans[i] = bPos[leftI]
					//badPos = 1
				} else {
					ans[i] = fix[fixI][0]
				}
			}
			leftcc[c]--
		}
		for _, f := range fix {
			if len(f) > 0 {
				Fprintln(out, "NO")
				return
			}
		}
		Fprintln(out, "YES")
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

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

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

package main

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

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

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		fix := make([][]int, n+1)
		final := make([]int, n+1)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
			if b[i] != a[i] {
				fix[b[i]] = append(fix[b[i]], i+1)
			}
			final[b[i]] = i + 1
		}
		fixI := 1
		cc := make([]int, m)
		leftcc := make([]int, n+1)
		for i := range cc {
			Fscan(in, &cc[i])
			if final[cc[i]]> 0 {
				leftcc[cc[i]]++
			}
		}
		leftI := 1
		ans := make([]int, m)
		//badPos := -1
		for i, c := range cc {
			if len(fix[c]) > 0 {
				ans[i] = fix[c][0]
				fix[c] = fix[c][1:]
				//badPos = -1
			} else if final[c] > 0 {
				ans[i] = final[c]
			} else {
				for ; fixI <= n && len(fix[fixI]) == 0; fixI++ {
				}
				if fixI > n {
					for ; leftI <= n && leftcc[leftI] <= 0; leftI++ {
					}
					if leftI > n {
						Fprintln(out, "NO")
						return
					}
					fix[leftI] = append(fix[leftI], final[leftI])
					ans[i] = final[leftI]
					//badPos = 1
				} else {
					ans[i] = fix[fixI][0]
				}
			}
			leftcc[c]--
		}
		for _, f := range fix {
			if len(f) > 0 {
				Fprintln(out, "NO")
				return
			}
		}
		Fprintln(out, "YES")
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

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

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

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64sl(n int64) []int64 {
	sl := make([]int64, n)
	for i := range sl {
		sl[i] = sint64()
	}
	return sl
}

func suint64() uint64 {
	s := sstring()
	i := uint64(0)
	for _, r := range s {
		i *= 10
		i += uint64(r - '0')
	}
	return i
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		m := sint64()
		a := sint64sl(n)
		b := sint64sl(n)
		c := sint64sl(m)
		res := sol(n, m, a, b, c)
		if res == nil {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
	}
}

func sol(n, m int64, a, b, c []int64) []int64 {
	diff := map[int64][]int64{} // desiredcolor: []position
	for i := range a {
		if a[i] == b[i] {
			continue
		}
		diff[b[i]] = append(diff[b[i]], int64(i))
	}
	if len(diff) == 0 {
		return solSame(n, m, a, b, c)
	}
	// printf("diff=%v\n", diff)
	return solDiff(n, m, a, b, c, diff)
}

func solSame(n, m int64, a, b, c []int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i) + 1
	}
	// printf("set=%v\n", set)
	res := make([]int64, m)
	if v, ok := set[c[len(c)-1]]; !ok {
		return nil
	} else {
		for i := range res {
			res[i] = v
		}
	}
	return res
}

func solDiff(n, m int64, a, b, c []int64, diff map[int64][]int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i)
	}
	res := make([]int64, m)
	for i := len(c) - 1; i >= 0; i-- {
		color := c[i]
		if len(diff[color]) == 0 {
			if i == len(c)-1 {
				if pos, ok := set[color]; !ok {
					return nil
				} else {
					res[i] = pos + 1
				}
				continue
			}
			res[i] = res[len(res)-1] // paint last painter's plank, for it to be repainted later
			continue
		}
		res[i] = diff[color][len(diff[color])-1] + 1
		diff[color] = diff[color][:len(diff[color])-1]
		if len(diff[color]) == 0 {
			delete(diff, color)
		}
	}
	// printf("diff2=%v\n", diff)
	if len(diff) != 0 {
		return nil
	}
	return res
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64sl(n int64) []int64 {
	sl := make([]int64, n)
	for i := range sl {
		sl[i] = sint64()
	}
	return sl
}

func suint64() uint64 {
	s := sstring()
	i := uint64(0)
	for _, r := range s {
		i *= 10
		i += uint64(r - '0')
	}
	return i
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		m := sint64()
		a := sint64sl(n)
		b := sint64sl(n)
		c := sint64sl(m)
		res := sol(n, m, a, b, c)
		if res == nil {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
	}
}

func sol(n, m int64, a, b, c []int64) []int64 {
	diff := map[int64][]int64{} // desiredcolor: []position
	for i := range a {
		if a[i] == b[i] {
			continue
		}
		diff[b[i]] = append(diff[b[i]], int64(i))
	}
	if len(diff) == 0 {
		return solSame(n, m, a, b, c)
	}
	// printf("diff=%v\n", diff)
	return solDiff(n, m, a, b, c, diff)
}

func solSame(n, m int64, a, b, c []int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i) + 1
	}
	// printf("set=%v\n", set)
	res := make([]int64, m)
	if v, ok := set[c[len(c)-1]]; !ok {
		return nil
	} else {
		for i := range res {
			res[i] = v
		}
	}
	return res
}

func solDiff(n, m int64, a, b, c []int64, diff map[int64][]int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i)
	}
	res := make([]int64, m)
	for i := len(c) - 1; i >= 0; i-- {
		color := c[i]
		if len(diff[color]) == 0 {
			if i == len(c)-1 {
				if pos, ok := set[color]; !ok {
					return nil
				} else {
					res[i] = pos + 1
				}
			}
			res[i] = res[len(res)-1] // paint last painter's plank, for it to be repainted later
			continue
		}
		res[i] = diff[color][len(diff[color])-1] + 1
		diff[color] = diff[color][:len(diff[color])-1]
		if len(diff[color]) == 0 {
			delete(diff, color)
		}
	}
	// printf("diff2=%v\n", diff)
	if len(diff) != 0 {
		return nil
	}
	return res
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64sl(n int64) []int64 {
	sl := make([]int64, n)
	for i := range sl {
		sl[i] = sint64()
	}
	return sl
}

func suint64() uint64 {
	s := sstring()
	i := uint64(0)
	for _, r := range s {
		i *= 10
		i += uint64(r - '0')
	}
	return i
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		m := sint64()
		a := sint64sl(n)
		b := sint64sl(n)
		c := sint64sl(m)
		res := sol(n, m, a, b, c)
		if res == nil {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
	}
}

func sol(n, m int64, a, b, c []int64) []int64 {
	diff := map[int64][]int64{} // desiredcolor: []position
	for i := range a {
		if a[i] == b[i] {
			continue
		}
		diff[b[i]] = append(diff[b[i]], int64(i))
	}
	if len(diff) == 0 {
		return solSame(n, m, a, b, c)
	}
	// printf("diff=%v\n", diff)
	return solDiff(n, m, a, b, c, diff)
}

func solSame(n, m int64, a, b, c []int64) []int64 {
	set := map[int64]int64{}
	for i := range a {
		set[a[i]] = int64(i) + 1
	}
	// printf("set=%v\n", set)
	res := make([]int64, m)
	if v, ok := set[c[len(c)-1]]; !ok {
		return nil
	} else {
		for i := range res {
			res[i] = v
		}
	}
	return res
}

func solDiff(n, m int64, a, b, c []int64, diff map[int64][]int64) []int64 {
	res := make([]int64, m)
	for i := len(c) - 1; i >= 0; i-- {
		color := c[i]
		if len(diff[color]) == 0 {
			if i == len(c)-1 {
				return nil
			}
			res[i] = res[len(res)-1] // paint last plank, for it to be repainted later
			continue
		}
		res[i] = diff[color][len(diff[color])-1]+1
		diff[color] = diff[color][:len(diff[color])-1]
		if len(diff[color]) == 0 {
			delete(diff, color)
		}
	}
	// printf("diff2=%v\n", diff)
	if len(diff) != 0 {
		return nil
	}
	return res
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		a := make([]int,n+5)
		b := make([]int,n+5)
		c := make([]int,m+5)
		ned := map[int][]int{}
		des := map[int]int{}
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
			if des[a[i]]==0{
				des[a[i]]=i
			}
		}
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&b[i])
			if b[i]!=a[i]{
				ned[b[i]] = append(ned[b[i]],i)
			}
		}
		for i:=1;i<=m;i++{
			fmt.Fscan(in,&c[i])
		}
		flag := true
		ops := []int{}
		er := []int{}
		for i:=1;i<=m;i++{
			if len(ned[c[i]])>0{
				tar := ned[c[i]][0]
				ned[c[i]] = ned[c[i]][1:]
				if len(er)>0{
					for j:=0;j<len(er);j++{
						ops = append(ops,tar)
					}
					er = []int{}
				}
				ops = append(ops,tar)
				des[c[i]]=tar
			}else{
				if des[c[i]]!=0{
					if len(er)>0{
						for j:=0;j<len(er);j++{
							ops = append(ops,des[c[i]])
						}
						er = []int{}
					}
					ops = append(ops,des[c[i]])
				}else{
					er = append(er,1)
				}
			}
		}
		for _,v := range ned{
			if len(v)>0{
				flag = false
			}
		}
		if len(er)>0{
			flag = false
		}
		if flag{
			fmt.Fprintln(out,"YES")
			for i:=0;i<len(ops);i++{
				fmt.Fprintf(out,"%d ",ops[i])
			}
			fmt.Fprintln(out)
		}else{
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

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

var n, m int
var color [100005][]int
var a, b, c, same, ans, cnt [100005]int
var colored int

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		fmt.Fscan(in, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &b[i])
			if a[i] == b[i] {
				same[a[i]] = i
			} else {
				color[b[i]] = append(color[b[i]], i)
				cnt[b[i]]++
			}
		}
		for i := 1; i <= m; i++ {
			fmt.Fscan(in, &c[i])
		}
		no := false
		colored = 0
		for i := m; i >= 1; i-- {
			x := c[i]
			if cnt[x] > 0 {
				pos := color[x][cnt[x]-1]
				ans[i] = pos
				a[pos] = x
				cnt[x]--
				colored = pos
			} else if same[x] != 0 {
				fmt.Println("same", same[x])
				ans[i] = same[x]
				colored = same[x]
			} else if colored != 0 {
				ans[i] = colored
			} else {
				no = true
				break
			}
			// fmt.Print(i, " ", ans[i], "|")
		}
		for i := 1; i <= n; i++ {
			if a[i] != b[i] {
				no = true
			}
		}

		if no {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			for i := 1; i <= m; i++ {
				fmt.Fprint(out, ans[i], " ")
			}
			fmt.Fprintln(out)
		}
		for i := 1; i <= n; i++ {
			same[a[i]] = 0
			cnt[b[i]] = 0
			color[b[i]] = nil
		}
		// out.Flush()
	}
	out.Flush()
}


package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type pair struct {
	pos, val int
}

type byVal []pair

func (s byVal) Len() int           { return len(s) }
func (s byVal) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byVal) Less(i, j int) bool { return s[i].val < s[j].val }

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	a := make([]int, n)
	pv := make([]pair, n)
	for i := range a {
		a[i] = readInt()
		pv[i].pos = i
		pv[i].val = a[i]
	}
	ans := make([]byte, n)
	sort.Sort(sort.Reverse(byVal(pv)))
	for _, pv := range pv {
		for i := pv.pos - pv.val; i >= 0; i -= pv.val {
			if ans[i] == 'B' {
				ans[pv.pos] = 'A'
				break
			}
		}
		if ans[pv.pos] == 0 {
			for i := pv.pos + pv.val; i < n; i += pv.val {
				if ans[i] == 'B' {
					ans[pv.pos] = 'A'
					break
				}
			}
		}
		if ans[pv.pos] == 0 {
			ans[pv.pos] = 'B'
		}
	}
	fmt.Printf("%s\n", ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1033C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := make([]byte, n)
	var f func(int) byte
	f = func(p int) (res byte) {
		d := &dp[p]
		if *d > 0 {
			return *d
		}
		defer func() { *d = res }()
		for i := p % a[p]; i < n; i += a[p] {
			if a[i] > a[p] && f(i) == 'B' {
				return 'A'
			}
		}
		return 'B'
	}
	for i := 0; i < n; i++ {
		f(i)
	}
	Fprint(out, string(dp))
}

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

package main

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

var n int
var a, dp []int

func f(index int) int {
	if a[index] == n {
		return 2
	}
	if dp[index] != 0 {
		return dp[index]
	}
	for _, k := range []int{-1, 1} {
		for i := 1; ; i++ {
			newIndex := index + k*i*a[index]
			if newIndex < 0 || newIndex >= n {
				break
			}
			if a[newIndex] < a[index] {
				continue
			}
			if f(newIndex) == 2 {
				dp[index] = 1
				return dp[index]
			}
		}
	}
	dp[index] = 2
	return dp[index]
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	a = make([]int, n)
	dp = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}

	outBuf := bufio.NewWriter(os.Stdout)
	defer func() { outBuf.Flush() }()

	for i := 0; i < n; i++ {
		fmt.Fprintf(outBuf, "%c", "AB"[f(i)-1])
	}
}