package main

import (
	"fmt"
)

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

	var (
		i, j int
		a    = make([][]byte, n)
	)
	for {
		var d byte
		fmt.Scanf("%c", &d)

		if d < 42 || d > 56 {
			continue
		}

		if j == 0 {
			a[i] = make([]byte, m)
		}
		a[i][j] = d

		j++
		if j == m {
			j = 0
			i++
		}

		if i == n {
			break
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] == 42 {
				continue
			}

			var (
				required byte
				found    byte
			)

			if a[i][j] >= 49 {
				required = a[i][j] - 48
			}

			startI := i-1
			stopI := i+1
			startJ := j-1
			stopJ := j+1

			if i == 0 {
				startI =0
			}

			if stopI >=n {
				stopI = n-1
			}

			if j == 0 {
				startJ =0
			}

			if stopJ >=m {
				stopJ = m-1
			}

			for ci :=startI; ci <= stopI; ci++ {
				for cj :=startJ; cj <= stopJ; cj++ {
					if ci == i && cj == j {
						continue
					}
					if a[ci][cj] == 42 {
						found++
					}
				}
			}

			if found != required {
				fmt.Print("NO")
				return
			}
		}
	}

	fmt.Print("YES")
}

package main

import (
	"fmt"
)

func main() {
	var linesCount int
	var lineLength int
	fmt.Scan(&linesCount)
	fmt.Scan(&lineLength)
	board := make([]string, linesCount)
	for i, _ := range board {
		fmt.Scan(&board[i])
	}
	for i, line := range board {
		for j, ch := range line {
			if ch != '*' {
				var expected int8 = 0
				if ch != '.' {
					expected = int8(ch) - int8('0')
				}
				var actual int8 = 0
				if j > 0 && (line[j - 1] == '*'){
					actual++
				}
				if j < lineLength - 1 && (line[j + 1] == '*'){
					actual++
				}
				if i > 0 {
					if board[i-1][j] == '*' {
						actual++
					}
					if j > 0 && (board[i - 1][j - 1] == '*') {
						actual++
					}
					if j < lineLength - 1 && (board[i - 1][j + 1] == '*') {
						actual++
					}
				}
				if i < linesCount - 1 {
					if board[i+1][j] == '*' {
						actual++
					}
					if j > 0  && (board[i + 1][j - 1] == '*'){
						actual++
					}
					if j < lineLength - 1 && (board[i + 1][j + 1] == '*'){
						actual++
					}
				}
				if actual != expected {
					fmt.Println("NO")
					return
				}
			}
		}
	}
	fmt.Println("YES")
}

package main

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

func Resolve(input string) string {
	rows := strings.Split(input, "\n")
	n, m := parseFieldSize(rows[0])

	gameField := parseGameField(rows, m)

	for i, row := range gameField {
		for j, cell := range row {
			switch cell {
			case ".":
				bombsFound := findBombsNear(gameField, i, j, n, m)
				if bombsFound != 0 {
					// рядом с пустыми ячейками не может быть бомб
					return "NO"
				}
			case "*":
				break
			default:
				numberOfBombs, err := strconv.Atoi(cell)
				if err != nil {
					panic("got unexpected symbol: " + string(cell) + err.Error())
				}

				if numberOfBombs == 0 {
					continue
				}

				bombsFound := findBombsNear(gameField, i, j, n, m)

				if numberOfBombs != bombsFound {
					return "NO"
				}
			}
		}
	}
	return "YES"
}
func findBombsNear(gameField [][]string, rowIdx, cellIdx, fieldRows, fieldCells int) int {
	var bombsFound int

	for i := rowIdx - 1; i <= rowIdx+1; i++ {
		if i < 0 {
			// вышли за поле
			continue
		}

		for j := cellIdx - 1; j <= cellIdx+1; j++ {
			if j < 0 {
				// вышли за поле
				continue
			}

			if (i == rowIdx) && (j == cellIdx) {
				continue
			}

			// вышли за поле вниз
			if i > fieldRows-1 {
				continue
			}

			// вышли за поле направо
			if j > fieldCells-1 {
				continue
			}

			if gameField[i][j] == "*" {
				bombsFound++
			}
		}

	}

	return bombsFound
}

func parseFieldSize(header string) (int, int) {
	fieldSize := strings.Split(header, " ")

	n, err := strconv.Atoi(fieldSize[0])
	if err != nil {
		panic("can't parse field size N: " + fieldSize[0])
	}

	m, err := strconv.Atoi(fieldSize[1])
	if err != nil {
		panic("can't parse field size M: " + fieldSize[1])
	}

	return n, m
}

func parseGameField(rows []string, cells int) [][]string {
	countOfLines := len(rows) - 1 // минус заголовок
	gameField := make([][]string, countOfLines)

	for i := 1; i < countOfLines; i++ {
		gameField[i-1] = make([]string, cells)
		for j := 0; j < cells; j++ {
			gameField[i-1][j] = string(rows[i][j])
		}
	}

	return gameField
}

func main() {
	var (
		line        string
		overalInput string
		scanner     = bufio.NewScanner(os.Stdin)
	)

	if scanner.Scan() {
		line = scanner.Text()
	}

	rowsCount, _ := parseFieldSize(line)
	overalInput += line + "\n"

	for i := 0; i < rowsCount; i++ {
		if scanner.Scan() {
			line = scanner.Text()
		}
		overalInput += line + "\n"
	}

	fmt.Println(Resolve(overalInput))
}

