package main

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

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

	solve := func(_case int) string {
		var s string
		Fscan(in, &s)
		n := len(s)
		if strings.Count(s, "0") == n || strings.Count(s, "1") == n {
			return s
		}

		//ans := []byte{}

		return strings.Repeat("10", n)
	}

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

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

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if s[i] != s[i + 2] {
				break
			}
			if i == len(s) - 3 {
				f = false
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var s string
		fmt.Fscan(in, &s)
		r, isSame := rune(s[0]), true
		for _, ru := range s {if ru != r {isSame = false; break}}
		if isSame {
		    fmt.Fprint(out, s)
		    fmt.Fprint(out, "\n")
		    continue
		}
		var concat []string
		for i:=0; i<len(s); i++ {
		    concat = append(concat, "01")
		}
		fmt.Fprint(out, strings.Join(concat, ""))
		fmt.Fprint(out, "\n")
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%s\n", sol(s))
	}
}

func sol(t string) string {
	m := map[rune]int64{}
	for _, r := range t {
		m[r]++
	}
	if m['0'] == int64(len(t)) || m['1'] == int64(len(t)) {
		return t
	}
	ret := ""
	repeat := len(t)
	for ; repeat > 0; repeat-- {
		ret += "10"
	}
	return ret
}

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

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for T := stdin.ReadInt(); T > 0; T-- {
		t := []rune(stdin.Read())

		d := map[rune]bool{}
		for _, ch := range t {
			d[ch] = true
		}
		if len(d) == 1 {
			stdout.Println(string(t))
			continue
		}

		stack := NewDeque()
		stack.AppendLast(t[0])

		x := 1
		for x < len(t) {
			ch := stack.PeekLast().(rune)
			if ch == t[x] {
				if ch == '0' {
					stack.AppendLast('1')
				} else {
					stack.AppendLast('0')
				}
			} else {
				stack.AppendLast(t[x])
				x++
			}
		}

		ans := []rune{}
		for !stack.IsEmpty() {
			ans = append(ans, stack.PopFirst().(rune))
		}
		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

import "fmt"

func main(){

	var T int
	fmt.Scanln(&T)
	for i:=0;i<T;i++{
		var str string
		fmt.Scanln(&str)
		//fmt.Println(len(str))
		c := str[0]
		var flag int
		for i:=0;i<len(str);i++{
			if str[i]!=c{
				flag = 1
			}
		}
		if flag == 1{
			for i:=0;i<len(str);i++{
				fmt.Print("01")
			}
			fmt.Println()
		}else{
			fmt.Println(str)
		}
	}
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		str := s.NextString()

		var ones int
		for _, c := range str {
			if c == '1' {
				ones++
			}
		}

		if ones == 0 || ones == len(str) {
			fmt.Println(str)
			continue
		}

		res := make([]string, len(str))
		if str[0] == '1' {
			for j := 0; j < len(str); j++ {
				res[j] = "10"
			}
		} else {
			for j := 0; j < len(str); j++ {
				res[j] = "01"
			}
		}

		fmt.Println(strings.Join(res, ""))
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

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

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1342/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscanln(input, &s)
		fmt.Println(solve(s))
	}
}

func solve(s string) string {
	z, o := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			z++
		} else {
			o++
		}
	}

	if z == 0 || o == 0 {
		return s
	}

	var buff bytes.Buffer
	buff.WriteByte(s[0])
	prev := s[0]
	i := 1
	for i < len(s) {
		if prev != s[i] {
			buff.WriteByte(s[i])
			prev = s[i]
			i++
			continue
		}
		if prev == '0' {
			prev = '1'
			o--
		} else {
			prev = '0'
			z--
		}
		buff.WriteByte(prev)
	}

	return buff.String()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1342B(_r io.Reader, _w io.Writer) {
	var t int
	var s string
	for Fscan(_r, &t); t > 0; t-- {
		Fscan(_r, &s)
		n := len(s)
		if strings.Count(s, "0") == n || strings.Count(s, "1") == n {
			Fprintln(_w, s)
		} else {
			Fprintln(_w, strings.Repeat("01", n))
		}
	}
}

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

// https://codeforces.com/contest/1342/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscanln(input, &s)
		fmt.Println(solve(s))
	}
}

func solve(s string) string {
	z, o := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			z++
		} else {
			o++
		}
	}

	if z == 0 || o == 0 {
		return s
	}

	var buff bytes.Buffer
	buff.WriteByte(s[0])
	prev := s[0]
	for i := 1; i < len(s); i++ {
		if prev != s[i] {
			buff.WriteByte(s[i])
			continue
		}
		if prev == '0' {
			prev = '1'
		} else {
			prev = '0'
		}
		buff.WriteByte(prev)
	}

	return buff.String()
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		if n % 2 == 1 && n >=3 {
			s += string(s[n - 2])
			n = n + 1
		}
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 2 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		if n % 2 == 1 && n >=3 {
			s += string(s[n - 2])
			n = n + 1
		}
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var s string
		fmt.Fscan(in, &s)
		fmt.Fprint(out, s+s)
		fmt.Fprint(out, "\n")
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%s\n", sol(s))
	}
}

func sol(t string) string {
	m := map[rune]int64{}
	for _, r := range t {
		m[r]++
	}
	if m['0'] == int64(len(t)) || m['1'] == int64(len(t)) {
		return t
	}
	ret := ""
	repeat := max(m['0'], m['1']) + 1
	for ; repeat > 0; repeat-- {
		ret += "10"
	}
	return ret
}

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

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for T := stdin.ReadInt(); T > 0; T-- {
		t := []rune(stdin.Read())
		stack := NewDeque()
		stack.AppendLast(t[0])

		x := 1
		for x < len(t) {
			ch := stack.PeekLast().(rune)
			if ch == t[x] {
				if ch == '0' {
					stack.AppendLast('1')
				} else {
					stack.AppendLast('0')
				}
			} else {
				stack.AppendLast(t[x])
				x++
			}
		}

		ans := []rune{}
		for !stack.IsEmpty() {
			ans = append(ans, stack.PopFirst().(rune))
		}
		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}


package main

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

