package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(reader, &a[j])
		}

		sort.Sort(sort.Reverse(sort.IntSlice(a)))

		var sum int64
		for i := 0; i <= k; i++ {
			sum += int64(a[i])
		}

		fmt.Println(sum)
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		a := ReadInt64s(n)
		Println(solve(n, k, a))
	}
}

func solve(n, k int, a []int64) int64 {
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})
	return Sum(a[:k+1]...)
}

func Sum(xs ...int64) (v int64) {
	for _, x := range xs {
		v += x
	}
	return v
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

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

package main

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

var (
	t int

	n, k int
	A    []int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, k = readi2()
		A = readlls(n)

		ans := solve()
		printf("%d\n", ans)
	}
}

func solve() int64 {
	sort.Slice(A, func(i, j int) bool {
		return A[i] > A[j]
	})

	ans := A[0]
	idx := 1
	for i := 0; i < k; i++ {
		ans += A[idx+i]
	}

	return ans
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

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

// 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 *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

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

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

package main

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

// 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, k int
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if k == 0 {
			Fprintln(out, a[n-1]-a[0])
			return
		}

		s := int64(a[n-1])
		for i := n - 2; i >= 0 && k > 0; i-- {
			s += int64(a[i])
			k--
		}
		Fprintln(out, s)

		return
	}

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

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

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		s := int64(0)
		for _, v := range a[n-k-1:] {
			s += int64(v)
		}
		Fprintln(out, s)
	}
}

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

package main

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

var t, n, k int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		fmt.Fscan(input, &n, &k)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		var ans int64
		q := 0
		ans = int64(arr[n-1])

		for i := (n - 2); i >= 0; i-- {
			if q == k {
				break
			}

			ans += int64(arr[i])
			q++
		}

		fmt.Println(ans)
	}

}

package main

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

func calc(l []uint64, k uint64) uint64 {
	sort.Slice(l, func(i, j int) bool { return l[i] > l[j] })
	var sum uint64
	sum = 0
	for i := 0; uint64(i) <= k; i++ {
		sum += l[i]
	}

	return sum
}

func main() {
	const maxCapacity = 10000000
	buf := make([]byte, maxCapacity)
	input := bufio.NewScanner(os.Stdin)
	input.Buffer(buf, maxCapacity)
	input.Scan()
	num, _ := strconv.Atoi(input.Text())
	r := make([]uint64, num)
	for j := 0; j < num; j++ {
		input.Scan()
		sstr := strings.Split(input.Text(), " ")
		n, _ := strconv.Atoi(sstr[0])
		k, _ := strconv.Atoi(sstr[1])
		l := make([]uint64, n)
		input.Scan()
		str := strings.Split(input.Text(), " ")
		for i := 0; i < n; i++ {
			v, _ := strconv.Atoi(str[i])
			l[i] = uint64(v)
		}
		// fmt.Printf("%v\n", l)
		result := calc(l, uint64(k))
		r[j] = result
	}

	for j := 0; j < num; j++ {
		fmt.Printf("%v\n", r[j])
	}

}

package main

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

var (
	t     int16
	k     int
	n     int
	maxV  int
	maxP  int
	count int64
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {

		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)

		for i := range a {
			fmt.Fscan(reader, &a[i])
		}

		solve(a, k)

	}
}

func solve(a []int, k int) {

	sort.Ints(a)
	reverse(a)

	count = int64(a[0])

	for i := range a {
		if i == 0 {
			continue
		}

		count += int64(a[i])
		k--

		if k == 0 {
			break
		}
	}

	fmt.Println(count)

}

func max(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[0]
	a[0] = a[maxP]
	a[maxP] = temp

	return a[0]
}

func second(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if i == 0 {
			continue
		}
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[1]
	a[1] = a[maxP]
	a[maxP] = temp

	return a[1]
}

func reverse(a []int) {

	size := len(a)

	for i := 0; i < size/2; i++ {
		temp := a[i]
		a[i] = a[size-1-i]
		a[size-1-i] = temp
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
func readInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' { sign = -sign}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans << 3 + ans << 1 + int(c - '0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

var T, n, k int

func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func main() {
	readInt(&T)
	for kase := 1; kase <= T; kase++ {
		var a []int
		readInt(&n)
		readInt(&k)
		for i := 1; i <= n; i++ {
			var x int
			readInt(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		reverse(a)

		/*
		for i, i2 := range a {
			fmt.Println(i, i2)
		}
		*/

		var ans int64

		for i := 0; i < len(a); i++ {
			if k < 0 {
				continue
			}
			k--
			ans+=int64(a[i])
		}
		fmt.Println(ans)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func readInt(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

var T, n, k int64

func main() {
	readInt(&T)
	for kase := int64(1); kase <= T; kase++ {
		var a []int64
		readInt(&n)
		readInt(&k)
		for i := int64(1); i <= n; i++ {
			var x int64
			readInt(&x)
			a = append(a, x)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})

		for i := 1; i < len(a); i++ {
			if k <= 0 {
				continue
			}
			k--
			a[0] += a[i]
			a[i] -= a[i]
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		fmt.Println(a[len(a)-1] - a[0])
	}
}

package main

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

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

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

func solve() {
	var n, k int
	scanf("%d %d\n", &n, &k)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &d[i])
		} else {
			scanf("%d ", &d[i])
		}
	}
	sort.Ints(d)
	var sum int64
	sum = int64(0)
	cnt := 0
	for i := n - 1; cnt <= k && i >= 0; i-- {
		sum += int64(d[i])
		cnt++
	}
	printf("%d\n", sum)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func solve() {
	var n, k int
	scanf("%d %d\n", &n, &k)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &d[i])
		} else {
			scanf("%d ", &d[i])
		}
	}
	sort.Ints(d)
	var sum int64
	sum = int64(0)
	cnt := 0
	for i := n - 1; cnt <= k && i >= 0; i-- {
		sum += int64(d[i])
		cnt++
	}
	printf("%d\n", int64(sum))
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

var (
	t     int16
	k     int
	n     int
	maxV  int
	maxP  int
	count int
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {

		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)

		for i := range a {
			fmt.Fscan(reader, &a[i])
		}

		solve(a, k)

	}
}

func solve(a []int, k int) {

	sort.Ints(a)
	reverse(a)

	count = a[0]

	for i := range a {
		if i == 0 {
			continue
		}

		count += a[i]
		k--

		if k == 0 {
			break
		}
	}

	fmt.Println(count)

}

func max(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[0]
	a[0] = a[maxP]
	a[maxP] = temp

	return a[0]
}

func second(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if i == 0 {
			continue
		}
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[1]
	a[1] = a[maxP]
	a[maxP] = temp

	return a[1]
}

func reverse(a []int) {

	size := len(a)

	for i := 0; i < size/2; i++ {
		temp := a[i]
		a[i] = a[size-1-i]
		a[size-1-i] = temp
	}
}

package main

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

var (
	t     int16
	k     int
	n     int
	maxV  int
	maxP  int
	count int
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {

		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)

		for i := range a {
			fmt.Fscan(reader, &a[i])
		}

		solve(a, k)

	}
}

func solve(a []int, k int) {

	count = a[0]

	sort.Ints(a)
	reverse(a)

	for i := range a {
		count += a[i]
		k--

		if k == 0 {
			break
		}
	}

	fmt.Println(count)

}

func max(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[0]
	a[0] = a[maxP]
	a[maxP] = temp

	return a[0]
}

func second(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if i == 0 {
			continue
		}
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[1]
	a[1] = a[maxP]
	a[maxP] = temp

	return a[1]
}

func reverse(a []int) {

	size := len(a)

	for i := 0; i < size/2; i++ {
		temp := a[i]
		a[i] = a[size-1-i]
		a[size-1-i] = temp
	}
}

package main

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

var (
	t     int16
	k     int
	n     int
	maxV  int
	maxP  int
	count int
)

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

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {

		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)

		for i := range a {
			fmt.Fscan(reader, &a[i])
		}

		solve(a, k)

	}
}

func solve(a []int, k int) {

	count = a[0]

	sort.Ints(a)
	reverse(a)

	for i := range a {
		if i == 0 {
			continue
		}

		count += a[i]
		k--

		if k == 0 {
			break
		}
	}

	fmt.Println(count)

}

func max(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[0]
	a[0] = a[maxP]
	a[maxP] = temp

	return a[0]
}