package main

import "fmt"

type T struct {
  code uint8
  nBombs int
}

var (
  n int
  m int
  b byte
  field [100][100]T
)

func Check(i int, j int)bool {
  num:=0;
  if (i-1 >= 0) && (field[i-1][j].code == 0) { num++ }
  if (i+1 < n) && (field[i+1][j].code == 0) { num++ }
  if (j-1 >= 0) && (field[i][j-1].code == 0) { num++ }
  if (j+1 < m) && (field[i][j+1].code == 0) { num++ }
  if ((i-1 >= 0) && (j-1 >= 0)) && (field[i-1][j-1].code == 0) { num++ }
  if ((i+1 < n) && (j-1 >= 0)) && (field[i+1][j-1].code == 0) { num++ }
  if ((i-1 >= 0) && (j+1 < m)) && (field[i-1][j+1].code == 0) { num++ }
  if ((i+1 < n) && (j+1 < m)) && (field[i+1][j+1].code == 0) { num++ }
  return (num == field[i][j].nBombs)
}

func main() {
  s:=""
  fmt.Scanln(&n, &m)
  for i:=0; i < n; i++ {
    fmt.Scanln(&s)
    for j:=0; j < m; j++ {
      if s[j] == '*' {
        field[i][j].code = 0
        field[i][j].nBombs = 99
      } else {
        if s[j] == '.' {
          field[i][j].code = 2
          field[i][j].nBombs = 0
        } else {
          field[i][j].code = 2
          field[i][j].nBombs = int(s[j]) - 48
        }
      }
    }
  }
  f:=true;
  for i:=0; i < n; i++ {
    for j:=0; j < m; j++ {
      if field[i][j].code == 2 {
        f=Check(i,j);
        if !f { break }
      }
    }
    if !f { break }
  }
  if f { fmt.Println("YES")} else {fmt.Println("NO")}
}

// Codeforces 978 F done
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n,m int
var f []string
var valid bool

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading n, k
	n, m, _, _, _ = readFive()
	// reading f
	f = make([]string, n)
	for i:=0; i<n; i++ {
		f[i],_ = in.ReadString('\n')
	}
}

func starCount(i,j int) int {
	cnt := 0
	for di:=-1; di<=1; di++ {
		for dj:=-1; dj<=1; dj++ {
			ii := i+di
			jj := j+dj
			if ii>=0 && ii<n && jj>=0 && jj<m {
				c := (f[ii])[jj]
				isStar := c=='*'
				// fmt.Printf("c,isStar = %c %t\n", c, isStar)
				if isStar {
					cnt++
				}
			}
		}
	}
	return cnt
}

func solve() {
	valid = true
	for i:=0; i<n; i++ {
		for j:=0; j<m; j++ {
			c := f[i][j]
			if c=='*' {
				continue
			}
			cnt := starCount(i, j)
			ccnt := 0
			if '1'<=c && c<='8' {
				ccnt = int(c) - int('0')
			} else if c=='.' {
				ccnt = 0
			} else {
				fmt.Printf("Illegal character %c\n", c)
			}
			if cnt != ccnt {
				// fmt.Printf("Difference. i,j = %d %d  cnt,ccnt = %d %d\n",i,j,cnt,ccnt)
				valid = false
				return
			}
		}
	}
}