type node struct {
	i, val int
}

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

	var t int
	fmt.Fscanln(in, &t)

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

		ns := make([]node, n)
		sum := 0
		for j := 0; j < n; j++ {
			ns[j].i = j + 1
			fmt.Fscan(in, &ns[j].val)
			sum += 2 * ns[j].val
		}

		if m < n || n == 2 {
			fmt.Fprintln(out, -1)
			continue
		}

		sort.Slice(ns, func(l, r int) bool { return ns[l].val < ns[r].val })
		sum += (m - n) * (ns[0].val + ns[1].val)

		fmt.Fprintln(out, sum)

		for j := 0; j < n-1; j++ {
			fmt.Fprintln(out, j+1, j+2)
		}
		fmt.Fprintln(out, 1, n)

		for j := m - n; j > 0; j-- {
			fmt.Fprintln(out, ns[0].i, ns[1].i)
		}

		/*
		for _, v := range ns {
			fmt.Println("Got:", v)
		}
		fmt.Println("End")
		*/
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, m int

	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n, &m)
		a := make([]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			sum += 2 * a[i]
		}
		if (m < n || n == 2) {
			fmt.Println(-1)
		} else {
			fmt.Println(sum)
			for i := 0; i < n; i++ {
				fmt.Println(i+1, (i+1)%n+1)
			}
		}
	}
}

package main

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

var scanner *bufio.Scanner
var out *bufio.Writer

func init() {
	scanner = bufio.NewScanner(bufio.NewReader(os.Stdin))
	//scanner.Buffer(make([]byte, 311000), 311000)
	scanner.Split(bufio.ScanWords)
	out = bufio.NewWriterSize(os.Stdout, 10000)
}

func next() string {
	if !scanner.Scan() {
		panic("scanner.Scan() returned false")
	}
	return scanner.Text()
}

func nextInt() int {
	txt := next()
	num, err := strconv.Atoi(txt)
	if err != nil {
		panic(fmt.Errorf("Atoi(%q) returned error: %v", txt, err))
	}
	return num
}

func nextLong() int64 {
	txt := next()
	num, err := strconv.ParseInt(txt, 10, 64)
	if err != nil {
		panic(fmt.Errorf("ParseInt(%q, 10, 64) returned error: %v", txt, err))
	}
	return num
}

// ========================================================

func main() {
	defer out.Flush()
	numCases := nextInt()
	for caseId := 1; caseId <= numCases; caseId++ {
		n, m := nextInt(), nextInt()
		var sum int64
		for i := 0; i < n; i++ {
			sum += int64(nextInt())
		}
		if m < n || n < 3 {
			fmt.Fprintln(out, "-1")
			continue
		}
		fmt.Fprintln(out, sum*2)
		fmt.Fprintln(out, n, 1)
		for i := 1; i < n; i++ {
			fmt.Fprintln(out, i, i+1)
		}

	}
}

package main

import (
	"bufio"
	"fmt"
	// "math"
	"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(n, m int, costs []int) {
	if m < n || n <= 2 {
		printf("-1\n")
		return
	}

	sort.Ints(costs)
	sum := 0
	for _, v := range costs {
		sum += v
	}

	printf("%d\n", sum*2)
	for i := 1; i < n; i++ {
		printf("%d %d\n", i, i+1)
	}
	printf("%d %d\n", n, 1)
}

func main() {
	defer writer.Flush()
	tt := 0
	scanf("%d\n", &tt)
	for i := 0; i < tt; i++ {
		var n, m int
		scanf("%d %d\n", &n, &m)
		costs := make([]int, n)
		for j := 0; j < n; j++ {
			scanf("%d", &costs[j])
		}
		scanf("\n")
		solve(n, m, costs)
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n, m int
var A []int

type Edge struct {
	key          int
	nodeId, cost int
}
type EdgeList []*Edge
type byKey struct {
	EdgeList
}

func (l EdgeList) Len() int {
	return len(l)
}
func (l EdgeList) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l byKey) Less(i, j int) bool {
	return l.EdgeList[i].key < l.EdgeList[j].key
}

// how to use
// L := make(EdgeList, 0, 200000+5)
// L = append(L, &Edge{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, m = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if m < n {
		fmt.Println(-1)
		return
	}

	if n == 2 {
		fmt.Println(-1)
		return
	}

	sumA := Sum(A...)
	cost := 2 * sumA

	L := make(EdgeList, 0)
	for i := 0; i < n; i++ {
		L = append(L, &Edge{key: A[i], nodeId: i + 1, cost: A[i]})
	}
	sort.Stable(byKey{L})

	mm := m - n
	cost += mm * (L[0].cost + L[1].cost)

	answers := [][]int{}
	for i := 1; i <= n; i++ {
		if i == n {
			answers = append(answers, []int{i, 1})
		} else {
			answers = append(answers, []int{i, i + 1})
		}
	}
	for i := 0; i < mm; i++ {
		answers = append(answers, []int{L[0].nodeId, L[1].nodeId})
	}

	fmt.Println(cost)
	for i := 0; i < m; i++ {
		fmt.Printf("%d %d\n", answers[i][0], answers[i][1])
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		sum := 0
		for i := range a {
			Fscan(in, &a[i])
			sum += a[i] * 2
		}
		if n == 2 || n > m {
			Fprintln(out, -1)
			continue
		}
		Fprintln(out, sum)
		for i := 1; i < n; i++ {
			Fprintln(out, i, i+1)
		}
		Fprintln(out, n, 1)
	}
}

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

package main

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

type node struct {
	i, val int
}

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

	var t int
	fmt.Fscanln(in, &t)

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

		ns := make([]node, n)
		sum := 0
		for j := 0; j < n; j++ {
			ns[j].i = j + 1
			fmt.Fscan(in, &ns[j].val)
			sum += 2 * ns[j].val
		}

		if m < n {
			fmt.Fprintln(out, -1)
			continue
		}

		sort.Slice(ns, func(l, r int) bool { return ns[l].val < ns[r].val })
		sum += (m - n) * (ns[0].val + ns[1].val)

		fmt.Fprintln(out, sum)

		for j := 0; j < n-1; j++ {
			fmt.Fprintln(out, j+1, j+2)
		}
		fmt.Fprintln(out, 1, n)

		for j := m - n; j > 0; j-- {
			fmt.Fprintln(out, ns[0].i, ns[1].i)
		}

		/*
		for _, v := range ns {
			fmt.Println("Got:", v)
		}
		fmt.Println("End")
		*/
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, m int

	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n, &m)
		a := make([]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			sum += 2 * a[i]
		}
		fmt.Println(sum)
		for i := 0; i < n; i++ {
			fmt.Println(i+1, (i+1)%n+1)
		}
	}
}

package main

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

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(n, m int, costs []int) {
	if m < n-1 || n <= 2 {
		printf("-1\n")
		return
	}
	rst := 0
	for _, v := range costs {
		rst += v
	}
	printf("%d\n", rst * 2)
	for i := 1; i < n; i++ {
		printf("%d %d\n", i, i+1)
	}
	printf("%d %d\n", n, 1)
}

