package main

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

type Gangster struct {
	Gang, City int
}

type Pair struct {
	First, Second int
}

var t int

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

	fmt.Fscan(input, &t)

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

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

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

		ans := make([]Pair, 0)
		var last int

		for i := (n - 1); i >= 0; i-- {
			if arr[i].Gang == arr[0].Gang {
				last = i - 1
				break
			}

			var p Pair
			p.First = arr[0].City
			p.Second = arr[i].City

			ans = append(ans, p)
		}

		if len(ans) == 0 || last < 0 {
			fmt.Println("NO")
			continue
		}

		for i := last; i >= 0; i-- {
			var p Pair
			p.First = arr[i].City
			p.Second = arr[n-1].City
			ans = append(ans, p)
		}

		fmt.Println("YES")
		l := len(ans)
		for i := 0; i < l; i++ {
			fmt.Printf("%d %d\n", ans[i].First, ans[i].Second)
		}
	}
}


package main

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

type Gangster struct {
	Gang, City int
}

type Pair struct {
	First, Second int
}

var t int

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

	fmt.Fscan(input, &t)

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

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

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

		ans := make([]Pair, 0)
		var last int

		for i := (n - 1); i >= 0; i-- {
			if arr[i].Gang == arr[0].Gang {
				last = i
				break
			}

			var p Pair
			p.First = arr[0].City
			p.Second = arr[i].City

			ans = append(ans, p)
		}

		if len(ans) == 0 {
			fmt.Println("NO")
			continue
		}

		for i := last; i > 0; i-- {
			var p Pair
			p.First = arr[i].City
			p.Second = arr[n-1].City
			ans = append(ans, p)
		}

		fmt.Println("YES")
		l := len(ans)
		for i := 0; i < l; i++ {
			fmt.Printf("%d %d\n", ans[i].First, ans[i].Second)
		}
	}
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the first best position in the slice (no neighbors
// with equal value) and shifts that value to said position (also adjusts
// indexMap in a similar fashion)
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := 0; j < len(districts); j++ {
		mainCon := (j != districtIndex)
		con1 := (districts[j] != districts[districtIndex])
		edgeCon := (j == 0 || j == len(districts)-1)

		if edgeCon && mainCon && con1 {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}

		if !edgeCon {
			if mainCon && con1 && districts[j+1] != districts[districtIndex] {
				districts, _ = shiftSliceElement(districts, districtIndex, j)
				indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	sortedDistricts, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	if !sanityCheck(sortedDistricts) {
		return roadConnections, errors.New("Can't sort districts")
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the first best position in the slice (no neighbors
// with equal value) and shifts that value to said position (also adjusts
// indexMap in a similar fashion)
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := 0; j < len(districts); j++ {
		mainCon := (j != districtIndex)
		con1 := (districts[j] != districts[districtIndex])
		edgeCon := (j == 0 || j == len(districts)-1)

		if edgeCon && mainCon && con1 {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}

		if !edgeCon {
			if mainCon && con1 && districts[j+1] != districts[districtIndex] {
				districts, _ = shiftSliceElement(districts, districtIndex, j)
				indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

func sanityCheck(districts []int) bool {
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			return false
		}
	}
	return true
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the first best position in the slice (no neighbors
// with equal value) and shifts that value to said position (also adjusts
// indexMap in a similar fashion)
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := 0; j < len(districts); j++ {
		mainCon := (j != districtIndex)
		con1 := (districts[j] != districts[districtIndex])
		con2 := (districts[j+1] != districts[districtIndex])
		edgeCon := (j == 0 || j == len(districts)-1)
		if edgeCon && mainCon && con1 {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}
		if mainCon && con1 && con2 && !edgeCon {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) bool {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
		return false
	}
	if len(roadConnections) > numberDistricts[testCase]-1 {
		fmt.Println("NO")
		return false
	}
	fmt.Println("YES")
	printRoadConnections(roadConnections)
	return true
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	var err error
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]

	zip := Zipper{districts, makeRange(1, districtCount)}
	districtMap := zip.Sort()
	// fmt.Println(districtMap)
	roadConnections = connectFirstDistrict(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)
	roadConnections, err = connectRemainingDistricts(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)

	return roadConnections, err
}

func connectFirstDistrict(roadConnections [][]int, districtMap [][]int, count int) [][]int {
	for i := 1; i < count; i++ {
		if districtMap[i][0] != districtMap[0][0] {
			roadConnections = append(roadConnections, []int{districtMap[0][1], districtMap[i][1]})
		}
	}
	return roadConnections
}

func connectRemainingDistricts(roadConnections [][]int, districtMap [][]int, count int) ([][]int, error) {
	var err error
	for i := 2; i < count; i++ {
		if districtMap[0][0] != districtMap[i][0] {
			return roadConnections, err
		}
		connection, err := findNextViableConnection(districtMap, count, i)
		roadConnections = append(roadConnections, connection)
		if err != nil {
			return roadConnections, err
		}
	}
	return roadConnections, err
}

func findNextViableConnection(districtMap [][]int, count int, index int) ([]int, error) {
	var err error
	for j := index + 1; j < count; j++ {
		if districtMap[index][0] != districtMap[j][0] {
			return []int{districtMap[index][1], districtMap[j][1]}, err
		}
	}
	return []int{districtMap[index][1], districtMap[index][1]}, errors.New("Districts not connectable")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

//Zipper contains two slices where the elements are tied together
type Zipper struct {
	A, B []int
}

//Zip creates a slice with zipped elements of A and B
func (zip Zipper) Zip() [][]int {
	var zipped [][]int
	if len(zip.A) != len(zip.B) {
		panic("Can only zip slices with equal dimensions")
	}
	for i := 0; i < len(zip.A); i++ {
		zipped = append(zipped, []int{zip.A[i], zip.B[i]})
	}
	return zipped
}

//Sort A or B while keeping the elements tied together
func (zip Zipper) Sort() [][]int {
	zipped := zip.Zip()
	sort.Slice(zipped, func(i, j int) bool {
		return zipped[i][0] < zipped[j][0]
	})
	return zipped
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	fmt.Println(districts)
	return districts, indexMap, err
}

//shiftDistrict checks for the next different value from districts[districtIndex]
//and shifts this element to that index and also return adjusted indexMap
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := districtIndex + 1; j < len(districts); j++ {
		if districts[j] != districts[districtIndex] {
			districts, _ = shiftSliceElement(districts, j, districtIndex)
			indexMap, _ = shiftSliceElement(indexMap, j, districtIndex)
			return districts, indexMap, err
		}
	}
	if districts[len(districts)-1] == districts[len(districts)-2] {
		if districts[len(districts)-1] != districts[0] {
			districts, _ = shiftSliceElement(districts, len(districts)-1, 0)
			indexMap, _ = shiftSliceElement(indexMap, len(districts)-1, 0)
			return districts, indexMap, err
		}
		for j := 0; j < len(districts)-1; j++ {
			con1 := districts[j] != districts[len(districts)-1]
			con2 := districts[j+1] != districts[len(districts)-1]
			notEqualCon := districts[j] != districts[len(districts)-1]
			if con1 && con2 && notEqualCon {
				districts, _ = shiftSliceElement(districts, districts[len(districts)-1], j)
				indexMap, _ = shiftSliceElement(indexMap, indexMap[len(districts)-1], j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}


package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 4096*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the next different value from districts[districtIndex]
//and shifts this element to that index and also return adjusted indexMap
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := districtIndex + 1; j < len(districts); j++ {
		if districts[j] != districts[districtIndex] {
			districts, _ = shiftSliceElement(districts, j, districtIndex)
			indexMap, _ = shiftSliceElement(indexMap, j, districtIndex)
			return districts, indexMap, err
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = arr.Min();
            int start = 0;
            var zeroMemo = new List<int>();
            bool ir = false;
            int id = 0;
            int notzeroCnt = 0;
            int zeroCnt = 0;
            for (int i =0; i< n; i++)
            {

                if(arr[i] == round)
                {
                    start = i;
                    zeroMemo.Add(i);
                }

                if (arr[i] == 0)
                {
                    zeroCnt++;
                }
                else if (i > 0 && arr[i - 1] == 0 && arr[i] != 0)
                {
                    id = i - 1;
                    notzeroCnt++;
                }
            }

            if (arr[lastBox] == round) start = lastBox;
            else if(notzeroCnt==1)
            {
                //start = Array.IndexOf(arr, 1)-1;
                //if (notzeroCnt > lastBox - start) start = Array.IndexOf(arr,1, lastBox+1)-1;
                ir = true;
                start = id;
                if (start < 0) start = n-1;
            }
            else if (zeroMemo.Count() > 1)
            {

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            if (ir)
            {

               ans[start] = n-zeroCnt;

            }
            else if (arr[start] == 0 )
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    else if(i>start && i<lastBox) ans[i] = arr[i] - round - 1;
                    else if (i > lastBox && i < start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else if (i < lastBox &&  start <= lastBox) ans[i] = arr[i] - round;
                    else if(i < lastBox  || i==lastBox || lastBox<start) ans[i] = arr[i] - round-1;
                    //else if (i == lastBox)
                    //{
                    //    ans[i] = arr[i] - round - 1;
                    //}

                    //else if (lastBox < start && i > lastBox && i < start)
                    //{
                    //    ans[i] = arr[i] - round;
                    //}
                    //else if (lastBox < start) ans[i] = arr[i] - round - 1;
                    //else if (start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                    //else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                    else ans[i] = arr[i] - round;

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = int.MaxValue;//arr.Min();
            int start = 0; //Array.LastIndexOf(arr, round);
            var zeroMemo = new List<int>();
            for (int i =0; i< n; i++)
            {
                if(arr[i]<round)
                {
                    round = arr[i];
                    start = i;
                    zeroMemo.Clear();
                    zeroMemo.Add(i);
                }
                else if(arr[i] == round)
                {
                    start = i;
                    zeroMemo.Add(i);
                }
            }

            if (zeroMemo.Count() > 1)
            {

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }
            if (arr[lastBox] == round) start = lastBox;

            if (arr[start] == 0)
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    else if (i < lastBox)
                    {
                        if(round>0 && start<i && i<lastBox) ans[i] = arr[i] - round - 1;
                        else if (round > 0　&& start<=lastBox) ans[i] = arr[i] - round;
                        else if(round>0) ans[i] = arr[i] - round-1;
                        else ans[i] = arr[i] - 1;
                    }
                    else if (i == lastBox)
                    {
                        ans[i] = arr[i] - round - 1;
                    }
                    else if(i>lastBox && i<start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else
                    {
                        if (round > 0 && lastBox < start && i > lastBox && i < start)
                        {
                            ans[i] = arr[i] - round;
                        }
                        else if (round > 0 && lastBox < start) ans[i] = arr[i] - round - 1;
                        else if (round > 0 && start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                        else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                        else ans[i] = arr[i] - round ;

                    }

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = arr.Min();
            int start = Array.LastIndexOf(arr, round);

            var zeroMemo = new List<int>();
            if (arr.Count(c => c == round) > 1)
            {
                for (int i = 0; i < n; i++)
                {
                    if (arr[i] == round)
                    {
                        zeroMemo.Add(i);
                    }
                 }

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            //if(arr.Count(c=>c==0)>1 && lastBox< Array.LastIndexOf(arr, arr.Min()))
            //{
            //    start = Array.IndexOf(arr, round, lastBox);
            //}
            //else start = Array.LastIndexOf(arr, round);

            for (int i =0; i< n; i++)
            {
                if (i == lastBox && arr[i] == round) start = i;
            }

            if (arr[start] == 0)
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;
                }
                //for(int i =0; i< n; i++)
                //{
                //    if (i < start || i > lastBox) ans[i] = arr[i];
                //    else if (i == start)
                //    {
                //        if (lastBox > start)
                //        {
                //            ans[i] = (lastBox - start);
                //        }
                //        else
                //        {
                //            ans[i] = n - (start - lastBox);
                //        }
                //    }
                //    else ans[i] = arr[i] - 1;
                //}
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + lastBox + 1;
                        }

                    }
                    else if (i < lastBox)
                    {
                        if(round>0 && start<i && i<lastBox) ans[i] = arr[i] - round - 1;
                        else if (round > 0　&& start<=lastBox) ans[i] = arr[i] - round;
                        else if(round>0) ans[i] = arr[i] - round-1;
                        else ans[i] = arr[i] - 1;
                    }
                    else if (i == lastBox)
                    {
                        ans[i] = arr[i] - round - 1;
                    }
                    else
                    {
                        if (round > 0) ans[i] = arr[i] - round;
                        else ans[i] = arr[i] - round - 1;

                    }

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }
            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = int.MaxValue;//arr.Min();
            int start = 0; //Array.LastIndexOf(arr, round);
            var zeroMemo = new List<int>();
            for (int i =0; i< n; i++)
            {
                if(arr[i]<round)
                {
                    round = arr[i];
                    start = i;
                    zeroMemo.Clear();
                    zeroMemo.Add(i);
                }
                else if(arr[i] == round)
                {
                    start = i;
                    zeroMemo.Add(i);
                }
            }

            if (arr[lastBox] == round) start = lastBox;
            else if (zeroMemo.Count() > 1)
            {

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            if (arr[start] == 0)
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    else if (i < lastBox && start < i && i < lastBox) ans[i] = arr[i] - round - 1;
                    else if (i < lastBox &&  start <= lastBox) ans[i] = arr[i] - round;
                    else if(i < lastBox ) ans[i] = arr[i] - round-1;
                    //{
                    //    if( start<i && i<lastBox) ans[i] = arr[i] - round - 1;
                    //    else if ( start<=lastBox) ans[i] = arr[i] - round;
                    //    else ans[i] = arr[i] - 1;
                    //}
                    else if (i == lastBox)
                    {
                        ans[i] = arr[i] - round - 1;
                    }
                    else if(i>lastBox && i<start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else if (lastBox < start && i > lastBox && i < start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else if (lastBox < start) ans[i] = arr[i] - round - 1;
                    else if (start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                    else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                    else ans[i] = arr[i] - round;

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = int.MaxValue;//arr.Min();
            int start = 0; //Array.LastIndexOf(arr, round);
            var zeroMemo = new List<int>();
            for (int i =0; i< n; i++)
            {
                if(arr[i]<round)
                {
                    round = arr[i];
                    start = i;
                    zeroMemo.Clear();
                    zeroMemo.Add(i);
                }
                else if(arr[i] == round)
                {
                    start = i;
                    zeroMemo.Add(i);
                }
            }

            if (arr[lastBox] == round) start = lastBox;
            else if (zeroMemo.Count() > 1)
            {

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            if (arr[start] == 0)
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    //else if (i < lastBox &&  start <= lastBox) ans[i] = arr[i] - round;
                    else if(i < lastBox  || i==lastBox || lastBox<start) ans[i] = arr[i] - round-1;
                    //else if (i == lastBox)
                    //{
                    //    ans[i] = arr[i] - round - 1;
                    //}
                    //else if(i>lastBox && i<start)
                    //{
                    //    ans[i] = arr[i] - round;
                    //}
                    //else if (lastBox < start && i > lastBox && i < start)
                    //{
                    //    ans[i] = arr[i] - round;
                    //}
                    //else if (lastBox < start) ans[i] = arr[i] - round - 1;
                    //else if (start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                    //else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                    else ans[i] = arr[i] - round;

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = arr.Min();
            int start = 0;
            var zeroMemo = new List<int>();
            bool ir = false;
            int id = 0;
            int notzeroCnt = 0;
            int zeroCnt = 0;
            for (int i =0; i< n; i++)
            {

                if(arr[i] == round)
                {
                    start = i;
                    zeroMemo.Add(i);
                }

                if (arr[i] == 0)
                {
                    zeroCnt++;
                }
                else if (i > 0 && arr[i - 1] == 0 && arr[i] != 0)
                {
                    id = i - 1;
                    notzeroCnt++;
                }
            }

            if (arr[lastBox] == round) start = lastBox;
            else if(notzeroCnt==1 && zeroCnt>1)
            {
                //start = Array.IndexOf(arr, 1)-1;
                //if (notzeroCnt > lastBox - start) start = Array.IndexOf(arr,1, lastBox+1)-1;
                ir = true;
                start = id;
                if (start < 0) start = n-1;
            }
            else if (zeroMemo.Count() > 1)
            {

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            if (ir)
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start) ans[start] = n - zeroCnt;
                    else if (start<lastBox && i > start && i <= lastBox)
                    {
                        ans[i] = arr[i] - 1;
                    }
                    else if (start > lastBox && (i > start || i <= lastBox))
                    {
                        ans[i] = arr[i] - 1;
                    }
                    else ans[i] = arr[i];
                }
            }
            else if (arr[start] == 0 )
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    else if(i>start && i<lastBox) ans[i] = arr[i] - round - 1;
                    else if (i > lastBox && i < start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else if (i < lastBox &&  start <= lastBox) ans[i] = arr[i] - round;
                    else if(i < lastBox  || i==lastBox || lastBox<start) ans[i] = arr[i] - round-1;
                    //else if (i == lastBox)
                    //{
                    //    ans[i] = arr[i] - round - 1;
                    //}

                    //else if (lastBox < start && i > lastBox && i < start)
                    //{
                    //    ans[i] = arr[i] - round;
                    //}
                    //else if (lastBox < start) ans[i] = arr[i] - round - 1;
                    //else if (start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                    //else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                    else ans[i] = arr[i] - round;

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //int n = int.Parse(Console.ReadLine());

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //for (int i = 0; i < n; i++)
            //{
            //    input[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            //int n = int.Parse(Console.ReadLine());
            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int n = num[0];
            //int m = num[1];

            //var arr = new int[m][];

            //for(int i =0; i< m; i++)
            //{
            //    arr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //}

            var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); ;
            var arr = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            int n = num[0];
            int lastBox = num[1]-1;

            var ans = new long[n];

            long round = arr.Min();
            int start = Array.LastIndexOf(arr, round);

            var zeroMemo = new List<int>();
            if (arr.Count(c => c == round) > 1)
            {
                for (int i = 0; i < n; i++)
                {
                    if (arr[i] == round)
                    {
                        zeroMemo.Add(i);
                    }
                 }

                for (int i = 0; i < zeroMemo.Count(); i++)
                {
                    int cur = zeroMemo[i];
                    if (check(n, lastBox, cur, zeroMemo))
                    {
                        start = cur;
                        break;
                    }

                }

            }

            for (int i =0; i< n; i++)
            {
                if (i == lastBox && arr[i] == round) start = i;
            }

            if (arr[start] == 0)
            {
                int count = (lastBox > start) ? lastBox - start : n - (start-lastBox);
                int cnt = 0;
                for(int j = start;cnt<n;)
                {
                    if(j==start)
                    {
                        if (lastBox > start)
                        {
                            ans[j] = (lastBox - start);
                        }
                        else
                        {
                            ans[j] = n - (start - lastBox);
                        }
                    }
                    else if(count>=0)
                    {
                        ans[j] = arr[j] - 1;
                    }
                    else ans[j] = arr[j];
                    count--;
                    cnt++;
                    j = (j < n - 1 )? j+1 :  0;

                }

            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (i == start)
                    {
                        if (arr[i] == 0)
                        {
                            if (lastBox > start) ans[i] = lastBox - start;
                            else ans[i] = n - (start - lastBox);
                        }
                        else if (lastBox == start)
                        {
                            ans[i] = round * n;
                        }
                        else if (lastBox > start)
                        {
                            ans[i] = round * n + (lastBox - start);
                        }
                        else
                        {
                            ans[i] = round * n + (n-(start-lastBox)) ;
                        }

                    }
                    else if (i < lastBox)
                    {
                        if(round>0 && start<i && i<lastBox) ans[i] = arr[i] - round - 1;
                        else if (round > 0　&& start<=lastBox) ans[i] = arr[i] - round;
                        else if(round>0) ans[i] = arr[i] - round-1;
                        else ans[i] = arr[i] - 1;
                    }
                    else if (i == lastBox)
                    {
                        ans[i] = arr[i] - round - 1;
                    }
                    else if(i>lastBox && i<start)
                    {
                        ans[i] = arr[i] - round;
                    }
                    else
                    {
                        if (round > 0 && lastBox < start && i > lastBox && i < start)
                        {
                            ans[i] = arr[i] - round;
                        }
                        else if (round > 0 && lastBox < start) ans[i] = arr[i] - round - 1;
                        else if (round > 0 && start < lastBox && i < lastBox) ans[i] = arr[i] - round;
                        else if (start < lastBox && i > lastBox) ans[i] = arr[i] - round;
                        else ans[i] = arr[i] - round ;

                    }

                }
            }

            Console.WriteLine(string.Join(" ", ans));

            //Console.WriteLine();

            //Console.WriteLine();

        }

        public static bool check (int  n ,int last, int zero, List<int> list)
        {
            int diff = 0;
            if(last<zero)
            {
                diff = n - ( zero-last);
                for (int i = 0; i < list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur< last || cur>zero) return false;

                }
                return true;
            }
            else
            {
                diff = last - zero;
                for(int i=0; i<list.Count(); i++)
                {
                    int cur = list[i];
                    if (cur == zero) continue;
                    else if (cur > zero && cur < last) return false;

                }
                return true;

            }

        }

    }

    class Segment
    {
        public Tuple<long, int>[] arr;
        int n;

        public Segment(int n)
        {
            this.n = n * 2;
            //arr = Enumerable.Range(0, n*2).ToArray();
            arr = new Tuple<long, int>[this.n];
            for (int i = 0; i < this.n; i++)
            {
                arr[i] = Tuple.Create((long)0, 0);
            }

        }

        public void update(int i, long x, int ind)
        {
            i = (n / 2) + i - 1;
            arr[i] = Tuple.Create(x, ind);
            while (i > 0)
            {
                i = (i - 1) / 2;
                //arr[i] = Math.Max(arr[i*2+1], arr[i*2+2]);
                if (arr[i * 2 + 1].Item1 > arr[i * 2 + 2].Item1)
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 1].Item1, arr[i * 2 + 1].Item2);
                }
                else
                {
                    arr[i] = Tuple.Create(arr[i * 2 + 2].Item1, arr[i * 2 + 2].Item2);
                }

            }

        }

        //call : query(a,b, 0, 0, n)
        public long query(int a, int b, int k, int l, int r)
        {
            if (r <= a || b <= l) return int.MaxValue;
            if (a <= l && r <= b) return arr[k].Item1;
            else
            {
                long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.Max(vl, vr);
            }
        }

    }

    class UnionFind
    {
        public int[] path;

        public UnionFind(int n)
        {
            path = new int[n];

            for (int i = 0; i < n; i++)
            {
                path[i] = i;
            }

        }

        private int root(int i)
        {
            while (i != path[i])
            {
                path[i] = path[path[i]];
                i = path[i];
            }
            return i;
        }

        public bool find(int p, int q)
        {
            return root(p) == root(q);
        }

        public void unite(int p, int q)
        {
            int i = root(p);
            int j = root(q);
            path[i] = j;
        }

    }
}