func printRes() {
	var ans string
	if valid {
		ans = "Yes"
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}

package main;

import (
	"fmt"
)

func main() {
	var my = [...]int{-1, -1, -1, 0, 0, 1, 1, 1};
	var mx = [...]int{-1, 0, 1, -1, 1, -1, 0, 1};

	var n int;
	var m int;

	fmt.Scan(&n);
	fmt.Scan(&m);

	board := make([]string, n);

	for i, _ := range board {
		fmt.Scan(&board[i]);
	}

	var flag bool = true;

	for i, line := range board {
		for j, ch := range line {
			if ch != '*' {
				var num = -1;
				if ch == '.' {
					num = 0;
				} else {
					num = int(ch) - int('0')
				}

				cnt := 0;
				for k := 0; k < 8; k++ {
					ny := i + my[k];
					nx := j + mx[k];

					if ny < 0 || ny >= n || nx < 0 || nx >= m {
						continue;
					}

					if board[ny][nx] == '*' {
						cnt++;
					}
				}
				// fmt.Println(i, j, cnt, num);
				if cnt != num {
					flag = false;
				}
			}
		}
	}

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

package main

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

func main() {
	var (
		err        error
		input, row string
	)

	inputReader := bufio.NewReader(os.Stdin)

	for err != io.EOF {
		row, err = inputReader.ReadString('\n')
		input += row
	}

	fmt.Print(Solve(input))
}

func Solve(input string) string {
	sourceMx, rows, columns := ParseMatrix(input)

	expectedMx := make([][]byte, rows)

	for i := int64(0); i < rows; i++ {
		expectedMx[i] = make([]byte, columns)

		for j := int64(0); j < columns; j++ {
			expectedMx[i][j] = '.'
		}
	}

	CalculateSaper(rows, columns, sourceMx, expectedMx)

	if MatrixEquals(rows, columns, sourceMx, expectedMx) {
		return "YES"
	}

	return "NO"
}

func CalculateSaper(rows int64, columns int64, sourceMx [][]byte, expectedMx [][]byte) {
	for r := int64(0); r < rows; r++ {
		for c := int64(0); c < columns; c++ {
			if sourceMx[r][c] == '*' {
				for er := r - 1; er <= r+1; er++ {
					for ec := c - 1; ec <= c+1; ec++ {
						if er < 0 || er >= rows {
							continue
						}

						if ec < 0 || ec >= columns {
							continue
						}

						if er == r && ec == c {
							expectedMx[er][ec] = '*'
							continue
						}

						if expectedMx[er][ec] == '.' {
							expectedMx[er][ec] = '0'
						}

						if expectedMx[er][ec] != '*' {
							expectedMx[er][ec]++
						}
					}
				}
			}
		}
	}
}

func ParseMatrix(input string) (mx [][]byte, rows int64, columns int64) {
	inputReader := bufio.NewReader(bytes.NewBufferString(input))
	row, _ := inputReader.ReadString('\n')
	fmt.Sscanf(row, "%d %d", &rows, &columns)

	mx = make([][]byte, rows)

	for n := int64(0); n < rows; n++ {
		row, _ := inputReader.ReadString('\n')

		mx[n] = make([]byte, columns)

		for m := int64(0); m < columns; m++ {
			mx[n][m] = row[m]
		}
	}

	return
}

func MatrixEquals(rows int64, columns int64, left, right [][]byte) bool {
	for r := int64(0); r < rows; r++ {
		for c := int64(0); c < columns; c++ {
			if left[r][c] != right[r][c] {
				return false
			}
		}
	}

	return true
}

package main

import (
	"fmt"
	"strconv"
)

func emptyMatrix(r,c int) [][]int{
	__ := make([][]int, r)
	for i := 0; i < r; i++{
		 __[i] = make([]int,c)
	}
	return __
}

func neighBombs(mapp [][]int, loc [2]int) int {
	n_bombs := 0
	neighbours := [][]int{
		{loc[0]-1, loc[1]-1},
		{loc[0]-1, loc[1]},
		{loc[0]-1, loc[1]+1},
		{loc[0], loc[1]-1},
		{loc[0], loc[1]+1},
		{loc[0]+1, loc[1]-1},
		{loc[0]+1, loc[1]},
		{loc[0]+1, loc[1]+1},
	}
	for _, path := range neighbours{
		if (0 <= path[0]) && (path[0] < len(mapp)) && (0 <= path[1]) && (path[1] < len(mapp[0])){
			if mapp[path[0]][path[1]] == -1 {
				n_bombs+=1
			}
		}
	}
	return n_bombs
}

func main() {
	var r,c,temp_digit int
	var ln string
	fmt.Scanln(&r,&c)
	mapp := emptyMatrix(r,c)
	for i := 0;i < r; i++ {
		fmt.Scanln(&ln)
		for j := 0; j < c;j++ {
			if ln[j] == '.'{
				mapp[i][j] = 0
				continue
			}
			if ln[j] == '*' {
				mapp[i][j] = -1
				continue
			}
			temp_digit,_ = strconv.Atoi(string(ln[j]))
			mapp[i][j] = temp_digit
		}
	}
	for rows := 0; rows < len(mapp); rows++{
		for col := 0; col < len(mapp[0]); col++{
			if mapp[rows][col] != neighBombs(mapp, [2]int{rows,col}) && mapp[rows][col] != -1 {
				fmt.Print("NO")
				return
			}
		}
	}
	fmt.Print("YES")
}

package main;

import (
	"fmt"
)

func main() {
	var my = [...]int{-1, -1, -1, 0, 0, 1, 1, 1};
	var mx = [...]int{-1, 0, 1, -1, 1, -1, 0, 1};

	var n int;
	var m int;

	fmt.Scan(&n);
	fmt.Scan(&m);

	board := make([]string, n);

	for i, _ := range board {
		fmt.Scan(&board[i]);
	}

	var flag bool = true;

	for i, line := range board {
		for j, ch := range line {
			if ch != '*' {
				var num = -1;
				if ch == '.' {
					num = 0;
				} else {
					num = int(ch) - int('0')
				}

				cnt := 0;
				for k := 0; k < 8; k++ {
					ny := i + my[k];
					nx := j + mx[k];

					if ny < 0 || ny >= n || nx <= 0 || nx >= m {
						continue;
					}

					if board[ny][nx] == '*' {
						cnt++;
					}
				}
				// fmt.Println(i, j, cnt, num);
				if cnt != num {
					flag = false;
				}
			}
		}
	}

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


package main

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

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

	var T, n int
	var a, b, c string
	var s []byte
	f := func(a, b string) {
		c0 := strings.Count(a, "0")
		if c0 >= n != (strings.Count(b, "0") >= n) {
			return
		}
		tar := byte('0')
		if c0 < n {
			tar = '1'
		}
		s = nil
		i, j := 0, 0
		for i < 2*n && j < 2*n {
			if a[i] == b[j] {
				s = append(s, a[i])
				i++
				j++
			} else if a[i] != tar {
				s = append(s, a[i])
				i++
			} else {
				s = append(s, b[j])
				j++
			}
		}
		s = append(s, a[i:]...)
		s = append(s, b[j:]...)
	}
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &a, &b, &c)
		f(a, b)
		f(a, c)
		f(b, c)
		Fprintln(out, string(s))
	}
}
func main() { CF1508A(os.Stdin, os.Stdout) }

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)
	for tc > 0 {
		tc--
		n := readNum(reader)
		A, _ := reader.ReadString('\n')
		B, _ := reader.ReadString('\n')
		C, _ := reader.ReadString('\n')
		res := solve(n, A, B, C)
		buf.WriteString(res)
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A, B, C string) string {
	var p1, p2, p3 int
	var buf bytes.Buffer

	N := 2 * n
	for p1 < N && p2 < N && p3 < N {
		if A[p1] == B[p2] {
			buf.WriteByte(A[p1])
			p1++
			p2++
		} else if A[p1] == C[p3] {
			buf.WriteByte(A[p1])
			p1++
			p3++
		} else {
			// B[p2] == C[p3]
			buf.WriteByte(B[p2])
			p2++
			p3++
		}
	}
	l := buf.Len() - n
	if p1 == N {
		if p2 >= l {
			buf.WriteString(B[p2:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else if p2 == N {
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else {
		// p3 == N
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(B[p2:N])
		}
	}

	return buf.String()
}

package main

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

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--
		var n int
		fmt.Fscan(in, &n)
		v := make([]string, 3)
		at := make([][]int, 2)
		for i := 0; i < 3; i++ {
			fmt.Fscan(in, &v[i])
			count := 0
			for _, c := range v[i] {
				if c == '1' {
					count++
				}
			}
			idx := 0
			if count >= n {
				idx = 1
			}
			at[idx] = append(at[idx], i)
		}
		idx := 0
		if len(at[0]) < 2 {
			idx = 1
		}
		w := &strings.Builder{}
		i, j := 0, 0
		x := '0'
		if idx == 1 {
			x = '1'
		}
		for i < len(v[at[idx][0]]) && j < len(v[at[idx][1]]) {
			if v[at[idx][0]][i] == v[at[idx][1]][j] {
				w.WriteByte(v[at[idx][0]][i])
				i++
				j++
			}else {
				if rune(v[at[idx][1]][j]) != x {
					w.WriteByte(v[at[idx][1]][j])
					j++
				}else {
					w.WriteByte(v[at[idx][0]][i])
					i++
				}
			}
		}
		w.WriteString(v[at[idx][0]][i:])
		w.WriteString(v[at[idx][1]][j:])
		fmt.Fprintln(out, w.String())
	}
}

package main

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

func main() {

	/*rand.Seed(time.Now().Unix())

	str := "01"

	for k := 0; k < 1000; k++ {
		var bts bytes.Buffer
		for j := 0; j < 10; j++ {
			idx := rand.Intn(2)
			b := str[idx]
			bts.WriteByte(b)
		}
		aa := bts.String()

		bts = bytes.Buffer{}
		for j := 0; j < 10; j++ {
			idx := rand.Intn(2)
			b := str[idx]
			bts.WriteByte(b)
		}
		bb := bts.String()

		bts = bytes.Buffer{}
		for j := 0; j < 10; j++ {
			idx := rand.Intn(2)
			b := str[idx]
			bts.WriteByte(b)
		}
		cc := bts.String()

		ans := solve(aa, bb, cc, 5)

		var count int

		if len(ans) > 15 {
			panic("Incorrect len " + strconv.Itoa(len(ans)))
		}

		idx := 0
		for j := 0; j < len(ans); j++ {
			a := ans[j]

			if a == aa[idx] {
				idx++

				if idx >= 10 {
					count++
					break
				}
			}
		}

		idx = 0
		for j := 0; j < len(ans); j++ {
			a := ans[j]

			if a == bb[idx] {
				idx++

				if idx >= 10 {
					count++
					break
				}
			}
		}

		idx = 0
		for j := 0; j < len(ans); j++ {
			a := ans[j]

			if a == cc[idx] {
				idx++

				if idx >= 10 {
					count++
					break
				}
			}
		}

		if count < 2 {
			fmt.Println(aa)
			fmt.Println(bb)
			fmt.Println(cc)
			fmt.Println(ans)
			panic("Count less then two")
		}

	}*/

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int

		fmt.Fscan(r, &n)

		var a, b, c string
		fmt.Fscan(r, &a)
		fmt.Fscan(r, &b)
		fmt.Fscan(r, &c)

		ans := solve(a, b, c, n)

		fmt.Println(ans)
	}
}

func solve(a, b, c string, n int) string {
	n = 2 * n

	var ans bytes.Buffer

	var aZer int
	var aOne int

	for i:= 0; i < n; i++ {
		if a[i] == '0' {
			aZer++
		} else if a[i] == '1' {
			aOne++
		} else {
			panic("unknown" + string(a[i]))
		}
	}

	var bZer int
	var bOne int

	for i:= 0; i < n; i++ {
		if b[i] == '0' {
			bZer++
		} else if b[i] == '1' {
			bOne++
		} else {
			panic("unknown" + string(b[i]))
		}
	}

	var cZer int
	var cOne int

	for i:= 0; i < n; i++ {
		if c[i] == '0' {
			cZer++
		} else if c[i] == '1' {
			cOne++
		} else {
			panic("unknown" + string(c[i]))
		}
	}

	first, second, char := getTwo(a, b, c, aZer, aOne, bZer, bOne, cZer, cOne)

	opposite := getOpposite(char)

	key := 0
	mp := make(map[int]int)

	for  i := 0; i < n; i++ {
		if second[i] == opposite {
			mp[key]++
		} else {
			key++
		}
	}

	key = 0

	for i := 0; i < n; i++ {
		f := first[i]

		if f == char {
			n := mp[key]

			for j := 0; j < n; j++ {
				ans.WriteByte(opposite)
			}

			ans.WriteByte(f)
			key++

		} else {
			ans.WriteByte(f)
		}
	}

	if v , ok := mp[key]; ok {

		for j := 0; j < v; j++ {
			ans.WriteByte(opposite)
		}
	}

	return ans.String()
}

func getOpposite(c byte) byte {
	if c == '1' {
		return '0'
	} else if c == '0' {
		return '1'
	}
	panic("unknown" + string(c))
}

func getTwo(a, b, c string, aZer, aOne, bZer, bOne, cZer, cOne int) (string, string, byte) {
	if aZer >= aOne {
		if bZer >= bOne {
			//todo take a b 0
			if aZer >= bZer {
				return a, b, '0'
			} else {
				return b, a, '0'
			}

		} else {

			if cZer >= cOne {
				if aZer >= cZer {
					return a, c, '0'
				} else {
					return c, a, '0'
				}
				//todo take a c 0

			} else {
				if bOne >= cOne {
					return b, c, '1'
				} else {
					return c, b, '1'
				}
				//todo take b c 1
			}
		}

	} else {
		if bZer >= bOne {

			if cZer >= cOne {
				if bZer >= cZer {
					return b, c, '0'
				} else {
					return c, b, '0'
				}
				//todo take b, c 0

			} else {
				if aOne >= cOne {
					return a, c, '1'
				} else {
					return c, a, '1'
				}
				//todo take a, c 1

			}
		} else {
			if aOne >= bOne {
				return a, b, '1'
			} else {
				return b, a, '1'
			}
			//todo take a, b 1
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)
	for tc > 0 {
		tc--
		n := readNum(reader)
		A, _ := reader.ReadString('\n')
		B, _ := reader.ReadString('\n')
		C, _ := reader.ReadString('\n')
		res := solve(n, A, B, C)
		buf.WriteString(res)
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A, B, C string) string {
	v0 := make([]string, 0, 2)
	v1 := make([]string, 0, 2)
	if label(n, A) {
		v0 = append(v0, A)
	} else {
		v1 = append(v1, A)
	}
	if label(n, B) {
		v0 = append(v0, B)
	} else {
		v1 = append(v1, B)
	}
	if label(n, C) {
		v0 = append(v0, C)
	} else {
		v1 = append(v1, C)
	}

	if len(v0) > 1 {
		return mix(n, v0[0], v0[1], '0')
	}
	return mix(n, v1[0], v1[1], '1')
}

func mix(n int, a, b string, c byte) string {
	v1 := make([]int, 0, n)
	v2 := make([]int, 0, n)
	v1 = append(v1, -1)
	v2 = append(v2, -1)

	for i := 0; i < 2*n; i++ {
		if a[i] == c {
			v1 = append(v1, i)
		}
		if b[i] == c {
			v2 = append(v2, i)
		}
	}

	var res bytes.Buffer

	for i := 0; i < n; i++ {
		for j := v1[i] + 1; j < v1[i+1]; j++ {
			res.WriteByte(a[j])
		}
		for j := v2[i] + 1; j < v2[i+1]; j++ {
			res.WriteByte(b[j])
		}
		res.WriteByte(c)
	}

	for j := v1[n] + 1; j < 2*n; j++ {
		res.WriteByte(a[j])
	}
	for j := v2[n] + 1; j < 2*n; j++ {
		res.WriteByte(b[j])
	}

	return res.String()
}

func label(n int, s string) bool {
	var cnt0 int
	for i := 0; i < 2*n; i++ {
		if s[i] == '0' {
			cnt0++
		}
	}
	return cnt0 >= n
}

func solve1(n int, A, B, C string) string {
	var p1, p2, p3 int
	var buf bytes.Buffer

	N := 2 * n
	for p1 < N && p2 < N && p3 < N {
		if A[p1] == B[p2] {
			buf.WriteByte(A[p1])
			p1++
			p2++
		} else if A[p1] == C[p3] {
			buf.WriteByte(A[p1])
			p1++
			p3++
		} else {
			// B[p2] == C[p3]
			buf.WriteByte(B[p2])
			p2++
			p3++
		}
	}
	l := buf.Len() - n
	if p1 == N {
		if p2 >= l {
			buf.WriteString(B[p2:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else if p2 == N {
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else {
		// p3 == N
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(B[p2:N])
		}
	}

	return buf.String()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)
	for tc > 0 {
		tc--
		n := readNum(reader)
		A, _ := reader.ReadString('\n')
		B, _ := reader.ReadString('\n')
		C, _ := reader.ReadString('\n')
		res := solve(n, A, B, C)
		buf.WriteString(res)
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A, B, C string) string {
	var p1, p2, p3 int
	var buf bytes.Buffer

	N := 2 * n
	for p1 < N && p2 < N && p3 < N {
		if A[p1] == B[p2] {
			buf.WriteByte(A[p1])
			p1++
			p2++
		} else if A[p1] == C[p3] {
			buf.WriteByte(A[p1])
			p1++
			p3++
		} else {
			// B[p2] == C[p3]
			buf.WriteByte(B[p2])
			p2++
			p3++
		}
	}
	l := (N - buf.Len()) / 2
	if p1 == N {
		if p2 >= l {
			buf.WriteString(B[p2:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else if p2 == N {
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(C[p3:N])
		}
	} else {
		// p3 == N
		if p1 >= l {
			buf.WriteString(A[p1:N])
		} else {
			buf.WriteString(B[p2:N])
		}
	}

	return buf.String()
}

package main

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

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--
		var n int
		fmt.Fscan(in, &n)
		v := make([]string, 3)
		at := make([][]int, 2)
		for i := 0; i < 3; i++ {
			fmt.Fscan(in, &v[i])
			count := 0
			for _, c := range v[i] {
				if c == '1' {
					count++
				}
			}
			idx := 0
			if count > n {
				idx = 1
			}
			at[idx] = append(at[idx], i)
		}
		idx := 0
		if len(at[0]) < 2 {
			idx = 1
		}
		w := &strings.Builder{}
		i, j := 0, 0
		x := '0'
		if idx == 1 {
			x = '1'
		}
		for i < len(v[at[idx][0]]) && j < len(v[at[idx][1]]) {
			if v[at[idx][0]][i] == v[at[idx][1]][j] {
				w.WriteByte(v[at[idx][0]][i])
				i++
				j++
			}else {
				w.WriteByte(v[at[idx][0]][i])
				i++
				if rune(v[at[idx][1]][j]) != x {
					w.WriteByte(v[at[idx][1]][j])
					j++
				}
			}
		}
		w.WriteString(v[at[idx][0]][i:])
		w.WriteString(v[at[idx][1]][j:])
		fmt.Fprintln(out, w.String())
	}
}

package main

import (
	"bufio"
	"os"

	"fmt"
	"bytes"
)

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int

		fmt.Fscan(r, &n)

		var a, b, c string
		fmt.Fscan(r, &a)
		fmt.Fscan(r, &b)
		fmt.Fscan(r, &c)

		ans := solve(a, b, c, n)

		fmt.Println(ans)
	}
}

func solve(a, b, c string, n int) string {
	n = 2 * n

	var ans bytes.Buffer

	var aZer int
	var aOne int

	for i:= 0; i < n; i++ {
		if a[i] == '0' {
			aZer++
		} else if a[i] == '1' {
			aOne++
		} else {
			panic("unknown" + string(a[i]))
		}
	}

	var bZer int
	var bOne int

	for i:= 0; i < n; i++ {
		if b[i] == '0' {
			bZer++
		} else if b[i] == '1' {
			bOne++
		} else {
			panic("unknown" + string(b[i]))
		}
	}

	var cZer int
	var cOne int

	for i:= 0; i < n; i++ {
		if c[i] == '0' {
			cZer++
		} else if c[i] == '1' {
			cOne++
		} else {
			panic("unknown" + string(c[i]))
		}
	}

	first, second, char := getTwo(a, b, c, aZer, aOne, bZer, bOne, cZer, cOne)

	opposite := getOpposite(char)

	key := 0
	mp := make(map[int]int)

	for  i := 0; i < n; i++ {
		if second[i] == opposite {
			mp[key]++
		} else {
			key++
		}
	}

	key = 0

	for i := 0; i < n; i++ {
		f := first[i]

		if f == char {
			n := mp[key]

			for j := 0; j < n; j++ {
				ans.WriteByte(opposite)

			}

			ans.WriteByte(f)
			key++

		} else {
			ans.WriteByte(f)
		}
	}

	return ans.String()
}

func getOpposite(c byte) byte {
	if c == '1' {
		return '0'
	} else if c == '0' {
		return '1'
	}
	panic("unknown" + string(c))
}

func getTwo(a, b, c string, aZer, aOne, bZer, bOne, cZer, cOne int) (string, string, byte) {
	if aZer >= aOne {
		if bZer >= bOne {
			//todo take a b 0
			if aZer >= bZer {
				return a, b, '0'
			} else {
				return b, a, '0'
			}

		} else {

			if cZer >= cOne {
				if aZer >= cZer {
					return a, c, '0'
				} else {
					return c, a, '0'
				}
				//todo take a c 0

			} else {
				if bOne >= cOne {
					return b, c, '1'
				} else {
					return c, b, '1'
				}
				//todo take b c 1
			}
		}

	} else {
		if bZer >= bOne {

			if cZer >= cOne {
				if bZer >= cZer {
					return b, c, '0'
				} else {
					return c, b, '0'
				}
				//todo take b, c 0

			} else {
				if aOne >= bOne {
					return a, c, '1'
				} else {
					return c, a, '1'
				}
				//todo take a, c 1

			}
		} else {
			if aOne >= bOne {
				return a, b, '1'
			} else {
				return b, a, '1'
			}
			//todo take a, b 1
		}
	}
}

package main

import (
	"bufio"
	"os"

	"fmt"
	"bytes"
)

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int

		fmt.Fscan(r, &n)

		var a, b, c string
		fmt.Fscan(r, &a)
		fmt.Fscan(r, &b)
		fmt.Fscan(r, &c)

		ans := solve(a, b, c, n)

		fmt.Println(ans)
	}
}

func solve(a, b, c string, n int) string {

	n = 2 * n

	diff := make([]bool, len(a))

	for i := 0 ; i < len(a); i++ {
		if a [i] != b[i] {
			diff[i] = true
		}
	}

	var aCount int
	var bCount int

	for i := 0; i < n; i++ {
		if diff[i] == true {
			if a[i] == c[i] {
				aCount++
			} else {
				bCount++
			}
		}
	}

	var ans bytes.Buffer

	if aCount > bCount {

		for i := 0; i < n; i++ {
			if diff[i] == true  {
				ans.WriteRune(rune(a[i]))
				ans.WriteRune(rune(c[i]))
			} else {
				ans.WriteRune(rune(a[i]))
			}
		}

	} else {
		for i := 0; i < n; i++ {
			if diff[i] == true  {
				ans.WriteRune(rune(b[i]))
				ans.WriteRune(rune(c[i]))
			} else {
				ans.WriteRune(rune(b[i]))
			}
		}
	}

	return ans.String()
}


package main

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

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

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		i := n - 2
		max := n - 1
		choose := []int{n - 2, n - 1}
		for ; i >= 0; i-- {
			if nums[i]-nums[max] < nums[choose[0]]-nums[choose[1]] {
				choose = []int{i, max}
			}
			if nums[max] < nums[i] {
				max = i
			}
			if nums[i] > nums[i+1] {
				break
			}
		}
		if i == -1 {
			fmt.Fprintln(out, 0)
			continue
		}
		if i == n-2 || nums[choose[0]]-nums[choose[1]] > nums[i+1] {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, i+1)
		for j := 0; j < i+1; j++ {
			fmt.Fprintln(out, j+1, choose[0]+1, choose[1]+1)
		}
	}
}

// 1 0 1 2

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 0 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			// UPDATE: since 0 case is similar to positive case including it here
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] > arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i ++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, 0, n)
		for j := 0; j < n; j ++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
			continue
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, 0)
			continue
		}
		if arr[n-1] < 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		fmt.Fprintln(out, n-2)
		for j := 1; j < n-1; j ++ {
			fmt.Fprintln(out, j, n-1, n)
		}
	}
}