func main() {
	defer writer.Flush()
	tt := 0
	scanf("%d\n", &tt)
	for i := 0; i < tt; i++ {
		var n, m int
		scanf("%d %d\n", &n, &m)
		costs := make([]int, n)
		for j := 0; j < n; j++ {
			scanf("%d", &costs[j])
		}
		scanf("\n")
		solve(n, m, costs)
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n, m int
var A []int

type Edge struct {
	key          int
	nodeId, cost int
}
type EdgeList []*Edge
type byKey struct {
	EdgeList
}

func (l EdgeList) Len() int {
	return len(l)
}
func (l EdgeList) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l byKey) Less(i, j int) bool {
	return l.EdgeList[i].key < l.EdgeList[j].key
}

// how to use
// L := make(EdgeList, 0, 200000+5)
// L = append(L, &Edge{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n, m = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	if m < n {
		fmt.Println(-1)
		return
	}

	sumA := Sum(A...)
	cost := 2 * sumA

	L := make(EdgeList, 0)
	for i := 0; i < n; i++ {
		L = append(L, &Edge{key: A[i], nodeId: i + 1, cost: A[i]})
	}
	sort.Stable(byKey{L})

	mm := m - n
	cost += mm * (L[0].cost + L[1].cost)

	answers := [][]int{}
	for i := 1; i <= n; i++ {
		if i == n {
			answers = append(answers, []int{i, 1})
		} else {
			answers = append(answers, []int{i, i + 1})
		}
	}
	for i := 0; i < mm; i++ {
		answers = append(answers, []int{L[0].nodeId, L[1].nodeId})
	}

	fmt.Println(cost)
	for i := 0; i < m; i++ {
		fmt.Printf("%d %d\n", answers[i][0], answers[i][1])
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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


package main

import (
	"fmt"
	"os"
)

func max(seqs []int, joins int) int {
	if joins >= len(seqs)-1 {
		sum := -1
		for i := 0; i < len(seqs); i++ {
			sum += 1 + seqs[i]
		}
		return sum
	}
	// joins < len(seqs)
	max := -1
	for i := 0; i < joins+1; i++ {
		max += 1 + seqs[i]
	}
	sum := max
	for i := joins + 1; i < len(seqs); i++ {
		sum += seqs[i] - seqs[i-joins-1]
		if sum > max {
			max = sum
		}
	}
	return max
}

func solve(s string, chg int) int {
	n := len(s)
	var soa, sob []int // sequences of a's / b's
	c, cPrev := byte(0), byte(0)
	for i := 0; i < n; i++ {
		cPrev, c = c, s[i]
		if c == cPrev {
			if c == 'a' {
				soa[len(soa)-1]++
				sob = append(sob, 0)
			} else {
				sob[len(sob)-1]++
				soa = append(soa, 0)
			}
		} else {
			if c == 'a' {
				soa = append(soa, 1)
			} else {
				sob = append(sob, 1)
			}
		}
	}
	if s[0] == 'a' {
		sob = append([]int{0}, sob...)
	} else {
		soa = append([]int{0}, soa...)
	}
	if c == 'a' {
		sob = append(sob, 0)
	} else {
		soa = append(soa, 0)
	}
	soaMax := max(soa, chg)
	sobMax := max(sob, chg)
	if soaMax > sobMax {
		return soaMax
	}
	return sobMax
}

func main() {
	var n, k int
	nr, err := fmt.Fscanln(os.Stdin, &n, &k)
	if nr != 2 || err != nil {
		panic(err)
	}
	var s string
	nr, err = fmt.Fscanln(os.Stdin, &s)
	if nr != 1 || err != nil {
		panic(err)
	}
	res := solve(s, k)
	fmt.Println(res)
}

package main

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

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 main() {
	defer writer.Flush()
	var n, c int
	scanf("%d %d\n", &n, &c)
	var s string
	scanf("%s\n", &s)
	//printf("%d %d %s\n", n, c, s)
	alphabet := [2]byte{'a', 'b'}
	ans := 0
	for i := 0; i < len(alphabet); i++ {
		bad := 0
		j := 0
		k := 0
		for k = 0; k < len(s); k++ {
			if s[k] != alphabet[i] {
				bad++
			}
			if bad > c {
				for j <= k && s[j] == alphabet[i] {
					j++
				}
				bad--
				j++
			}
			if k-j+1 > ans {
				ans = k - j + 1
			}
		}
	}
	printf("%d\n", ans)
}


package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

var n int
var mat [][]int

func fw() {
        var nc int
        for u := 0; u < n; u++ {
                for v := 0; v < n; v++ {
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        mat[k][u], mat[u][k] = nc, nc
                                }
                        }
                }
        }
}

func sum() int64 {
        var s int64
        for u := 0; u < n - 1; u++ {
                for v := u + 1; v < n; v++ {
                        s += int64(mat[u][v])
                }
        }
        return s
}

func main() {
        defer w.Flush()

        fmt.Fscanf(r, "%d\n", &n)
        mat = make([][]int, n)
        for i := 0; i < n; i++ {
                mat[i] = make([]int, n)
                for j := 0; j < n - 1; j++ {
                        fmt.Fscanf(r, "%d ", &mat[i][j])
                }
                fmt.Fscanf(r, "%d\n", &mat[i][n-1])
        }
        fw()

        s := sum()
        var t int
        fmt.Fscanf(r, "%d\n", &t)
        var i, j, c int
        var nc int
        for ; t > 0; t-- {
                fmt.Fscanf(r, "%d %d %d\n", &i, &j, &c)
                i -= 1
                j -= 1
                if mat[i][j] > c {
                        mat[i][j] = c
                        mat[j][i] = c

                        for u := 0; u < n; u++ {
                                for v := 0; v < n; v++ {
                                        nc = mat[u][i] + c + mat[j][v]
                                        if mat[u][j] + c + mat[i][v] < nc {
                                                nc = mat[u][j] + c + mat[j][v]
                                        }
                                        if nc < mat[u][v] {
                                                mat[u][v], mat[v][u] = nc, nc
                                        }
                                }
                        }
                }

                s = sum()
                fmt.Fprintf(w, "%v ", s)
        }
}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int32

