import java.io.PrintWriter import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.ClassTag import scala.util.* import scala.annotation.tailrec import scala.collection.mutable class Bit(val size: Int): private val vec = Array.fill(size){0} def get(position: Int): Int = var pos = position var result = 0 while pos >= 0 do result += vec(pos) pos -= ~pos & (pos + 1) result def add(position: Int, value: Int) = var pos = position while pos < size do vec(pos) += value pos += ~pos & (pos + 1) def solve(n: Int, permutation: Array[Int]): Option[ArrayBuffer[Int]] = val result = ArrayBuffer[Int]() val bit = Bit(n) for (p, i) <- permutation.zipWithIndex do if i != p then val left = i - bit.get(p) result.addAll(i until i - left by - 1) else if bit.get(p) != i then return None bit.add(p, 1) Some(result) @main def main = val testCount = readLine().toInt for testCase <- 1 to testCount do val n = readLine().toInt val permutation = readLine().split(' ').map(_.toInt - 1) solve(n, permutation) match case Some(result) => println(result.size) println(result.mkString(" ")) case None => println(-1)