func second(a []int) int {
	maxV = 0
	maxP = 0

	for i := range a {
		if i == 0 {
			continue
		}
		if a[i] > maxV {
			maxV = a[i]
			maxP = i
		}
	}

	temp := a[1]
	a[1] = a[maxP]
	a[maxP] = temp

	return a[1]
}

func reverse(a []int) {

	size := len(a)

	for i := 0; i < size/2; i++ {
		temp := a[i]
		a[i] = a[size-1-i]
		a[size-1-i] = temp
	}
}

package main

import (
	"fmt"
	"sort"
)

const maxn int = 2e5 + 7

var T, n, k int
var a []int

func main() {
	fmt.Scan(&T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scan(&n, &k)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		/*
		for _,val := range a {
			fmt.Print(val," ")
		}
		*/

		var val = a[0] * 2
		for i := n - 2; i >= 0; i-- {
			if k <= 0 {
				continue
			}
			if a[i] < val {
				a[n-1] += a[0]
				a[0] -= a[0]
				k--
			} else {
				a[n-1] += a[i]
				a[i] -= a[i]
				k--
			}
		}
		fmt.Println(a[n-1] - a[0])
	}
}

/*

1
2 1
70 37

 */

package main

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

var in = bufio.NewReader(os.Stdin)

func readInt(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

var T, n, k int64

func main() {
	readInt(&T)
	for kase := int64(0); kase <= T; kase++ {
		var a []int64
		readInt(&n)
		readInt(&k)
		for i := int64(1); i <= n; i++ {
			var x int64
			readInt(&x)
			a = append(a, x)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})

		for i := 1; i < len(a); i++ {
			if k <= 0 {
				continue
			}
			k--
			a[0] += a[i]
			a[i] -= a[i]
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		fmt.Println(a[len(a)-1] - a[0])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
func readInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' { sign = -sign}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans << 3 + ans << 1 + int(c - '0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

var T, n, k int

func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func main() {
	readInt(&T)
	for kase := 1; kase <= T; kase++ {
		var a []int
		readInt(&n)
		readInt(&k)
		for i := 1; i <= n; i++ {
			var x int
			readInt(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		reverse(a)
		/*
		for i, i2 := range a {
			fmt.Println(i, i2)
		}
		*/

		for i := 1; i < len(a); i++ {
			if k <= 0 {
				continue
			}
			k--
			a[0] += a[i]
			a[i] -= a[i]
		}
		sort.Ints(a)
		fmt.Println(a[len(a)-1]-a[0])
	}
}

/*
1
3 1
47 69 42
*/

package main

import (
	"fmt"
	"sort"
)

var T, n, k int

func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func main() {
	_, _ = fmt.Scan(&T)
	for kase := 1; kase <= T; kase++ {
		var a []int
		_, _ = fmt.Scan(&n, &k)
		for i := 1; i <= n; i++ {
			var x int
			_, _ = fmt.Scan(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		reverse(a)
		for i, i2 := range a {
			fmt.Println(i, i2)
		}
		for i := 1; i < len(a); i++ {
			if k <= 0 {
				continue
			}
			k--
			a[0] += a[i]
			a[i] -= a[i]
		}
		sort.Ints(a)
		fmt.Println(a[len(a)-1]-a[0])
	}
}

package main

import (
	"fmt"
	"sort"
)

const maxn int = 2e5 + 7

var T, n, k int
var a []int

func main() {
	fmt.Scan(&T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scan(&n, &k)
		for i := 1; i <= n; i++ {
			var x int
			fmt.Scan(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		var val = a[0] * 2
		for i := n - 2; i >= 1; i-- {
			if k <= 0 {
				continue
			}
			if a[i] < val {
				a[n-1] += a[0]
				a[0] -= a[0]
				k--
			} else {
				a[n-1] += a[i]
				a[i] -= a[i]
				k--
			}
		}
		fmt.Println(a[n-1] - a[0])
	}
}

package main

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

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

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

func solve() {
	var n, k int
	scanf("%d %d\n", &n, &k)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &d[i])
		} else {
			scanf("%d ", &d[i])
		}
	}
	sort.Ints(d)
	sum := 0
	cnt := 0
	for i := n - 1; cnt <= k; i-- {
		sum += d[i]
		cnt++
	}
	printf("%d\n", sum)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		a := ReadInts(n)
		Println(solve(n, k, a))
	}
}

func solve(n, k int, a []int) int {
	sort.Ints(a)
	for i := n - 2; k > 0; k-- {
		a[n-1] += a[i]
	}
	return a[n-1]
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		a := ReadInts(n)
		Println(solve(n, k, a))
	}
}

func solve(n, k int, a []int) int {
	sort.Ints(a)
	for i := 0; i < k; i++ {
		a[n-1] += a[n-2-i]
	}
	return a[n-1]
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		a := ReadInts(n)
		Println(solve(n, k, a))
	}
}

func solve(n, k int, a []int) int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return Sum(a[:k+1]...)
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt(), ReadInt()
		a := ReadInts(n)
		Println(solve(n, k, a))
	}
}

func solve(n, k int, a []int) int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	if k == 0 {
		return a[0] - a[n-1]
	}
	if k >= n {
		return Sum(a...)
	}
	return Sum(a[:k+1]...)
}

func Sum(xs ...int) (v int) {
	for _, x := range xs {
		v += x
	}
	return v
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
  "container/heap"
	"errors"
	"math/rand"
)

const (
	partitionThreshold            = 8
	naiveSelectionLengthThreshold = 100
	naiveSelectionThreshold       = 10
	heapSelectionKRatio           = 0.001
	heapSelectionThreshold        = 1e3
)

/*
A type, typically a collection, which satisfies quickselect.Interface can be
used as data in the QuickSelect method. The interface is the same as the
interface required by Go's canonical sorting package (sort.Interface).
Note that the methods require that the elements of the collection be enumerated
by an integer index.
*/
type Interface interface {
	// Len is the number of elements in the collection
	Len() int
	// Less reports whether the element with
	// index i should sort before the element with index j
	Less(i, j int) bool
	// Swap swaps the order of elements i and j
	Swap(i, j int)
}

type reverse struct {
	// This embedded Interface permits Reverse to use the methods of
	// another Interface implementation.
	Interface
}

// Less returns the opposite of the embedded implementation's Less method.
func (r reverse) Less(i, j int) bool {
	return r.Interface.Less(j, i)
}

func Reverse(data Interface) Interface {
	return &reverse{data}
}

// The IntSlice type attaches the QuickSelect interface to an array of ints. It
// implements Interface so that you can call QuickSelect(k) on any IntSlice.
type IntSlice []int

func (t IntSlice) Len() int {
	return len(t)
}

func (t IntSlice) Less(i, j int) bool {
	return t[i] < t[j]
}