func main() {
	var (
		n, i, j, q, a, b, dab int32
		s                     int64
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += int64(dist[i][j])
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		if dab < dist[a][b] {
			s = 0
			for i = 1; i < n; i++ {
				for j = i + 1; j <= n; j++ {
					if dist[i][a]+dab+dist[b][j] < dist[i][j] {
						dist[i][j] = dist[i][a] + dab + dist[b][j]
						dist[j][i] = dist[i][j]
					}
					if dist[i][b]+dab+dist[a][j] < dist[i][j] {
						dist[i][j] = dist[i][b] + dab + dist[a][j]
						dist[j][i] = dist[i][j]
					}
					s += int64(dist[i][j])
				}
			}
		}
		fmt.Fprint(out, s)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

import (
	"fmt"
)

var dist [301][301]int16

func main() {
	var (
		n, i, j, q, a, b, dab, s int16
	)

	fmt.Scan(&n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Scan(&dist[i][j])
			s += dist[i][j]
		}
	}
	s /= 2

	fmt.Scan(&q)
	for ; q > 0; q-- {
		fmt.Scan(&a)
		fmt.Scan(&b)
		fmt.Scan(&dab)
		if dab < dist[a][b] {
			s = 0
			for i = 1; i < n; i++ {
				for j = i + 1; j <= n; j++ {
					if dist[i][a]+dab+dist[b][j] < dist[i][j] {
						dist[i][j] = dist[i][a] + dab + dist[b][j]
						dist[j][i] = dist[i][j]
					}
					if dist[i][b]+dab+dist[a][j] < dist[i][j] {
						dist[i][j] = dist[i][b] + dab + dist[a][j]
						dist[j][i] = dist[i][j]
					}
					s += dist[i][j]
				}
			}
		}
		fmt.Print(s, " ")

	}
	fmt.Println()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int32

func main() {
	var (
		n, i, j, q, a, b, dab, s int32
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += dist[i][j]
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		if true || dab < dist[a][b] {
			s = 0
			for i = 1; i <= n; i++ {
				for j = 1; j <= n; j++ {
					if dist[i][a]+dab+dist[b][j] < dist[i][j] {
						dist[i][j] = dist[i][a] + dab + dist[b][j]
						dist[j][i] = dist[i][j]
					}
					if dist[i][b]+dab+dist[a][j] < dist[i][j] {
						dist[i][j] = dist[i][b] + dab + dist[a][j]
						dist[j][i] = dist[i][j]
					}
					s += dist[i][j]
				}
			}
		}
		fmt.Fprint(out, s/2)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int32

func main() {
	var (
		n, i, j, q, a, b, dab, s int32
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += dist[i][j]
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		s = 0
		for i = 1; i < n; i++ {
			for j = i + 1; j <= n; j++ {
				if dist[i][a]+dab+dist[b][j] < dist[i][j] {
					dist[i][j] = dist[i][a] + dab + dist[b][j]
					dist[j][i] = dist[i][j]
				}
				if dist[i][b]+dab+dist[a][j] < dist[i][j] {
					dist[i][j] = dist[i][b] + dab + dist[a][j]
					dist[j][i] = dist[i][j]
				}
				s += dist[i][j]
			}
		}

		fmt.Fprint(out, s)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int16

func main() {
	var (
		n, i, j, q, a, b, dab int16
		s                     int32 // int16 overflow :)
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += int32(dist[i][j])
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		if dab < dist[a][b] {
			s = 0
			for i = 1; i < n; i++ {
				for j = i + 1; j <= n; j++ {
					if dist[i][a]+dab+dist[b][j] < dist[i][j] {
						dist[i][j] = dist[i][a] + dab + dist[b][j]
						dist[j][i] = dist[i][j]
					}
					if dist[i][b]+dab+dist[a][j] < dist[i][j] {
						dist[i][j] = dist[i][b] + dab + dist[a][j]
						dist[j][i] = dist[i][j]
					}
					s += int32(dist[i][j])
				}
			}
		}
		fmt.Fprint(out, s)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int32

func main() {
	var (
		n, i, j, q, a, b, dab, s int32
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += dist[i][j]
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		if dab >= dist[a][b] {
			continue
		}
		s = 0
		for i = 1; i < n; i++ {
			for j = i + 1; j <= n; j++ {
				if dist[i][a]+dab+dist[b][j] < dist[i][j] {
					dist[i][j] = dist[i][a] + dab + dist[b][j]
					dist[j][i] = dist[i][j]
				}
				if dist[i][b]+dab+dist[a][j] < dist[i][j] {
					dist[i][j] = dist[i][b] + dab + dist[a][j]
					dist[j][i] = dist[i][j]
				}
				s += dist[i][j]
			}
		}

		fmt.Fprint(out, s)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

//http://codeforces.com/contest/25/problem/C
//C. Roads in Berland

package main

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

var dist [301][301]int32

func main() {
	var (
		n, i, j, q, a, b, dab, s int32
	)

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

	fmt.Fscan(in, &n)

	for i = 1; i <= n; i++ {
		for j = 1; j <= n; j++ {
			fmt.Fscan(in, &dist[i][j])
			s += dist[i][j]
		}
	}
	s /= 2

	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &dab)
		if dab < dist[a][b] {
			s = 0
			for i = 1; i < n; i++ {
				for j = i + 1; j <= n; j++ {
					if dist[i][a]+dab+dist[b][j] < dist[i][j] {
						dist[i][j] = dist[i][a] + dab + dist[b][j]
						dist[j][i] = dist[i][j]
					}
					if dist[i][b]+dab+dist[a][j] < dist[i][j] {
						dist[i][j] = dist[i][b] + dab + dist[a][j]
						dist[j][i] = dist[i][j]
					}
					s += dist[i][j]
				}
			}
		}
		fmt.Fprint(out, s)
		fmt.Fprint(out, " ")

	}
	fmt.Fprintln(out)
	out.Flush()

}

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

var n int
var mat [][]int

func fw(mat[][]int) int {
        var nc int
        for u := 0; u < n; u++ {
                for v := 0; v < n; v++ {
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        mat[k][u], mat[u][k] = nc, nc
                                }
                        }
                }
        }

        s := 0
        for u := 0; u < n - 1; u++ {
                for v := u + 1; v < n; v++ {
                        s += mat[u][v]
                }
        }
        return s
}

func main() {
        defer w.Flush()

        fmt.Fscanf(r, "%d\n", &n)
        mat = make([][]int, n)
        for i := 0; i < n; i++ {
                mat[i] = make([]int, n)
                for j := 0; j < n - 1; j++ {
                        fmt.Fscanf(r, "%d ", &mat[i][j])
                }
                fmt.Fscanf(r, "%d\n", &mat[i][n-1])
        }
        s := fw(mat)

        var t int
        fmt.Fscanf(r, "%d\n", &t)
        var u, v, c int
        var nc int
        for ; t > 0; t-- {
                fmt.Fscanf(r, "%d %d %d\n", &u, &v, &c)
                u -= 1
                v -= 1
                if mat[u][v] > c {
                        s -= mat[u][v] - c
                        mat[u][v] = c
                        mat[v][u] = c
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        s -= mat[u][k] - nc
                                        mat[k][u], mat[u][k] = nc, nc
                                }

                                nc = mat[v][u] + mat[u][k]
                                if nc < mat[v][k] {
                                        s -= mat[v][k] - nc
                                        mat[k][v], mat[v][k] = nc, nc
                                }
                        }
                }

                fmt.Fprintf(w, "%v ", s)
        }
}

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

var n int
var mat [][]int

func fw() {
        var nc int
        for u := 0; u < n; u++ {
                for v := 0; v < n; v++ {
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        mat[k][u], mat[u][k] = nc, nc
                                }
                        }
                }
        }
}

func sum() int {
        s := 0
        for u := 0; u < n - 1; u++ {
                for v := u + 1; v < n; v++ {
                        s += mat[u][v]
                }
        }
        return s
}

func main() {
        defer w.Flush()

        fmt.Fscanf(r, "%d\n", &n)
        mat = make([][]int, n)
        for i := 0; i < n; i++ {
                mat[i] = make([]int, n)
                for j := 0; j < n - 1; j++ {
                        fmt.Fscanf(r, "%d ", &mat[i][j])
                }
                fmt.Fscanf(r, "%d\n", &mat[i][n-1])
        }
        fw()

        s := sum()
        var t int
        fmt.Fscanf(r, "%d\n", &t)
        var i, j, c int
        var nc int
        for ; t > 0; t-- {
                fmt.Fscanf(r, "%d %d %d\n", &i, &j, &c)
                i -= 1
                j -= 1
                if mat[i][j] > c {
                        mat[i][j] = c
                        mat[j][i] = c

                        for u := 0; u < n; u++ {
                                for v := 0; v < n; v++ {
                                        nc = mat[u][i] + c + mat[j][v]
                                        if mat[u][j] + c + mat[i][v] < nc {
                                                nc = mat[u][j] + c + mat[j][v]
                                        }
                                        if nc < mat[u][v] {
                                                mat[u][v], mat[v][u] = nc, nc
                                        }
                                }
                        }
                }

                s = sum()
                fmt.Fprintf(w, "%v ", s)
        }
}

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

var n int
var mat [][]int

func fw(mat[][]int) int {
        var nc int
        for u := 0; u < n; u++ {
                for v := 0; v < n; v++ {
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        mat[k][u], mat[u][k] = nc, nc
                                }
                        }
                }
        }

        s := 0
        for u := 0; u < n - 1; u++ {
                for v := u + 1; v < n; v++ {
                        s += mat[u][v]
                }
        }
        return s
}