package main

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

/*
2
5
3 2 5 1 5
4
2 -5 -1 4
---
3		-4 -4 -4 1 5
1 4 5
2 4 5
3 4 5
2
1 3 4
2 3 4
=======
4
3
1 0 1
3
-1 0 1
4
-3 2 5 4
4
-3 2 5 9
---
1
1 2 3
0
-1
0
=======
1
6
1 5 6 4 3 -5
---
-1

*/

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

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int64, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		diff := a[n-2] - a[n-1]

		sortFunc := func(i, j int) bool {
			return a[i] < a[j]
		}

		if sort.SliceIsSorted(a, sortFunc) {
			fmt.Fprintln(writer, 0)
		} else if a[n-1] < a[n-2] || a[n-2] < diff {
			fmt.Fprintln(writer, -1)
		} else {
			fmt.Fprintln(writer, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(writer, "%d %d %d\n", i+1, n-1, n)
			}
		}
	}
}

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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx], idx
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		isInc := true
		var curr int
		var prev int
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &curr)
			if j > 0 && prev > curr {
				isInc = false
			}
			if j < n-1 {
				prev = curr
			}
		}
		if isInc {
			fmt.Println(0)
		} else if curr < 0 || prev > curr {
			fmt.Println(-1)
		} else {
			fmt.Println(n - 2)
			for j := n - 2; j > 0; j-- {
				fmt.Println(j, j+1, n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := 0; i < n-1; i++ {
				if arr[i] > arr[i+1] {
					fmt.Fprintln(out, -1)
					break
				} else if i == n-2 {
					fmt.Fprintln(out, 0)
				}
			}
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

	var t int
	Fscan(in, &t)
	var solve func()
	solve = func() {

		var n int
		Fscan(in, &n)
		a := make([]int, n)
		flag := true
		for j := 0; j < n; j++ {
			Fscan(in, &a[j])
			if j != 0 && a[j-1] > a[j] {
				flag = false
			}
		}
		if flag {
			Fprintln(out, 0)
			return
		}
		if a[n-2] > a[n-1] {
			Fprintln(out, -1)
			return
		}
		if a[n-1] >= 0 {
			Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				Fprintln(out, i+1, n-1, n)
			}
		} else {
			Fprintln(out, -1)
			return
		}
	}
	for i := 0; i < t; i++ {
		solve()
	}

}

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

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		if sort.IntsAreSorted(arr) {
			fmt.Fprintln(out, 0)
		} else if arr[n-2] > arr[n-1] || arr[n-2]-arr[n-1] > arr[n-2] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

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

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int64, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		if arr[n] == 0 {
			Fprintln(out, n-2)
			for i := 1; i <= n-2; i++ {
				Fprintf(out, "%d %d %d\n", i, n-1, n)
			}
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}
	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

package main

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

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	// ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		// if arr[n] == 0 {
		Fprintln(out, n-2)
		for i := 1; i <= n-2; i++ {
			Fprintf(out, "%d %d %d\n", i, n-1, n)
		}
		// continue Outer
		// }
		// a := arr[n]
		// ans = ans[:0]
		// times := 0
		// for i := n - 2; i >= 1; i-- {
		//     if arr[i] > arr[i+1] {
		//         arr[i] = arr[i+1] - a
		//         times++
		//         ans = append(ans, [3]int{i, i + 1, n})
		//     }
		// }
		// Fprintln(out, times)
		// for _, v := range ans {
		//     Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		// }
	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-1, n)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := 0; i < n-1; i++ {
				if arr[i] < arr[i+1] {
					fmt.Fprintln(out, -1)
					break
				} else if  i == n-2 {
					fmt.Fprintln(out, 0)
				}
			}
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n).
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-1; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		ans := [][]int{}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 { //直接倒着来一遍
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					ans = append(ans, []int{i, i + 1, n})
					arr[i-1] = arr[i] - arr[n-1]
				}
			}
			fmt.Fprintln(out, len(ans))
			for _, a := range ans {
				fmt.Fprintln(out, a[0], "", a[1], "", a[2])
			}
		}
	}
}