func (t IntSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the IntSlice so that the first k elements in the
// IntSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t IntSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The Float64Slice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// Float64Slice.
type Float64Slice []float64

func (t Float64Slice) Len() int {
	return len(t)
}

func (t Float64Slice) Less(i, j int) bool {
	return t[i] < t[j] || isNaN(t[i]) && !isNaN(t[j])
}

func (t Float64Slice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the Float64Slice so that the first k elements in the
// Float64Slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t Float64Slice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The StringSlice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// StringSlice.
type StringSlice []string

func (t StringSlice) Len() int {
	return len(t)
}

func (t StringSlice) Less(i, j int) bool {
	return t[i] > t[j]
}

func (t StringSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the StringSlice so that the first k elements in the
// StringSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t StringSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// isNaN is a copy of math.IsNaN to avoid a dependency on the math package.
func isNaN(f float64) bool {
	return f != f
}

/*
Helper function that does all of the work for QuickSelect. This implements
Hoare's Selection Algorithm which finds the smallest k elements in an interface
in expected O(n) time.
The algorithm works by finding a random pivot element, and making sure all the
elements to the left are less than the pivot element and vice versa for
elements on the right. Recursing on this solves the selection algorithm.
*/
func randomizedSelectionFinding(data Interface, low, high, k int) {
	var pivotIndex int

	for {
		if low >= high {
			return
		} else if high-low <= partitionThreshold {
			insertionSort(data, low, high+1)
			return
		}

		pivotIndex = rand.Intn(high+1-low) + low
		pivotIndex = partition(data, low, high, pivotIndex)

		if k < pivotIndex {
			high = pivotIndex - 1
		} else if k > pivotIndex {
			low = pivotIndex + 1
		} else {
			return
		}
	}
}

// Insertion sort
func insertionSort(data Interface, a, b int) {
	for i := a + 1; i < b; i++ {
		for j := i; j > a && data.Less(j, j-1); j-- {
			data.Swap(j, j-1)
		}
	}
}

/*
This method does a run over all of the data keeps a list of the k smallest
indices that it has seen so far. At the end, it swaps those k elements and
moves them to the front.
*/
func naiveSelectionFinding(data Interface, k int) {
	smallestIndices := make([]int, k)
	for i := 0; i < k; i++ {
		smallestIndices[i] = i
	}
	resetLargestIndex(smallestIndices, data)

	for i := k; i < data.Len(); i++ {
		if data.Less(i, smallestIndices[k-1]) {
			smallestIndices[k-1] = i
			resetLargestIndex(smallestIndices, data)
		}
	}

	insertionSort(IntSlice(smallestIndices), 0, k)
	for i := 0; i < k; i++ {
		data.Swap(i, smallestIndices[i])
	}
}

/*
Takes the largest index in `indices` according to the data Interface and places
it at the end of the indices array.
*/
func resetLargestIndex(indices []int, data Interface) {
	var largestIndex = 0
	var currentLargest = indices[0]

	for i := 1; i < len(indices); i++ {
		if data.Less(currentLargest, indices[i]) {
			largestIndex = i
			currentLargest = indices[i]
		}
	}

	indices[len(indices)-1], indices[largestIndex] = indices[largestIndex], indices[len(indices)-1]
}

/*
Helper function for the selection algorithm. Returns the partitionIndex.
It goes through all elements between low and high and makes sure that the
elements in the range [low, partitionIndex) are less than the element that was
originally in the pivotIndex and that the elements in the range
[paritionIndex + 1, high] are greater than the element originally in the
pivotIndex.
*/
func partition(data Interface, low, high, pivotIndex int) int {
	partitionIndex := low
	data.Swap(pivotIndex, high)
	for i := low; i < high; i++ {
		if data.Less(i, high) {
			data.Swap(i, partitionIndex)
			partitionIndex++
		}
	}
	data.Swap(partitionIndex, high)
	return partitionIndex
}

type dataHeap struct {
	heapIndices []int
	data        Interface
}

func (h dataHeap) Len() int           { return len(h.heapIndices) }
func (h dataHeap) Less(i, j int) bool { return h.data.Less(h.heapIndices[j], h.heapIndices[i]) }
func (h dataHeap) Swap(i, j int) {
	h.heapIndices[i], h.heapIndices[j] = h.heapIndices[j], h.heapIndices[i]
}

func (h *dataHeap) Push(x interface{}) {
	h.heapIndices = append(h.heapIndices, x.(int))
}

func (h *dataHeap) Pop() interface{} {
	old := h.heapIndices
	n := len(old)
	x := old[n-1]
	h.heapIndices = old[0 : n-1]
	return x
}

/*
This method implements the heap strategy for selecting the smallest k elements.
It keeps a max-heap of the smallest k elements seen so far as we iterate over
all of the elements. It adds a new element and pops the largest element.
*/
func heapSelectionFinding(data Interface, k int) {
	heapIndices := make([]int, k)
	for i := 0; i < k; i++ {
		heapIndices[i] = i
	}

	h := &dataHeap{heapIndices, data}
	heap.Init(h)
	var currentHeapMax int
	for i := k; i < data.Len(); i++ {
		currentHeapMax = h.heapIndices[0]

		if data.Less(i, currentHeapMax) {
			heap.Push(h, i)
			heap.Pop(h)
		}
	}

	insertionSort(IntSlice(h.heapIndices), 0, len(h.heapIndices))
	for i := 0; i < len(h.heapIndices); i++ {
		data.Swap(i, h.heapIndices[i])
	}
}

/*
QuickSelect swaps elements in the data provided so that the first k elements
(i.e. the elements occuping indices 0, 1, ..., k-1) are the smallest k elements
in the data.
QuickSelect implements Hoare's Selection Algorithm and runs in O(n) time, so it
is asymptotically faster than sorting or other heap-like implementations for
finding the smallest k elements in a data structure.
Note that k must be in the range [0, data.Len()), otherwise the QuickSelect
method will raise an error.
*/
func QuickSelect(data Interface, k int) error {
	length := data.Len()
	if k < 1 || k > length {
		message := fmt.Sprintf("The specified index '%d' is outside of the data's range of indices [0,%d)", k, length)
		return errors.New(message)
	}

	kRatio := float64(k) / float64(length)
	if length <= naiveSelectionLengthThreshold && k <= naiveSelectionThreshold {
		naiveSelectionFinding(data, k)
	} else if kRatio <= heapSelectionKRatio && k <= heapSelectionThreshold {
		heapSelectionFinding(data, k)
	} else {
		randomizedSelectionFinding(data, 0, length-1, k)
	}

	return nil
}

// IntQuickSelect mutates the data so that the first k elements in the int
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on int slices.
func IntQuickSelect(data []int, k int) error {
	return QuickSelect(IntSlice(data), k)
}

// Float64Select mutates the data so that the first k elements in the float64
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on float64 slices.
func Float64QuickSelect(data []float64, k int) error {
	return QuickSelect(Float64Slice(data), k)
}

// StringQuickSelect mutates the data so that the first k elements in the string
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on string slices.
func StringQuickSelect(data []string, k int) error {
	return QuickSelect(StringSlice(data), k)
}

func calc(l []int, k uint64) int {
  IntQuickSelect(l, int(k))
	var sum int
  sum = 0
  if k == 0 {
    return l[len(l)-1] - l[0]
  }
  k+=1
	for _, v := range l {
		k--
		sum += v
    if k == 0 {
      break
    }
	}

	return sum
}

func main() {
  const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	input := bufio.NewScanner(os.Stdin)
	input.Buffer(buf, maxCapacity)
	input.Scan()
	num, _ := strconv.Atoi(input.Text())
  r := make([]int, num)
	for j := 0; j < num; j++ {
    input.Scan()
    sstr := strings.Split(input.Text(), " ")
    n, _ := strconv.Atoi(sstr[0])
    k, _ := strconv.Atoi(sstr[1])
    l := make([]int, 0)
		input.Scan()
		str := strings.Split(input.Text(), " ")
    for i := 0; i < n; i++ {
			v, _ := strconv.Atoi(str[i])
			l = append(l, (v))
		}
		result := calc(l, uint64(k))
    r[j] = result
	}

  for j := 0; j < num; j++ {
    fmt.Printf("%v\n", r[j])
  }

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
  "container/heap"
	"errors"
	"math/rand"
)

const (
	partitionThreshold            = 8
	naiveSelectionLengthThreshold = 100
	naiveSelectionThreshold       = 10
	heapSelectionKRatio           = 0.001
	heapSelectionThreshold        = 1e3
)

/*
A type, typically a collection, which satisfies quickselect.Interface can be
used as data in the QuickSelect method. The interface is the same as the
interface required by Go's canonical sorting package (sort.Interface).
Note that the methods require that the elements of the collection be enumerated
by an integer index.
*/
type Interface interface {
	// Len is the number of elements in the collection
	Len() int
	// Less reports whether the element with
	// index i should sort before the element with index j
	Less(i, j int) bool
	// Swap swaps the order of elements i and j
	Swap(i, j int)
}

type reverse struct {
	// This embedded Interface permits Reverse to use the methods of
	// another Interface implementation.
	Interface
}

// Less returns the opposite of the embedded implementation's Less method.
func (r reverse) Less(i, j int) bool {
	return r.Interface.Less(j, i)
}

func Reverse(data Interface) Interface {
	return &reverse{data}
}

// The IntSlice type attaches the QuickSelect interface to an array of ints. It
// implements Interface so that you can call QuickSelect(k) on any IntSlice.
type IntSlice []int

func (t IntSlice) Len() int {
	return len(t)
}

func (t IntSlice) Less(i, j int) bool {
	return t[i] > t[j]
}

func (t IntSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the IntSlice so that the first k elements in the
// IntSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t IntSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The Float64Slice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// Float64Slice.
type Float64Slice []float64

func (t Float64Slice) Len() int {
	return len(t)
}

func (t Float64Slice) Less(i, j int) bool {
	return t[i] < t[j] || isNaN(t[i]) && !isNaN(t[j])
}

func (t Float64Slice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the Float64Slice so that the first k elements in the
// Float64Slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t Float64Slice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The StringSlice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// StringSlice.
type StringSlice []string

func (t StringSlice) Len() int {
	return len(t)
}

func (t StringSlice) Less(i, j int) bool {
	return t[i] > t[j]
}

func (t StringSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the StringSlice so that the first k elements in the
// StringSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t StringSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// isNaN is a copy of math.IsNaN to avoid a dependency on the math package.
func isNaN(f float64) bool {
	return f != f
}

/*
Helper function that does all of the work for QuickSelect. This implements
Hoare's Selection Algorithm which finds the smallest k elements in an interface
in expected O(n) time.
The algorithm works by finding a random pivot element, and making sure all the
elements to the left are less than the pivot element and vice versa for
elements on the right. Recursing on this solves the selection algorithm.
*/
func randomizedSelectionFinding(data Interface, low, high, k int) {
	var pivotIndex int

	for {
		if low >= high {
			return
		} else if high-low <= partitionThreshold {
			insertionSort(data, low, high+1)
			return
		}

		pivotIndex = rand.Intn(high+1-low) + low
		pivotIndex = partition(data, low, high, pivotIndex)

		if k < pivotIndex {
			high = pivotIndex - 1
		} else if k > pivotIndex {
			low = pivotIndex + 1
		} else {
			return
		}
	}
}

// Insertion sort
func insertionSort(data Interface, a, b int) {
	for i := a + 1; i < b; i++ {
		for j := i; j > a && data.Less(j, j-1); j-- {
			data.Swap(j, j-1)
		}
	}
}

/*
This method does a run over all of the data keeps a list of the k smallest
indices that it has seen so far. At the end, it swaps those k elements and
moves them to the front.
*/
func naiveSelectionFinding(data Interface, k int) {
	smallestIndices := make([]int, k)
	for i := 0; i < k; i++ {
		smallestIndices[i] = i
	}
	resetLargestIndex(smallestIndices, data)

	for i := k; i < data.Len(); i++ {
		if data.Less(i, smallestIndices[k-1]) {
			smallestIndices[k-1] = i
			resetLargestIndex(smallestIndices, data)
		}
	}

	insertionSort(IntSlice(smallestIndices), 0, k)
	for i := 0; i < k; i++ {
		data.Swap(i, smallestIndices[i])
	}
}

/*
Takes the largest index in `indices` according to the data Interface and places
it at the end of the indices array.
*/
func resetLargestIndex(indices []int, data Interface) {
	var largestIndex = 0
	var currentLargest = indices[0]

	for i := 1; i < len(indices); i++ {
		if data.Less(currentLargest, indices[i]) {
			largestIndex = i
			currentLargest = indices[i]
		}
	}

	indices[len(indices)-1], indices[largestIndex] = indices[largestIndex], indices[len(indices)-1]
}

/*
Helper function for the selection algorithm. Returns the partitionIndex.
It goes through all elements between low and high and makes sure that the
elements in the range [low, partitionIndex) are less than the element that was
originally in the pivotIndex and that the elements in the range
[paritionIndex + 1, high] are greater than the element originally in the
pivotIndex.
*/
func partition(data Interface, low, high, pivotIndex int) int {
	partitionIndex := low
	data.Swap(pivotIndex, high)
	for i := low; i < high; i++ {
		if data.Less(i, high) {
			data.Swap(i, partitionIndex)
			partitionIndex++
		}
	}
	data.Swap(partitionIndex, high)
	return partitionIndex
}

type dataHeap struct {
	heapIndices []int
	data        Interface
}

func (h dataHeap) Len() int           { return len(h.heapIndices) }
func (h dataHeap) Less(i, j int) bool { return h.data.Less(h.heapIndices[j], h.heapIndices[i]) }
func (h dataHeap) Swap(i, j int) {
	h.heapIndices[i], h.heapIndices[j] = h.heapIndices[j], h.heapIndices[i]
}

func (h *dataHeap) Push(x interface{}) {
	h.heapIndices = append(h.heapIndices, x.(int))
}

func (h *dataHeap) Pop() interface{} {
	old := h.heapIndices
	n := len(old)
	x := old[n-1]
	h.heapIndices = old[0 : n-1]
	return x
}

/*
This method implements the heap strategy for selecting the smallest k elements.
It keeps a max-heap of the smallest k elements seen so far as we iterate over
all of the elements. It adds a new element and pops the largest element.
*/
func heapSelectionFinding(data Interface, k int) {
	heapIndices := make([]int, k)
	for i := 0; i < k; i++ {
		heapIndices[i] = i
	}

	h := &dataHeap{heapIndices, data}
	heap.Init(h)
	var currentHeapMax int
	for i := k; i < data.Len(); i++ {
		currentHeapMax = h.heapIndices[0]

		if data.Less(i, currentHeapMax) {
			heap.Push(h, i)
			heap.Pop(h)
		}
	}

	insertionSort(IntSlice(h.heapIndices), 0, len(h.heapIndices))
	for i := 0; i < len(h.heapIndices); i++ {
		data.Swap(i, h.heapIndices[i])
	}
}

/*
QuickSelect swaps elements in the data provided so that the first k elements
(i.e. the elements occuping indices 0, 1, ..., k-1) are the smallest k elements
in the data.
QuickSelect implements Hoare's Selection Algorithm and runs in O(n) time, so it
is asymptotically faster than sorting or other heap-like implementations for
finding the smallest k elements in a data structure.
Note that k must be in the range [0, data.Len()), otherwise the QuickSelect
method will raise an error.
*/
func QuickSelect(data Interface, k int) error {
	length := data.Len()
	if k < 1 || k > length {
		message := fmt.Sprintf("The specified index '%d' is outside of the data's range of indices [0,%d)", k, length)
		return errors.New(message)
	}

	kRatio := float64(k) / float64(length)
	if length <= naiveSelectionLengthThreshold && k <= naiveSelectionThreshold {
		naiveSelectionFinding(data, k)
	} else if kRatio <= heapSelectionKRatio && k <= heapSelectionThreshold {
		heapSelectionFinding(data, k)
	} else {
		randomizedSelectionFinding(data, 0, length-1, k)
	}

	return nil
}

// IntQuickSelect mutates the data so that the first k elements in the int
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on int slices.
func IntQuickSelect(data []int, k int) error {
	return QuickSelect(IntSlice(data), k)
}

// Float64Select mutates the data so that the first k elements in the float64
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on float64 slices.
func Float64QuickSelect(data []float64, k int) error {
	return QuickSelect(Float64Slice(data), k)
}

// StringQuickSelect mutates the data so that the first k elements in the string
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on string slices.
func StringQuickSelect(data []string, k int) error {
	return QuickSelect(StringSlice(data), k)
}

func calc(l []int, k uint64) int {
  IntQuickSelect(l, int(k+1))
//  fmt.Println(l)
	var sum int
  sum = 0
  if k == 0 {
    return l[len(l)-1] - l[0]
  }
  k+=1
	for _, v := range l {
		k--
		sum += v
    if k == 0 {
      break
    }
	}

	return sum
}

func main() {
  const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	input := bufio.NewScanner(os.Stdin)
	input.Buffer(buf, maxCapacity)
	input.Scan()
	num, _ := strconv.Atoi(input.Text())
  r := make([]int, num)
	for j := 0; j < num; j++ {
    input.Scan()
    sstr := strings.Split(input.Text(), " ")
    n, _ := strconv.Atoi(sstr[0])
    k, _ := strconv.Atoi(sstr[1])
    l := make([]int, 0)
		input.Scan()
		str := strings.Split(input.Text(), " ")
    for i := 0; i < n; i++ {
			v, _ := strconv.Atoi(str[i])
			l = append(l, (v))
		}
		result := calc(l, uint64(k))
    r[j] = result
	}

  for j := 0; j < num; j++ {
    fmt.Printf("%v\n", r[j])
  }

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
  "container/heap"
	"errors"
	"math/rand"
)

const (
	partitionThreshold            = 8
	naiveSelectionLengthThreshold = 100
	naiveSelectionThreshold       = 10
	heapSelectionKRatio           = 0.001
	heapSelectionThreshold        = 1e3
)

/*
A type, typically a collection, which satisfies quickselect.Interface can be
used as data in the QuickSelect method. The interface is the same as the
interface required by Go's canonical sorting package (sort.Interface).
Note that the methods require that the elements of the collection be enumerated
by an integer index.
*/
type Interface interface {
	// Len is the number of elements in the collection
	Len() int
	// Less reports whether the element with
	// index i should sort before the element with index j
	Less(i, j int) bool
	// Swap swaps the order of elements i and j
	Swap(i, j int)
}

type reverse struct {
	// This embedded Interface permits Reverse to use the methods of
	// another Interface implementation.
	Interface
}

// Less returns the opposite of the embedded implementation's Less method.
func (r reverse) Less(i, j int) bool {
	return r.Interface.Less(j, i)
}

func Reverse(data Interface) Interface {
	return &reverse{data}
}

// The IntSlice type attaches the QuickSelect interface to an array of ints. It
// implements Interface so that you can call QuickSelect(k) on any IntSlice.
type IntSlice []int

func (t IntSlice) Len() int {
	return len(t)
}

func (t IntSlice) Less(i, j int) bool {
	return t[i] < t[j]
}

func (t IntSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the IntSlice so that the first k elements in the
// IntSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t IntSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The Float64Slice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// Float64Slice.
type Float64Slice []float64

func (t Float64Slice) Len() int {
	return len(t)
}

func (t Float64Slice) Less(i, j int) bool {
	return t[i] < t[j] || isNaN(t[i]) && !isNaN(t[j])
}

func (t Float64Slice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the Float64Slice so that the first k elements in the
// Float64Slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t Float64Slice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// The StringSlice type attaches the QuickSelect interface to an array of
// float64s. It implements Interface so that you can call QuickSelect(k) on any
// StringSlice.
type StringSlice []string

func (t StringSlice) Len() int {
	return len(t)
}

func (t StringSlice) Less(i, j int) bool {
	return t[i] > t[j]
}

func (t StringSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}

// QuickSelect(k) mutates the StringSlice so that the first k elements in the
// StringSlice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect
func (t StringSlice) QuickSelect(k int) error {
	return QuickSelect(t, k)
}

// isNaN is a copy of math.IsNaN to avoid a dependency on the math package.
func isNaN(f float64) bool {
	return f != f
}

/*
Helper function that does all of the work for QuickSelect. This implements
Hoare's Selection Algorithm which finds the smallest k elements in an interface
in expected O(n) time.
The algorithm works by finding a random pivot element, and making sure all the
elements to the left are less than the pivot element and vice versa for
elements on the right. Recursing on this solves the selection algorithm.
*/
func randomizedSelectionFinding(data Interface, low, high, k int) {
	var pivotIndex int

	for {
		if low >= high {
			return
		} else if high-low <= partitionThreshold {
			insertionSort(data, low, high+1)
			return
		}

		pivotIndex = rand.Intn(high+1-low) + low
		pivotIndex = partition(data, low, high, pivotIndex)

		if k < pivotIndex {
			high = pivotIndex - 1
		} else if k > pivotIndex {
			low = pivotIndex + 1
		} else {
			return
		}
	}
}

// Insertion sort
func insertionSort(data Interface, a, b int) {
	for i := a + 1; i < b; i++ {
		for j := i; j > a && data.Less(j, j-1); j-- {
			data.Swap(j, j-1)
		}
	}
}

/*
This method does a run over all of the data keeps a list of the k smallest
indices that it has seen so far. At the end, it swaps those k elements and
moves them to the front.
*/
func naiveSelectionFinding(data Interface, k int) {
	smallestIndices := make([]int, k)
	for i := 0; i < k; i++ {
		smallestIndices[i] = i
	}
	resetLargestIndex(smallestIndices, data)

	for i := k; i < data.Len(); i++ {
		if data.Less(i, smallestIndices[k-1]) {
			smallestIndices[k-1] = i
			resetLargestIndex(smallestIndices, data)
		}
	}

	insertionSort(IntSlice(smallestIndices), 0, k)
	for i := 0; i < k; i++ {
		data.Swap(i, smallestIndices[i])
	}
}

/*
Takes the largest index in `indices` according to the data Interface and places
it at the end of the indices array.
*/
func resetLargestIndex(indices []int, data Interface) {
	var largestIndex = 0
	var currentLargest = indices[0]

	for i := 1; i < len(indices); i++ {
		if data.Less(currentLargest, indices[i]) {
			largestIndex = i
			currentLargest = indices[i]
		}
	}

	indices[len(indices)-1], indices[largestIndex] = indices[largestIndex], indices[len(indices)-1]
}

/*
Helper function for the selection algorithm. Returns the partitionIndex.
It goes through all elements between low and high and makes sure that the
elements in the range [low, partitionIndex) are less than the element that was
originally in the pivotIndex and that the elements in the range
[paritionIndex + 1, high] are greater than the element originally in the
pivotIndex.
*/
func partition(data Interface, low, high, pivotIndex int) int {
	partitionIndex := low
	data.Swap(pivotIndex, high)
	for i := low; i < high; i++ {
		if data.Less(i, high) {
			data.Swap(i, partitionIndex)
			partitionIndex++
		}
	}
	data.Swap(partitionIndex, high)
	return partitionIndex
}

type dataHeap struct {
	heapIndices []int
	data        Interface
}

func (h dataHeap) Len() int           { return len(h.heapIndices) }
func (h dataHeap) Less(i, j int) bool { return h.data.Less(h.heapIndices[j], h.heapIndices[i]) }
func (h dataHeap) Swap(i, j int) {
	h.heapIndices[i], h.heapIndices[j] = h.heapIndices[j], h.heapIndices[i]
}

func (h *dataHeap) Push(x interface{}) {
	h.heapIndices = append(h.heapIndices, x.(int))
}

func (h *dataHeap) Pop() interface{} {
	old := h.heapIndices
	n := len(old)
	x := old[n-1]
	h.heapIndices = old[0 : n-1]
	return x
}

/*
This method implements the heap strategy for selecting the smallest k elements.
It keeps a max-heap of the smallest k elements seen so far as we iterate over
all of the elements. It adds a new element and pops the largest element.
*/
func heapSelectionFinding(data Interface, k int) {
	heapIndices := make([]int, k)
	for i := 0; i < k; i++ {
		heapIndices[i] = i
	}

	h := &dataHeap{heapIndices, data}
	heap.Init(h)
	var currentHeapMax int
	for i := k; i < data.Len(); i++ {
		currentHeapMax = h.heapIndices[0]

		if data.Less(i, currentHeapMax) {
			heap.Push(h, i)
			heap.Pop(h)
		}
	}

	insertionSort(IntSlice(h.heapIndices), 0, len(h.heapIndices))
	for i := 0; i < len(h.heapIndices); i++ {
		data.Swap(i, h.heapIndices[i])
	}
}

/*
QuickSelect swaps elements in the data provided so that the first k elements
(i.e. the elements occuping indices 0, 1, ..., k-1) are the smallest k elements
in the data.
QuickSelect implements Hoare's Selection Algorithm and runs in O(n) time, so it
is asymptotically faster than sorting or other heap-like implementations for
finding the smallest k elements in a data structure.
Note that k must be in the range [0, data.Len()), otherwise the QuickSelect
method will raise an error.
*/
func QuickSelect(data Interface, k int) error {
	length := data.Len()
	if k < 1 || k > length {
		message := fmt.Sprintf("The specified index '%d' is outside of the data's range of indices [0,%d)", k, length)
		return errors.New(message)
	}

	kRatio := float64(k) / float64(length)
	if length <= naiveSelectionLengthThreshold && k <= naiveSelectionThreshold {
		naiveSelectionFinding(data, k)
	} else if kRatio <= heapSelectionKRatio && k <= heapSelectionThreshold {
		heapSelectionFinding(data, k)
	} else {
		randomizedSelectionFinding(data, 0, length-1, k)
	}

	return nil
}

// IntQuickSelect mutates the data so that the first k elements in the int
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on int slices.
func IntQuickSelect(data []int, k int) error {
	return QuickSelect(IntSlice(data), k)
}

// Float64Select mutates the data so that the first k elements in the float64
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on float64 slices.
func Float64QuickSelect(data []float64, k int) error {
	return QuickSelect(Float64Slice(data), k)
}

// StringQuickSelect mutates the data so that the first k elements in the string
// slice are the k smallest elements in the slice. This is a convenience
// method for QuickSelect on string slices.
func StringQuickSelect(data []string, k int) error {
	return QuickSelect(StringSlice(data), k)
}

func calc(l []int, k uint64) int {
  IntQuickSelect(l, int(k+1))
	var sum int
  sum = 0
  if k == 0 {
    return l[len(l)-1] - l[0]
  }
  k+=1
	for _, v := range l {
		k--
		sum += v
    if k == 0 {
      break
    }
	}

	return sum
}

func main() {
  const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	input := bufio.NewScanner(os.Stdin)
	input.Buffer(buf, maxCapacity)
	input.Scan()
	num, _ := strconv.Atoi(input.Text())
  r := make([]int, num)
	for j := 0; j < num; j++ {
    input.Scan()
    sstr := strings.Split(input.Text(), " ")
    n, _ := strconv.Atoi(sstr[0])
    k, _ := strconv.Atoi(sstr[1])
    l := make([]int, 0)
		input.Scan()
		str := strings.Split(input.Text(), " ")
    for i := 0; i < n; i++ {
			v, _ := strconv.Atoi(str[i])
			l = append(l, (v))
		}
		result := calc(l, uint64(k))
    r[j] = result
	}

  for j := 0; j < num; j++ {
    fmt.Printf("%v\n", r[j])
  }

}


package main

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

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

func solve() {
	_, v := _readArr()
	s := []rune(_readStr())
	m := make(map[int]rune)

	for i, x := range v {
		r, ok := m[x]
		if ok {
			if r != s[i] {
				_print("NO")
				return
			}
		} else {
			m[x] = s[i]
		}
	}

	_print("YES")
}

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

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 int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a { fmt.Fscan(r, &a[i]) }

		var s string
		fmt.Fscan(r, &s)

		mm := make([]int, 51)
		res := "YES"

		for i := range a {
			if mm[a[i]] == 0 {
				mm[a[i]] = int(s[i])
			} else if mm[a[i]] != int(s[i]) {
				res = "NO"
				break
			}
		}

		fmt.Fprintln(w, res)
	}

}

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 int
    scan(&n)
    a := make([]int, n, n)
    m := make(map[int]rune)
    for i := range a {
      scan(&a[i])
    }
    var s string
    scan(&s)
    for i, c := range s {
      if _, ok := m[a[i]]; !ok { m[a[i]] = c }
    }
    var res string
    for i := range a { res += string(m[a[i]]) }
    pf("%s\n", ys(res == s))
	}
}

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

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func solve(a []int, s string) {
	n := len(a)
	hash3 := map[int]byte{}
	var dfs func(u int) bool
	dfs = func(u int) bool {
		if u == n {
			return true
		}

		if v, ok := hash3[a[u]]; ok {
			if v == s[u] {
				if dfs(u + 1) {
					return true
				}
			} else {
				return false
			}
		} else {
			hash3[a[u]] = s[u]
			if dfs(u + 1) {
				return true
			}
			delete(hash3, a[u])
		}
		return false
	}

	if dfs(0) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		s := ""
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Fscan(reader, &s)
		solve(a, s)
	}
}

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

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

func isTransformed(nums []int, str string) string {
  if len(nums) < 2 {
    return "YES"
  }

  mymap := make(map[int]byte)
  for idx, num := range nums {
    val, ok := mymap[num]
    if !ok {
      mymap[num] = str[idx]
    } else {
      if val != str[idx] {
        return "NO"
      }
    }
  }

  return "YES"
}

func main() {
  var test int
  fmt.Fscanf(reader, "%d\n", &test)
  for test > 0 {
    var size int
    fmt.Fscanf(reader, "%d\n", &size)

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

    var str string
    fmt.Fscanf(reader, "%s\n", &str)

    fmt.Println(isTransformed(nums, str))
    test--
  }
}

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, _ = reader.ReadString('\n')
		text = strings.Replace(text, "\r\n", "", -1)
		raw := strings.Split(text, " ")
		text, _ = reader.ReadString('\n')
		word := strings.Replace(text, "\r\n", "", -1)
		//replaced := make([]string, 0)
		hash := make(map[string]uint8)
		can := true
	out:
		for i, s := range raw {
			if hash[s] == 0 {
				hash[s] = word[i]
			} else if hash[s] != word[i] {
				can = false
				break out
			}
		}
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

func main() {
	var (
		n, k int
		str  string
	)
	fmt.Scan(&k)
	for j := 0; j < k; j++ {
		fmt.Scan(&n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&nums[i])
		}
		fmt.Scan(&str)
		corr := map[int]uint8{}
		flag := true
		for i, el := range nums {
			if cor, ok := corr[el]; ok {
				if str[i] != cor {
					flag = false
					break
				}
			} else {
				corr[el] = str[i]
			}
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

func main() {
	defer writer.Flush()
	var t, n int
	var a []int
	var m map[int]rune
	var runes []rune
	var word, res string

	scanws(&t)
	for t > 0 {
		res = ""
		m = map[int]rune{}
		scanws(&n)
		a = make([]int, n)
		for i := range a {
			scanws(&a[i])
		}
		scanws(&word)
		runes = []rune(word)
		for i, r := range runes {
			if _, ok := m[a[i]]; !ok {
				m[a[i]] = r
			}
		}
		for i := range a {
			res += string(m[a[i]])
		}
		printf("%s\n", yesNoMap(word == res))
		t--
	}
}

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanws(a ...interface{}) { fmt.Fscan(reader, a...) }

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 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_1(os.Stdin, os.Stdout)
}

package main

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

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

func solve() {
    var n int
    Fscan(in, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        Fscan(in, &a[i])
    }

    var s string
    Fscan(in, &s)

    mp := make(map[int]string)
    for i := 0; i < n; i++ {
        if v, has := mp[a[i]]; has {
            if string(s[i]) != v {
                Fprintln(out, "NO")
                return
            }
        } else {
            mp[a[i]] = string(s[i])
        }
    }

    Fprintln(out, "YES")
}

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 int
		var s string
		fmt.Fscan(in, &n)

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		fmt.Fscan(in, &s)
		bb := make([]int, 51)
		for i := range bb {
			bb[i] = -1
		}

		f := true
		for i := range aa {
			ch := int(s[i] - 'a')
			if bb[aa[i]] >= 0 && bb[aa[i]] != ch {
				f = false
				break
			}
			bb[aa[i]] = ch
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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 := nextInt()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
		}
		s := nextString()
		flag := true
		for i := 0; i < n && flag; i++ {
			for j := 0; j < n; j++ {
				if a[i] == a[j] && s[i] != s[j] {
					flag = false
					break
				}
			}
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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 int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	var str string
	fmt.Fscan(in, &str)
	mp := make(map[int]byte)
	for i := range arr {
		val, ok := mp[arr[i]]
		if !ok {
			mp[arr[i]] = str[i]
		} else if val != str[i] {
			fmt.Fprintln(out, "NO")
			return
		}
	}
	fmt.Fprintln(out, "YES")
}

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

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

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

		var s string
		fmt.Fscan(in, &s)

		f := true
		mp := make(map[int]byte)
		for i := 0; i < n; i++ {
			if v, has := mp[a[i]]; has {
				if s[i] != v {
					f = false
					break
				}
			} else {
				mp[a[i]] = s[i]
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

	out.Flush()
}

package main

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

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

func solve() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	var s string
	fmt.Fscan(in, &s)

	mp := make(map[int]byte)
	for i := 0; i < n; i++ {
		if v, has := mp[a[i]]; has {
			if s[i] != v {
				fmt.Fprintln(out, "NO")
				return
			}
		} else {
			mp[a[i]] = s[i]
		}
	}

	fmt.Fprintln(out, "YES")
}

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

package main

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

func solve(l int, arr *[]int, str *string) string {
	h := make(map[int]byte)

	for i := 0; i < l; i++ {
		if v, ok := h[(*arr)[i]]; !ok {
			h[(*arr)[i]] = (*str)[i]
		} else {
			if v != (*str)[i] {
				return "NO"
			}
		}
	}

	return "YES"
}

func main() {
	n := readInt()

	for i := 0; i < n; i++ {
		l := readInt()
		arr := make([]int, l)
		arr = readInts()
		str := readString()
		writeLine(solve(l, &arr, &str))
	}

	// tests := []struct {
	// 	l      int
	// 	arr    []int
	// 	str    string
	// 	result string
	// }{
	// 	{
	// 		l:      5,
	// 		arr:    []int{2, 3, 2, 4, 1},
	// 		str:    "cacta",
	// 		result: "YES",
	// 	},
	// 	{
	// 		l:      4,
	// 		arr:    []int{1, 2, 2, 1},
	// 		str:    "aaab",
	// 		result: "NO",
	// 	},
	// }

	// for _, tt := range tests {
	// 	fmt.Println(tt.result == solve(tt.l, &tt.arr, &tt.str))
	// }

	return
}

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}

func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}

func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}

func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}