func main() {
        defer w.Flush()

        fmt.Fscanf(r, "%d\n", &n)
        mat = make([][]int, n)
        for i := 0; i < n; i++ {
                mat[i] = make([]int, n)
                for j := 0; j < n - 1; j++ {
                        fmt.Fscanf(r, "%d ", &mat[i][j])
                }
                fmt.Fscanf(r, "%d\n", &mat[i][n-1])
        }

        var t int
        var s int
        fmt.Fscanf(r, "%d\n", &t)
        var u, v, c int
        for ; t > 0; t-- {
                fmt.Fscanf(r, "%d %d %d\n", &u, &v, &c)
                u -= 1
                v -= 1
                if mat[u][v] > c {
                        s -= mat[u][v] - c
                        mat[u][v] = c
                        mat[v][u] = c
                        s = fw(mat)
                }

                fmt.Fprintf(w, "%v ", s)
        }
}

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

var n int
var mat [][]int

func fw() int {
        var nc int
        for u := 0; u < n; u++ {
                for v := 0; v < n; v++ {
                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        mat[k][u], mat[u][k] = nc, nc
                                }
                        }
                }
        }

        s := 0
        for u := 0; u < n - 1; u++ {
                for v := u + 1; v < n; v++ {
                        s += mat[u][v]
                }
        }
        return s
}

func main() {
        defer w.Flush()

        fmt.Fscanf(r, "%d\n", &n)
        mat = make([][]int, n)
        for i := 0; i < n; i++ {
                mat[i] = make([]int, n)
                for j := 0; j < n - 1; j++ {
                        fmt.Fscanf(r, "%d ", &mat[i][j])
                }
                fmt.Fscanf(r, "%d\n", &mat[i][n-1])
        }
        s := fw()

        var t int
        fmt.Fscanf(r, "%d\n", &t)
        var u, v, c int
        var nc int
        for ; t > 0; t-- {
                fmt.Fscanf(r, "%d %d %d\n", &u, &v, &c)
                u -= 1
                v -= 1
                if mat[u][v] > c {
                        s -= mat[u][v] - c
                        mat[u][v] = c
                        mat[v][u] = c

                        for k := 0; k < n; k++ {
                                nc = mat[u][v] + mat[v][k]
                                if nc < mat[u][k] {
                                        s -= mat[u][k] - nc
                                        mat[u][k], mat[k][u] = nc, nc
                                }

                                nc = mat[v][u] + mat[u][k]
                                if nc < mat[v][k] {
                                        s -= mat[v][k] - nc
                                        mat[v][k], mat[k][v] = nc, nc
                                }
                        }
                }

                fmt.Fprintf(w, "%v ", s)
        }
}


package main

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

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

func b1659(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var k int
	var x string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &x)
		ans := []byte{}
		se := make([]int, n)
		if k%2 == 0 {
			for i, v := range x {
				if v == '0' {
					if k == 0 {
						ans = append(ans, x[i:]...)
						break
					}
					if k > 0 {
						k--
						se[i]++
					}
				}
				ans = append(ans, '1')
			}
		} else {
			for i, v := range x {
				if k == 0 {
					if v == '1' {
						ans = append(ans, '0')
					} else {
						ans = append(ans, '1')
					}
				}
				if k > 0 {
					if v == '1' {
						se[i]++
						k--
					}
					ans = append(ans, '1')
				}
			}
		}

		se[0] += k - k%2
		if k > 0 && k%2 == 1 {
			se[n-1]++
			ans[n-1] = '0'
		}

		Fprintln(out, string(ans))
		for i, v := range se {
			if i > 0 {
				Fprintf(out, " ")
			}
			Fprintf(out, "%d", v)
		}
		Fprintln(out, "")
	}
}

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, m int
		Fscan(in, &n, &m)
		canUse := m

		var s string
		Fscan(in, &s)

		ans := make([]byte, n)
		ans2 := make([]int, n)
		for index, ch := range s {
			flag := m & 1
			v := int(ch - '0')
			if index != n-1 {
				if v^flag == 0 && canUse > 0 {
					ans2[index] += 1
					canUse -= 1
					ans[index] = '1'
				} else if v^flag == 1 {
					ans[index] = '1'
				} else if v^flag == 0 {
					ans[index] = '0'
				}
			} else {
				ans2[n-1] += canUse
				flag = (m - canUse) & 1
				v = v ^ flag
				ans[n-1] = byte('0' + v)
			}
		}
		Fprintln(out, string(ans))
		for i := 0; i < n; i++ {
			if i != n-1 {
				Fprint(out, ans2[i], " ")
			} else {
				Fprintln(out, ans2[i])
			}
		}
	}

}

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

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

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)
		ans := make([]int, n)
		temp := k
		for i := 0; i < n && temp > 0; i++ {
			if k&1 == 1 {
				if s[i] == '1' {
					ans[i] = 1
					temp--
				} else {
					ans[i] = 0
				}
			} else {
				if s[i] == '1' {
					ans[i] = 0
				} else {
					ans[i] = 1
					temp--
				}
			}
		}
		if temp > 0 {
			ans[n-1] += temp
		}
		sb := strings.Builder{}
		for i := 0; i < n; i++ {
			if (k-ans[i])&1 == 0 {
				sb.WriteByte(s[i])
			} else {
				if s[i] == '0' {
					sb.WriteByte('1')
				} else {
					sb.WriteByte('0')
				}
			}
		}
		fmt.Fprintln(out, sb.String())
		for i := 0; i < n; i++ {
			fmt.Fprint(out, ans[i])
			if i == n-1 {
				fmt.Fprintln(out)
			} else {
				fmt.Fprint(out, " ")
			}
		}
	}

}