package main

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

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

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		ans := [][]int{}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 { //直接倒着来一遍
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					ans = append(ans, []int{i, i + 1, n})
					arr[i-1] = arr[i] - arr[n-1]
				}
			}
			fmt.Fprintln(out, len(ans))
			for _, a := range ans {
				fmt.Fprintln(out, a[0], " ", a[1], " ", a[2])
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if sort.IntsAreSorted(arr) {
			fmt.Fprintln(out, 0)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := [][]int{}
			for i := n - 3; i >= 0; i-- {
				if arr[i] > d {
					arr[i] = d
					d = arr[i] - arr[n-1]
					s = append(s, []int{i + 1, n - 1, n})
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			p := n - 2
			d := arr[p] - arr[n-1]
			s := [][]int{}
			for i := n - 3; i >= 0; i-- {
				if arr[i] > d {
					arr[i] = d
					d = arr[i] - arr[n-1]
					s = append(s, []int{i + 1, p + 1, n})
					p = i
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		mins := make([]int, n)
		maxes := make([]int, n)
		min := n - 1
		max := n - 1
		mins[n-1] = min
		maxes[n-1] = max
		for i := n - 2; i >= 0; i-- {
			if arr[i] < arr[min] {
				min = i
			}
			if arr[i] > arr[max] {
				max = i
			}
			mins[i] = min
			maxes[i] = max
		}

		// fmt.Println(mins)
		// fmt.Println(maxes)

		s := [][]int{}
		f := true
		for i := 0; i < n-1; i++ {
			if arr[i] > arr[i+1] {
				if i == n-2 || arr[mins[i+1]]-arr[maxes[i+1]] > arr[i+1] {
					f = false
					break
				}

				s = append(s, []int{i + 1, mins[i+1] + 1, maxes[i+1] + 1})
			}
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

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

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		if arr[n] == 0 {
			Fprintln(out, n-2)
			for i := 1; i <= n-2; i++ {
				Fprintf(out, "%d %d %d\n", i, n-1, n)
			}
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}

	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

package main

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

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] <= 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}

	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-2, n-1)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-1, n-2)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i, n-2, n-1)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 1 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] > arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 1 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] >= arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