func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}

func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}

func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}

func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

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 int
		fmt.Fscan(r, &n)

		A := make([]int, n)

		for i := range A {
			fmt.Fscan(r, &A[i])
		}

		var s string
		fmt.Fscan(r, &s)

		m := make(map[int]string)

		res := "YES"

		for i := range A {
			//val, ok := m[A[i]]
			//if ok {
			//	if val != string(s[i]) {
			//		res = "NO"
			//		break
			//	}
			//} else {
			//	m[A[i]] = string(s[i])
			//}

			if m[A[i]] == "" {
				m[A[i]] = string(s[i])
			} else if m[A[i]] != string(s[i]) {
				res = "NO"
				break
			}
		}

		fmt.Fprintln(w, res)
	}
}

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 int
		fmt.Fscan(r, &n)

		A := make([]int, n)

		for i := range A {
			fmt.Fscan(r, &A[i])
		}

		var s string
		fmt.Fscan(r, &s)

		m := make(map[int]string)

		res := "YES"

		for i := range A {
			val, ok := m[A[i]]
			if ok {
				if val != string(s[i]) {
					res = "NO"
					break
				}
			} else {
				m[A[i]] = string(s[i])
			}
		}

		fmt.Fprintln(w, res)
	}
}

package main
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 int
		fmt.Fscan(in,&n)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		var word string
		fmt.Fscan(in,&word)
		for j:=0;j<n;j++{
			for k:=j+1;k<n;k++{
				if list[j] == list[k] {
					if string(word[k]) != string(word[j]) {
						fmt.Fprintln(out,"NO")
						goto out
					}
				}
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

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

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

	var (
		testcases int
	)

	fmt.Fscan(r, &testcases)
	for testcases > 0 {
		testcases -= 1

		var n int
		fmt.Fscan(r, &n)

		var mapper map[int]byte = make(map[int]byte)

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

		var s string
		fmt.Fscan(r, &s)

		// do the work
		var ret string = "YES"
		for iterator, item := range arr {
			if val, ok := mapper[item]; !ok {
				mapper[item] = s[iterator]
			} else {
				if val != s[iterator] {
					ret = "NO"
				}
			}
		}

		fmt.Fprintln(w, ret)

	}
}

package main

import "fmt"

func solve() {
    var n int
    fmt.Scan(&n)

    var arr = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&arr[i])
    }

    var str string
    fmt.Scan(&str)

    var charmap [50]int
    for i:= 0; i < n; i++ {
        var char int = (int(str[i]) - int('a') + 1)
        if charmap[arr[i]-1] == 0 {
            charmap[arr[i]-1] = char
        } else if charmap[arr[i]-1] != char {
            fmt.Println("NO")
            return
        }
    }

    fmt.Println("YES")
}