package main

import (
	"fmt"
	"strings"
)

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

	for test := 0; test < t; test++ {
		var n, k int
		fmt.Scanf("%d %d\n", &n, &k)

		var str string
		fmt.Scanln(&str)

		s := []byte(str)

		f := make([]int, n)
		remainK := k
		for i := 0; i < n && remainK > 0; i++ {
			if (k%2 == 0 && s[i] == '0') || (k%2 == 1 && s[i] == '1') {
				f[i] = 1
				remainK--
			}
		}

		f[n-1] += remainK

		for i := 0; i < n; i++ {
			if (k-f[i])%2 == 1 {
				if s[i] == '1' {
					s[i] = '0'
				} else {
					s[i] = '1'
				}
			}
		}

		fmt.Println(string(s))

		output := fmt.Sprint(f)
		output = strings.Replace(output, "[", "", -1)
		output = strings.Replace(output, "]", "", -1)
		fmt.Println(output)
	}
}

package main

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

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

	var T, n, k int
	var s []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &s)
		pos := [2][]int{}
		for i, b := range s {
			pos[b&1] = append(pos[b&1], i)
		}

		ans := make([]int, n)
		p := pos[k&1]
		m := len(p)
		for i := 1; i < m && k > k&1; i += 2 {
			s[p[i-1]] ^= 1
			s[p[i]] ^= 1
			ans[p[i-1]]++
			ans[p[i]]++
			k -= 2
		}

		if k&1 > 0 {
			i := bytes.IndexByte(s, '1')
			if i < 0 {
				i = n - 1
			}
			for j := range s {
				if j != i {
					s[j] ^= 1
				}
			}
			ans[i]++
			k--
		} else if k > 0 && m&1 > 0 {
			s[p[m-1]] ^= 1
			s[n-1] ^= 1
			ans[p[m-1]]++
			ans[n-1]++
			k -= 2
		}
		ans[0] += k

		Fprintf(out, "%s\n", s)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