package main

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

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

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		i := n - 2
		max := n - 1
		choose := []int{n - 1, n - 2}
		for ; i >= 0; i-- {
			if nums[i]-nums[max] < nums[choose[0]]-nums[choose[1]] {
				choose = []int{i, max}
			}
			if nums[max] < nums[i] {
				max = i
			}
			if nums[i] > nums[i+1] {
				break
			}
		}
		if i == -1 {
			fmt.Fprintln(out, 0)
			continue
		}
		if i == n-2 || nums[choose[0]]-nums[choose[1]] > nums[i+1] {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, i+1)
		for j := 0; j < i+1; j++ {
			fmt.Fprintln(out, j+1, choose[0]+1, choose[1]+1)
		}
	}
}

// 1 0 1 2

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i ++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for j := 0; j < n; j ++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		if arr[len(arr)-2] > arr[len(arr)-1] {
			fmt.Fprint(out, -1)
			continue
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			continue
		}
		fmt.Fprintln(out, n-2)
		for j := 0; j < n-2; j ++ {
			fmt.Fprintln(out, j, n-2, n-1)
		}
	}
}

package main

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

/*
1
5
3 2 5 1 5
---
-4 -4 -4 1 5

*/

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

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int64, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		diff := a[n-1] - a[n-2]

		sortFunc := func(i, j int) bool {
			return a[i] < a[j]
		}

		if sort.SliceIsSorted(a, sortFunc) {
			fmt.Fprintln(writer, 0)
		} else if a[n-1] < a[n-2] || diff < a[n-2] {
			fmt.Fprintln(writer, -1)
		} else {
			fmt.Fprintln(writer, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(writer, "%d %d %d\n", i+1, n-1, n)
			}
		}
	}
}

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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx], idx
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		isInc := true
		var curr int
		var prev int
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &curr)
			if j > 0 && prev > curr {
				isInc = false
			}
			if j < n-1 {
				prev = curr
			}
		}
		if isInc {
			fmt.Println(0)
		} else if curr < 0 || prev > curr {
			fmt.Println(-1)
		} else {
			for j := n - 2; j > 0; j-- {
				fmt.Println(j, j+1, n)
			}
		}
	}
}