func main() {
    var t int
    fmt.Scan(&t)

    for i := 0; i < t; i++ {
        solve()
    }
}

package main

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

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

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

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

type set struct {
	elements []rune
}

func (s set) add(elem rune) set {
	for _, i := range s.elements {
		if i == elem {
			return s
		}
	}
	s.elements = append(s.elements, elem)
	return s
}

func (s set) len() int {
	return len(s.elements)
}

func main() {
	test := numberFromConsole()
	for t := 0; t < test; t++ {
		n := numberFromConsole()
		a := sliceIntFromConsole()
		encoded, _ := reader.ReadString('\n')
		encoded = trim(encoded)

		codes := make(map[int]set, n)
		for i, e := range encoded {
			codes[a[i]] = codes[a[i]].add(e)
		}

		impossible := false
		for _, v := range codes {
			if v.len() != 1 {
				impossible = true
				break
			}
		}

		if impossible {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		nums := make([]int, n)
		var s string

		for j := 0; j < n; j++ {
			fmt.Scan(&nums[j])
		}
		fmt.Scan(&s)

		flag := true
		m := make(map[int]byte)
		for j := 0; j < n; j++ {
			v, exist := m[nums[j]]
			if !exist {
				m[nums[j]] = s[j]
				continue
			}

			if v != s[j] {
				flag = false
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var testNum int
	fmt.Fscan(in, &testNum)

	for i := 0; i < testNum; i++ {
		var sliceLen int
		fmt.Fscan(in, &sliceLen)

		var a []int
		for ii := 0; ii < sliceLen; ii++ {
			x := 0
			fmt.Fscan(in, &x)
			a = append(a, x)
		}

		var s string
		fmt.Fscan(in, &s)
		ans := true

		m := map[int]string{} // alpahbet - num
		for ii := 0; ii < sliceLen; ii++ {
			al := string(s[ii])

			if v, ok := m[a[ii]]; ok {
				if v != al {
					ans = false
					break
				}
			} else {
				m[a[ii]] = al
			}
		}

		// 12211
		// abbaa
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func (in *CF1744A) 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 *CF1744A) load() {
  if len(in.split) <= in.index {
    in.split = strings.Split(in.GetLine(), in.separator)
    in.index = 0
  }
}

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

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

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

/**
Run solve the problem CF1744A
Date: 10/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1744/A
Problem: CF1744A
**/
func (in *CF1744A) Run() {
  for t := in.NextInt(); t > 0; t-- {
    n := in.NextInt()
    mapa := make(map[int][]int)
    arr := make([]int, n)
    for i := 0; i < n; i++ {
      val := in.NextInt()
      if _, e := mapa[val]; !e {
        mapa[val] = []int{}
      }
      mapa[val] = append(mapa[val], i)
      arr[i] = val
    }

    str := in.NextString()
    ans := true
    for i := 0; i < n; i++ {
      p := mapa[arr[i]]
      x := uint8(0)
      for j := 0; j < len(p); j++ {
        if x == uint8(0) {
          x = str[p[j]]
        } else if x != str[p[j]] {
          ans = false
          break
        }
      }
    }

    if ans {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

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

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

package main

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

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

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

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

		var s string
		fmt.Fscan(in, &s)

		f := true
		mp := make(map[int]byte)

		for i := 0; i < n; i++ {
			if v, has := mp[a[i]]; has {
				if s[i] != v {
					fmt.Fprintln(out, "NO")
					f = false
					break
				}
			} else {
				mp[a[i]] = s[i]
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

	out.Flush()
}

package main

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

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

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

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

		var s string
		fmt.Fscan(in, &s)

		mp := make(map[int]byte)
		for i := 0; i < n; i++ {
			if v, has := mp[a[i]]; has {
				if s[i] != v {
					fmt.Fprintln(out, "NO")
				}
			} else {
				mp[a[i]] = s[i]
			}
		}

		fmt.Fprintln(out, "YES")
	}

	out.Flush()
}

package main

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

func main() {
	var in = bufio.NewReader(os.Stdin)
	var out = bufio.NewWriter(os.Stdout)
	var T int
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		var s string
		fmt.Fscan(in, &s)

		mp := make(map[int]byte)
		for i := 0; i < n; i++ {
			if v, has := mp[a[i]]; has {
				if s[i] != v {
					fmt.Fprintln(out, "NO")
					return
				}
			} else {
				mp[a[i]] = s[i]
			}
		}

		fmt.Fprintln(out, "YES")
	}
	out.Flush()
}

package main

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

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

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

		var s string
		fmt.Fscan(in, &s)

		mp := make(map[int]byte)
		for i := 0; i < n; i++ {
			if v, has := mp[a[i]]; has {
				if s[i] != v {
					fmt.Fprintln(out, "NO")
					return
				}
			} else {
				mp[a[i]] = s[i]
			}
		}

		fmt.Fprintln(out, "YES")
	}

	out.Flush()
}


package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func getI() int {
  return int(getI64())
}

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

var (
	unread int
	messageCount int
	queues [300001][]int
	joinedQueue []Message
)

type Message struct {
	app int
	idx int
}

func main()  {

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	_, q := getI(), getI()
	messageCount = 1
	for opNo := 0; opNo < q; opNo++ {
		command, i := getI(), getI()
		if command == 1 {
			joinedQueue = append(joinedQueue, Message{app: i, idx: messageCount})
			queues[i] = append(queues[i], messageCount)
			messageCount += 1
			unread += 1
		} else if command == 2 {
			unread -= len(queues[i])
			queues[i] = make([]int, 0)
		} else {
			for len(joinedQueue) > 0 && joinedQueue[0].idx <= i {
				message := joinedQueue[0]
				joinedQueue = joinedQueue[1:]
				if  len(queues[message.app]) > 0 && queues[message.app][0] == message.idx {
					queues[message.app] = queues[message.app][1:]
					unread -= 1
				}
			}
		}

		writer.WriteString(strconv.Itoa(unread))
		writer.WriteByte('\n')
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/704/problem/A

package main

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

type Query struct {
	QueryType int
	Value     int
}

type Event struct {
	Index int
	App   int
}

func Solve(n int, q int, queries []Query) []int {
	queues := make([][]int, n)
	events := []Event{}
	unread := 0
	ans := make([]int, q)
	eventCount := 0
	for i, q := range queries {
		if q.QueryType == 1 {
			eventCount += 1
			unread += 1
			queues[q.Value-1] = append(queues[q.Value-1], eventCount)
			events = append(events, Event{eventCount, q.Value})
		} else if q.QueryType == 2 {
			unread -= len(queues[q.Value-1])
			queues[q.Value-1] = []int{}
		} else {
			for len(events) > 0 && events[0].Index <= q.Value {
				event := events[0]
				events = events[1:]
				if len(queues[event.App-1]) > 0 && queues[event.App-1][0] == event.Index {
					unread -= 1
					queues[event.App-1] = queues[event.App-1][1:]
				}
			}
		}
		ans[i] = unread
	}
	return ans
}

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

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

	ans := Solve(n, q, queries)
	for _, elem := range ans {
		fmt.Fprintf(writer, "%d\n", elem)
	}
}

package main

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

const maxn = 500005

var n, q, res, pos, tot int
var cnt, viewed, which, moved [maxn]int

func gen(x int) {
	res++
	cnt[x]++
	tot++
	which[tot] = x
}

func read(x int) {
	res -= (cnt[x] - viewed[x])
	viewed[x] = cnt[x]
}

func first(t int) {
	for pos < t {
		pos++
		x := which[pos]
		moved[x]++
		if moved[x] > viewed[x] {
			viewed[x]++
			res--
		}
	}
}

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

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

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	in.Scan()
	q, _ = strconv.Atoi(in.Text())

	for i := 1; i <= n; i++ {
		cnt[i] = 0
		viewed[i] = 0
		moved[i] = 0
	}

	var kind, x, t int

	pos = 0
	tot = 0

	for i := 1; i <= q; i++ {
		in.Scan()
		kind, _ = strconv.Atoi(in.Text())

		if kind == 1 {
			in.Scan()
			x, _ = strconv.Atoi(in.Text())
			gen(x)
		} else if kind == 2 {
			in.Scan()
			x, _ = strconv.Atoi(in.Text())
			read(x)
		} else {
			in.Scan()
			t, _ = strconv.Atoi(in.Text())
			first(t)
		}

		out.WriteString(strconv.Itoa(res))
		out.WriteByte('\n')
	}
}

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func getI() int {
  return int(getI64())
}

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

type State struct {
	bookCount int
	shelfIdxs []int
}

type Command struct {
	command int

}

type Node struct {
	opNo     int
	children []*Node
}

func (node *Node) visit () {
	//fmt.Println("HELLO", node.opNo, node.children)
	for _, child := range node.children {
		command := commands[child.opNo - 1]

		if command[0] == 1 {
			i, j := command[1], command[2]
			if !shelves[i][j] {
				bookCount[child.opNo] = bookCount[child.opNo - 1] + 1
				shelves[i][j] = true
				child.visit()
				shelves[i][j]= false
			} else {
				bookCount[child.opNo] = bookCount[child.opNo - 1]
				child.visit()
			}
		} else if command[0] == 2 {
			i, j := command[1], command[2]
			if shelves[i][j] {
				bookCount[child.opNo] = bookCount[child.opNo - 1] - 1
				shelves[i][j] = false
				child.visit()
				shelves[i][j] = true
			} else {
				bookCount[child.opNo] = bookCount[child.opNo - 1]
				child.visit()
			}
		} else if command[0] == 3 {
			i := command[1]
			newBookCount := 0
			for idx:=0; idx < m; idx++ {
				if shelves[i][idx] { shelves[i][idx] = false } else {
					shelves[i][idx] = true
					newBookCount += 1
				}
			}

			bookCount[child.opNo] = bookCount[child.opNo - 1] - (m - newBookCount) + newBookCount
			child.visit()

			for idx:=0; idx < m; idx++ {
				shelves[i][idx] = !shelves[i][idx]
			}

		} else if command[0] == 4 {
			stateNo := command[1]
			bookCount[child.opNo] = bookCount[stateNo]
			child.visit()
		}
	}
}

var (
	m, n, q int
	commands [100001][]int
	bookCount [100001]int
	shelves [1000][1000]bool
	nodes [100001]*Node
)

func main()  {

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n = getI()
	m = getI()
	q = getI()

	bookCount[0] = 0
	nodes[0] = &Node{opNo: 0, children:make([]*Node, 0)}

	for opNo := 0; opNo < q; opNo++ {
		command := getI()
		if command == 1 {
			commands[opNo] = []int{command, getI() - 1, getI() - 1}
			node := &Node{opNo: opNo+1, children:make([]*Node, 0)}
			nodes[opNo + 1] = node
			nodes[opNo].children = append(nodes[opNo].children, node)
		} else if command == 2 {
			commands[opNo] = []int{command, getI() - 1, getI() - 1}
			node := &Node{opNo: opNo+1, children:make([]*Node, 0)}
			nodes[opNo + 1] = node
			nodes[opNo].children = append(nodes[opNo].children, node)
		} else if command == 3 {
			commands[opNo] = []int{command, getI() - 1}
			node := &Node{opNo: opNo+1, children:make([]*Node, 0)}
			nodes[opNo + 1] = node
			nodes[opNo].children = append(nodes[opNo].children, node)
		} else {
			stateNo := getI()
			commands[opNo] = []int{command, stateNo}
			node := &Node{opNo: opNo+1, children:make([]*Node, 0)}
			nodes[opNo + 1] = node
			nodes[stateNo].children = append(nodes[stateNo].children, node)
		}
	}

	nodes[0].visit()

	for i:=1; i<=q; i++{
		writer.WriteString(strconv.Itoa(bookCount[i]))
		writer.WriteByte('\n')
	}
}

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func getI() int {
  return int(getI64())
}

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

var (
	unread int
	messageCount int
	queues [300001][]int
	joinedQueue []Message
)

type Message struct {
	app int
	idx int
}

func main()  {

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	_, q := getI(), getI()
	messageCount = 1
	for opNo := 0; opNo < q; opNo++ {
		command, i := getI(), getI()
		if command == 1 {
			joinedQueue = append(joinedQueue, Message{app: i, idx: messageCount})
			queues[i] = append(queues[i], messageCount)
			messageCount += 1
			unread += 1
		} else if command == 2 {
			unread -= len(queues[i])
			queues[i] = make([]int, 0)
		} else {
			for ((len(joinedQueue) > 0) && joinedQueue[len(joinedQueue) - 1].idx >= messageCount - i) {
				message := joinedQueue[len(joinedQueue) - 1]
				if len(queues[message.app]) > 0 && queues[message.app][len(queues[message.app]) - 1] == message.idx {
					queues[message.app] = queues[message.app][:len(queues[message.app]) - 1]
					unread -= 1
				}
				joinedQueue = joinedQueue[:len(joinedQueue) - 1]
			}
		}
		writer.WriteString(strconv.Itoa(unread))
		writer.WriteByte('\n')
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/704/problem/A

package main

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

type Query struct {
	QueryType int
	Value     int
}

type Event struct {
	Index int
	App   int
}

func Solve(n int, q int, queries []Query) []int {
	queues := make([][]int, n)
	events := []Event{}
	unread := 0
	ans := make([]int, q)
	for i, q := range queries {
		if q.QueryType == 1 {
			unread += 1
			queues[q.Value-1] = append(queues[q.Value-1], i+1)
			events = append(events, Event{len(events) + 1, q.Value})
		} else if q.QueryType == 2 {
			unread -= len(queues[q.Value-1])
			queues[q.Value-1] = []int{}
		} else {
			for len(events) > 0 && events[0].Index <= q.Value {
				event := events[0]
				events = events[1:]
				if len(queues[event.App-1]) > 0 && queues[event.App-1][0] == event.Index {
					unread -= 1
					queues[event.App-1] = queues[event.App-1][1:]
				}
			}
		}
		ans[i] = unread
	}
	return ans
}

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

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

	ans := Solve(n, q, queries)
	for _, elem := range ans {
		fmt.Fprintf(writer, "%d\n", elem)
	}
}