/*
1
6 3
100001
---
111110
1 0 0 2 0 0

100001 -> 111110 -> 000001 -> 111110
=========
1
6 1
111001
---
100110
1 0 0 0 0 0
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, k int
	var s string
	scanf("%d %d\n%s\n", &n, &k, &s)

	bits := make([]bool, n)

	for i, r := range s {
		if r == '1' {
			bits[i] = true
		}
	}

	flips := make([]int, n)

	flipsLeftCnt := k

	for i, bit := range bits {
		if flipsLeftCnt > 0 {
			if !bit && k%2 == 0 || bit && k%2 != 0 {
				flips[i]++
				flipsLeftCnt--
			}
		} else {
			break
		}
	}

	flips[len(flips)-1] += flipsLeftCnt

	for i, cnt := range flips {
		if bits[i] == ((k-cnt)%2 == 0) {
			fmt.Fprintf(writer, "1")
		} else {
			fmt.Fprintf(writer, "0")
		}
	}
	fmt.Fprintln(writer)

	for _, cnt := range flips {
		fmt.Fprintf(writer, "%d ", cnt)
	}
	fmt.Fprintln(writer)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

	for ftr := 2; ftr <= sqrtA; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > sqrtA {
		factors = append(factors, num)
	}

	return factors
}

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

		z := k
		m := make([]int, n)
		var flipped int
		fn := func(ch byte) int {
			n := int(ch - '0')
			if flipped%2 != 0 {
				return n ^ 1
			}
			return n
		}
		var pos int
		for pos < n {
			if z <= 0 {
				break
			}
			if z%2 == 0 && fn(s[pos]) == 0 {
				m[pos]++
				z--
				flipped++
			} else if z%2 != 0 && fn(s[pos]) == 1 {
				m[pos]++
				z--
				flipped++
			}

			pos++
		}

		m[n-1] += z
		for i, ch := range s {
			z := k - m[i]
			if z%2 != 0 && ch == '1' {
				fmt.Fprint(out, 0)
			} else if z%2 != 0 && ch == '0' {
				fmt.Fprint(out, 1)
			} else {
				fmt.Fprint(out, string(ch))
			}
		}
		fmt.Fprintln(out)
		for _, v := range m {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

func main() {
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int
	fmt.Scan(&T)
	var n int
	var k int
	var s string
	for t := 0; t < T; t++ {
		fmt.Fscan(reader, &n, &k, &s)
		var ans []byte
		var flips []int
		flip := false
		for i := 0; i < n; i++ {
			val := s[i]
			if flip {
				if val == '1' {
					val = '0'
				} else {
					val = '1'
				}
			}
			if k == 0 || i == n-1 {
				ans = append(ans, val)
				flips = append(flips, k)
			} else {
				if k%2 == 0 {
					if val == '1' {
						// we are 1, want to keep it: dont flip!
						ans = append(ans, '1')
						flips = append(flips, 0)
					} else {
						// we are 0, want to flip it: flip!
						ans = append(ans, '1')
						k--
						flip = !flip
						flips = append(flips, 1)
					}
				} else {
					if val == '1' {
						// we are 1, want to keep it: flip!
						ans = append(ans, '1')
						k--
						flip = !flip
						flips = append(flips, 1)
					} else {
						// we are 0, want to flip it: don't flip!
						ans = append(ans, '1')
						flips = append(flips, 0)
					}
				}
			}
		}
		fmt.Fprintln(writer, string(ans))
		var flipstrings []string
		for _, j := range flips {
			flipstrings = append(flipstrings, strconv.Itoa(j))
		}
		fmt.Fprintln(writer, strings.Join(flipstrings, " "))
		// fmt.Fprintln(writer, ans)
	}
}

package main

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		k := _int()
		s := _string()
		r1, r2 := sol(n, k, s)
		printf("%s\n", r1)
		for _, r := range r2 {
			printf("%d ", r)
		}
		printf("\n")
	}
}

func sol(n, k int, s string) (string, []int) {
	r1 := make([]byte, n)
	r2 := make([]int, n)
	kc := k
	if k&1 == 1 {
		for i := range s {
			if kc > 0 {
				if s[i] == '1' {
					r1[i] = '1'
					r2[i]++
					kc--
				} else {
					r1[i] = '1'
				}
			} else {
				if s[i] == '1' {
					r1[i] = '0'
				} else {
					r1[i] = '1'
				}
			}
		}
	} else {
		for i := range s {
			if kc > 0 {
				if s[i] == '0' {
					r1[i] = '1'
					r2[i]++
					kc--
				} else {
					r1[i] = '1'
				}
			} else {
				if s[i] == '1' {
					r1[i] = '1'
				} else {
					r1[i] = '0'
				}
			}
		}
	}
	// clean up last digit
	r2[len(r2)-1] += kc
	if kc&1 == 1 {
		if r1[len(r1)-1] == '0' {
			r1[len(r1)-1] = '1'
		} else {
			r1[len(r1)-1] = '0'
		}
	}
	return string(r1), r2
}

package main

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

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

func printAnswer(m map[int]int, bitsCount int) {
	for i := 0; i < bitsCount; i++ {
		if val, ok := m[i]; ok {
			fmt.Fprint(writer, val)
			fmt.Fprint(writer, " ")
		} else {
			fmt.Fprint(writer, "0 ")
		}
	}
	fmt.Fprintln(writer)
}

func flipFirstOne(bits []rune) int {
	i := 0

	for i+1 < len(bits) {
		if bits[i] == '1' {
			break
		}

		i += 1
	}

	if bits[i] == '1' {
		bits[i] = '0'
	} else {
		bits[i] = '1'
	}

	return i
}

func solve(movesCount int, bits []rune) {
	defer writer.Flush()
	answer := make(map[int]int)
	one := '1'

	if movesCount%2 == 1 {
		movesCount -= 1
		flippedPosition := flipFirstOne(bits)
		one = '0'
		answer[flippedPosition] = 1
	}

	i := 0
	for movesCount != 0 && i < len(bits) {
		/** Looking for the first zero */
		for i < len(bits) && bits[i] == one {
			fmt.Fprint(writer, "1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else {
			if _, ok := answer[i]; ok {
				answer[i] += 1
			} else {
				answer[i] = 1
			}

			if i+1 == len(bits) {
				fmt.Fprint(writer, "0")
				if _, ok := answer[i]; ok {
					answer[i] += 1
				} else {
					answer[i] = 1
				}
				i += 1
				movesCount -= 2
				break
			} else {
				fmt.Fprint(writer, "1")
			}
		}

		i += 1

		/** Looking for the second zero */
		for i < len(bits) && bits[i] == one {
			if i+1 == len(bits) {
				break
			}

			fmt.Fprint(writer, "1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else if i+1 == len(bits) {
			if bits[i] == one {
				fmt.Fprint(writer, "0")
			} else {
				fmt.Fprint(writer, "1")
			}
		} else {
			fmt.Fprint(writer, "1")
		}

		if _, ok := answer[i]; ok {
			answer[i] += 1
		} else {
			answer[i] = 1
		}

		i += 1
		movesCount -= 2
	}

	if i >= len(bits) {
		if _, ok := answer[len(bits)-1]; ok {
			answer[len(bits)-1] += movesCount
		} else {
			answer[len(bits)-1] = movesCount
		}
	} else {
		for i < len(bits) {
			if bits[i] == one {
				fmt.Fprint(writer, "1")
			} else {
				fmt.Fprint(writer, "0")
			}

			i += 1
		}
	}

	fmt.Fprintln(writer)
	printAnswer(answer, len(bits))
}

func main() {
	var t, n, k int
	var bitsString string
	var bits []rune
	fmt.Scan(&t)

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

		bits = []rune(bitsString)
		solve(k, bits)
	}
}

package main

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

func main_div2_782_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n, k int
		Fscan(in, &n, &k)
		var s1 string
		Fscan(in, &s1)
		s := []byte(s1)
		ans := make([]int, n)
		if k == 0 {
			Fprintln(out, string(s))
			for i := 0; i < n; i++ {
				Fprint(out, ans[i], " ")
			}
			Fprintln(out)
			return
		}
		cnt := 0
		//var p = -1
		for i := 0; i < n; i++ {
			if cnt >= k {
				//	p = i
				break
			}
			if s[i] == '0' {
				if k&1 == 0 {
					ans[i] = 1
					cnt++

				}
				//	s[i] = '1'
			} else {
				if k&1 != 0 {
					ans[i] = 1
					cnt++
				}
			}
		}
		//	Fprintln(out, ans, k-cnt)
		if cnt < k {

			ans[n-1] += (k - cnt)

		}
		for i := 0; i < n; i++ {
			if (k-ans[i])&1 != 0 {
				if s[i] == '0' {
					s[i] = '1'
				} else {
					s[i] = '0'
				}
			}
		}
		//for i := 0; i < n; i++ {
		Fprintln(out, string(s))
		//}
		for i := 0; i < n; i++ {
			Fprint(out, ans[i], " ")
		}
		Fprintln(out)
		return
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div2_782_B()
}

package main

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

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

func printAnswer(m map[int]int, bitsCount int) {
	for i := 0; i < bitsCount; i++ {
		if val, ok := m[i]; ok {
			fmt.Fprint(writer, val)
			fmt.Fprint(writer, " ")
		} else {
			fmt.Fprint(writer, "0 ")
		}
	}
	fmt.Fprintln(writer)
}

func flipFirstOne(bits []rune) int {
	i := 0

	for i+1 < len(bits) {
		if bits[i] == '1' {
			break
		}

		i += 1
	}

	if bits[i] == '1' {
		bits[i] = '0'
	} else {
		bits[i] = '1'
	}

	return i
}

func solve(movesCount int, bits []rune) {
	defer writer.Flush()
	answer := make(map[int]int)
	one := '1'

	if movesCount%2 == 1 {
		movesCount -= 1
		flippedPosition := flipFirstOne(bits)
		one = '0'
		answer[flippedPosition] = 1
	}

	i := 0
	for movesCount != 0 && i < len(bits) {
		/** Looking for the first zero */
		for i < len(bits) && bits[i] == one {
			fmt.Fprint(writer, "1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else {
			if _, ok := answer[i]; ok {
				answer[i] += 1
			} else {
				answer[i] = 1
			}

			if i+1 == len(bits) {
				fmt.Fprint(writer, "0")
				if _, ok := answer[i]; ok {
					answer[i] += 1
				} else {
					answer[i] = 1
				}
				i += 1
				movesCount -= 2
				break
			} else {
				fmt.Fprint(writer, "1")
			}
		}

		i += 1

		/** Looking for the second zero */
		for i < len(bits) && bits[i] == one {
			if i+1 == len(bits) {
				break
			}

			fmt.Fprint(writer, "1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else if i+1 == len(bits) {
			fmt.Fprint(writer, "0")
		} else {
			fmt.Fprint(writer, "1")
		}

		if _, ok := answer[i]; ok {
			answer[i] += 1
		} else {
			answer[i] = 1
		}
		i += 1
		movesCount -= 2
	}

	if i >= len(bits) {
		if _, ok := answer[len(bits)-1]; ok {
			answer[len(bits)-1] += movesCount
		} else {
			answer[len(bits)-1] = movesCount
		}
	} else {
		for i < len(bits) {
			if bits[i] == one {
				fmt.Fprint(writer, "1")
			} else {
				fmt.Fprint(writer, "0")
			}

			i += 1
		}
	}

	fmt.Fprintln(writer)
	printAnswer(answer, len(bits))
}

func main() {
	var t, n, k int
	var bitsString string
	var bits []rune
	fmt.Scan(&t)

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

		bits = []rune(bitsString)
		solve(k, bits)
	}
}

package main

import "fmt"

func printArray(arr []int) {
	for _, num := range arr {
		fmt.Printf("%d ", num)
	}
	fmt.Println()
}

func flipFirstOne(bits []rune) int {
	i := 0

	for i+1 < len(bits) {
		if bits[i] == '1' {
			break
		}

		i += 1
	}

	if bits[i] == '1' {
		bits[i] = '0'
	} else {
		bits[i] = '1'
	}

	return i
}

func solve(movesCount int, bits []rune) {
	answer := make([]int, len(bits))
	one := '1'

	if movesCount%2 == 1 {
		movesCount -= 1
		flippedPosition := flipFirstOne(bits)
		one = '0'
		answer[flippedPosition] += 1
	}

	i := 0
	for movesCount != 0 && i < len(bits) {
		/** Looking for the first zero */
		for i < len(bits) && bits[i] == one {
			fmt.Print("1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else {
			answer[i] += 1

			if i+1 == len(bits) {
				fmt.Print("0")
				answer[i] += 1
				i += 1
				movesCount -= 2
				break
			} else {
				fmt.Print("1")
			}
		}

		i += 1

		/** Looking for the second zero */
		for i < len(bits) && bits[i] == one {
			if i+1 == len(bits) {
				break
			}

			fmt.Print("1")
			i += 1
		}

		if i >= len(bits) {
			break
		} else if i+1 == len(bits) {
			fmt.Print("0")
		} else {
			fmt.Print("1")
		}

		answer[i] += 1
		i += 1
		movesCount -= 2
	}

	if i >= len(bits) {
		answer[len(bits)-1] += movesCount
	} else {
		for i < len(bits) {
			if bits[i] == one {
				fmt.Print("1")
			} else {
				fmt.Print("0")
			}

			i += 1
		}
	}

	fmt.Println()
	printArray(answer)
}

func main() {
	var t, n, k int
	var bitsString string
	var bits []rune
	fmt.Scanf("%d", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d", &n, &k)
		fmt.Scanf("%s", &bitsString)

		bits = []rune(bitsString)
		solve(k, bits)
	}
}

package main

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

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

func b1659(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var k int
	var x string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &x)
		ans := []byte{}
		se := make([]int, n)
		if k%2 == 0 {
			for i, v := range x {
				if v == '0' {
					if k > 0 {
						k--
						se[i]++
					}
					if k == 0 {
						ans = append(ans, x[i:]...)
						break
					}
				}
				ans = append(ans, '1')
			}
		} else {
			for i, v := range x {
				if k == 0 {
					if v == '1' {
						ans = append(ans, '0')
					} else {
						ans = append(ans, '1')
					}
				}
				if k > 0 {
					if v == '1' {
						se[i]++
						k--
					}
					ans = append(ans, '1')
				}
			}
		}

		se[0] += k - k%2
		if k > 0 && k%2 == 1 {
			se[len(ans)-1]++
			ans[len(ans)-1] = '0'
		}

		Fprintln(out, string(ans))
		for i, v := range se {
			if i > 0 {
				Fprintf(out, " ")
			}
			Fprintf(out, "%d", v)
		}
		Fprintln(out, "")
	}
}

package main

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

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

func b1659(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var k int
	var x string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &x)
		ans := []byte{}
		se := make([]int, n)
		if k%2 == 0 {
			for i, v := range x {
				if v == '0' {
					if k > 0 {
						k--
						se[i]++
					}
					if k == 0 {
						ans = append(ans, x[i:]...)
						break
					}
				}
				ans = append(ans, '1')
			}
		} else {
			for i, v := range x {
				if k == 0 {
					if v == '1' {
						ans = append(ans, '0')
					} else {
						ans = append(ans, '1')
					}
				}
				if k > 0 {
					if v == '1' {
						se[i]++
						k--
					}
					ans = append(ans, '1')
				}
			}
		}

		se[0] += (k - k%2)
		if k > 0 && k%2 == 1 {
			se[len(ans)-1]++
			ans[len(ans)-1] = '0'
		}

		Fprintln(out, string(ans))
		for _, v := range se {
			Fprintf(out, "%d ", v)
		}
		Fprintln(out, "")
	}
}

package main

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

func main_div2_782_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n, k int
		Fscan(in, &n, &k)
		var s1 string
		Fscan(in, &s1)
		s := []byte(s1)
		ans := make([]int, n)
		if k == 0 {
			Fprintln(out, string(s))
			for i := 0; i < n; i++ {
				Fprint(out, ans[i], " ")
			}
			Fprintln(out)
			return
		}
		cnt := 0
		//var p = -1
		for i := 0; i < n; i++ {
			if cnt > k {
				//	p = i
				break
			}
			if s[i] == '0' {
				if k&1 == 0 {
					ans[i] = 1
					cnt++

				}
				//	s[i] = '1'
			} else {
				if k&1 != 0 {
					ans[i] = 1
					cnt++
				}
			}
		}
	//	Fprintln(out, ans, k-cnt)
		if cnt < k {

			ans[n-1] += k - cnt

		}
		for i := 0; i < n; i++ {
			if (k-ans[i])&1 != 0 {
				if s[i] == '0' {
					s[i] = '1'
				} else {
					s[i] = '0'
				}
			}
		}
		//for i := 0; i < n; i++ {
		Fprintln(out, string(s))
		//}
		for i := 0; i < n; i++ {
			Fprint(out, ans[i], " ")
		}
		Fprintln(out)
		return
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div2_782_B()
}