package main

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

func main() {
	var n, t, idx int
	var data [105]int

	in := bufio.NewReader ( os.Stdin )

	fmt.Fscan ( in, &t )
	for t > 0 {
		t--
		fmt.Fscan ( in, &n )
		var used [105]bool
		for i := 0 ; i < n ; i++ {
			fmt.Fscan ( in, &data[i] )
		}

		tms := n - 1
		for i := 1 ; tms > 0 && i <= n ; i++ {
			for j := 0 ; j < n ; j++ {
				if data[j] == i {
					idx = j;
					break;
				}
			}

			if idx == i - 1{
				continue
			}

			for idx != i - 1 && !used[idx - 1] && tms > 0 && data[idx] < data[idx - 1] {
				tmp := data[idx]
				data[idx] = data[idx - 1]
				data[idx - 1] = tmp
				used[idx - 1] = true
				idx--
				tms--
			}
		}

		for i := 0 ; i < n ; i++ {
			fmt.Printf ( "%d ", data[i] )
		}

		fmt.Println()
	}
}

	// int t, n, idx, tms;
	// vi data;
	// cin >> t;
	// while ( t-- ){
	// 	cin >> n;
	// 	GETDATA ( data, n );
	// 	MEM ( used, 0 );
	// 	tms = n - 1;
	// 	for ( int i = 1 ; tms && i <= n ; ++i ){
	// 		REPP ( j, 0, n ){
	// 			if ( data[j] == i ){
	// 				idx = j;
	// 				break;
	// 			}
	// 		}

	// 		if ( idx == i - 1 )
	// 			continue;

	// 		while ( idx != i - 1 && !used[idx - 1] && tms && data[idx] < data[idx - 1] ){
	// 			swap ( data[idx], data[idx - 1] );
	// 			// cout << "\t" << idx << ' ' << idx - 1 << '\n';
	// 			used[idx - 1] = true;
	// 			--idx;
	// 			--tms;
	// 		}
	// 	}

	// 	PIO ( data );
	// 	// for ( int i = 0 ; i < n ; i++ ) // del
	// 		// cout << used[i] << ' '; // del
	// 	// cout << '\n'; // del
	// }

// Author: sighduck
// URL: https://codeforces.com/contest/1256/problem/B

package main

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

type Min struct {
	Elem  int
	Index int
}

func solve(array []int, leftIndex int, mins []Min) []int {
	if leftIndex == len(array)-1 {
		return array
	} else if array[leftIndex] < mins[0].Elem {
		return solve(array, leftIndex+1, mins)
	} else {
		for i := mins[0].Index; i > leftIndex; i-- {
			array[i], array[i-1] = array[i-1], array[i]
		}
		return solve(array, mins[0].Index, mins[1:])
	}
}

func getMins(p []int) []Min {
	m := []Min{
		Min{Elem: p[len(p)-1], Index: len(p) - 1},
	}
	for i := len(p) - 2; i >= 0; i-- {
		if p[i] < m[0].Elem {
			m = append([]Min{{Elem: p[i], Index: i}}, m...)
		}
	}
	return m
}

func Solve(p []int) string {
	solution := solve(p, 0, getMins(p))
	return stringifySolution(solution)
}

func stringifySolution(solution []int) string {
	formattedSolution := []string{}
	for _, elem := range solution {
		formattedSolution = append(formattedSolution, strconv.Itoa(elem))
	}
	return strings.Join(formattedSolution, " ")
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &p[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%s\n", Solve(p))
	}
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(n)
		numOfOperation := int64(0)

		for i := int64(1); i <= n; i++ {
			curVal := int64(indexOf(i, a))
			for j := curVal; j > numOfOperation; j-- {
				a[j], a[j-1] = a[j-1], a[j]
			}
			if numOfOperation == curVal {
				numOfOperation = curVal + 1
			}
			if numOfOperation < curVal {
				numOfOperation = curVal
			}

		}

		line := ""
		for i := int64(0); i < n; i++ {
			line += S(a[i]) + " "
		}
		O <- line
	}
	close(O)
	oWg.Wait()
}

func indexOf(num int64, a []int64) int {
	for i := 0; i < len(a); i++ {
		if a[i] == num {
			return i
		}
	}
	return -1
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()
	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)

		s, t := 0, n
		for s < n-1 {
			idx := findMinimum(A, s, t)
			for i := idx - 1; i >= s; i-- {
				A[i], A[i+1] = A[i+1], A[i]
			}

			if idx == s {
				s++
			} else {
				s = idx
			}
		}
		fmt.Println(PrintIntsLine(A...))
	}
}

func findMinimum(A []int, s, t int) int {
	mini := 1000
	res := -1
	for i := s; i < t; i++ {
		if mini > A[i] {
			mini = A[i]
			res = i
		}
	}
	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)
		k := n - 1

		target := 1
	OUTER_LOOP:
		for k > 0 && target <= n {

			// targetを見つけたらそこでループは打ち切り
			for i := 0; i < n; i++ {
				// targetを見つけるまですすめる
				if A[i] != target {
					continue
				}

				// ここからはtargetを見つけてからの処理

				// targetの位置を記憶
				j := i
				for j > 0 {
					// 前のヤツのほうが小さいならばストップ
					if A[j-1] < A[j] {
						break
					}
					A[j-1], A[j] = A[j], A[j-1]
					j--
					k--
					if k == 0 {
						break OUTER_LOOP
					}
				}
				// あるtargetについて処理が終わったら抜ける
				break
			}

			// 次の数字へ
			target++
		}

		fmt.Println(PrintIntsLine(A...))
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)
		k := n - 1

		flag := true
		for flag && k > 0 {
			flag = false
			for j := n - 1; j > 0; j-- {
				if A[j] < A[j-1] {
					A[j], A[j-1] = A[j-1], A[j]
					flag = true
					k--
					if k == 0 {
						flag = false
						break
					}
				}
			}
		}

		fmt.Println(PrintIntsLine(A...))
	}
}

func bubbleSort(A []int, n int) int {
	res := 0
	flag := true // 逆の隣接要素が存在する
	for flag {
		flag = false
		for j := n - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				A[j], A[j-1] = A[j-1], A[j]
				flag = true
				res++
			}
		}
	}
	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)
		k := n - 1

		target := 1
	OUTER_LOOP:
		for k > 0 && target <= n {
			for i := 0; i < n; i++ {
				if A[i] != target {
					continue
				}

				// targetの位置を記憶
				j := i
				for j > 0 {
					// 前のヤツのほうが小さいならばストップ
					if A[j-1] < A[j] {
						break
					}
					A[j-1], A[j] = A[j], A[j-1]
					j--
					k--
					if k == 0 {
						break OUTER_LOOP
					}
				}

				// 次の数字へ
				target++
			}
		}

		fmt.Println(PrintIntsLine(A...))
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)
		k := n - 1

	OUTER_LOOP:
		for i := 1; i <= n; i++ {
			idx := find(A, i)
			for j := idx; j > 0; j-- {
				if A[j] < A[j-1] {
					A[j], A[j-1] = A[j-1], A[j]
					k--
					if k == 0 {
						break OUTER_LOOP
					}
				}
			}
		}

		fmt.Println(PrintIntsLine(A...))
	}
}

func find(A []int, val int) int {
	for i := 0; i < len(A); i++ {
		if A[i] == val {
			return i
		}
	}
	return -1
}

func bubbleSort(A []int, n int) int {
	res := 0
	flag := true // 逆の隣接要素が存在する
	for flag {
		flag = false
		for j := n - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				A[j], A[j-1] = A[j-1], A[j]
				flag = true
				res++
			}
		}
	}
	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"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])
		// 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 q int

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		n := ReadInt()
		A := ReadIntSlice(n)
		k := n - 1

		flag := true
	OUTER_LOOP:
		for flag && k > 0 {
			flag = false
			for j := n - 1; j > 0; j-- {
				if A[j] < A[j-1] {
					A[j], A[j-1] = A[j-1], A[j]
					flag = true
					k--
					if k == 0 {
						break OUTER_LOOP
					}
				}
			}
		}

		fmt.Println(PrintIntsLine(A...))
	}
}

func bubbleSort(A []int, n int) int {
	res := 0
	flag := true // 逆の隣接要素が存在する
	for flag {
		flag = false
		for j := n - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				A[j], A[j-1] = A[j-1], A[j]
				flag = true
				res++
			}
		}
	}
	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanStringSlice(n)
		sort.Strings(a)
		O <- strings.Join(a, " ")
	}
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%s", v)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(n)
		numOfOperation := int64(0)

		for i := int64(1); i <= n; i++ {
			curVal := int64(indexOf(i, a))
			for j := curVal; j > numOfOperation; j-- {
				a[j], a[j-1] = a[j-1], a[j]
			}
			if numOfOperation < curVal {
				numOfOperation = curVal
			}
		}

		line := ""
		for i := int64(0); i < n; i++ {
			line += S(a[i])
		}
		O <- line
	}
	close(O)
	oWg.Wait()
}

func indexOf(num int64, a []int64) int {
	for i := 0; i < len(a); i++ {
		if a[i] == num {
			return i
		}
	}
	return -1
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(n)
		numOfOperation := int64(0)

		for i := int64(1); i <= n; i++ {
			curVal := int64(indexOf(i, a))
			for j := curVal; j > numOfOperation; j-- {
				a[j], a[j-1] = a[j-1], a[j]
			}
			if numOfOperation < curVal {
				numOfOperation = curVal
			}
		}

		line := ""
		for i := int64(0); i < n; i++ {
			line += S(a[i]) + " "
		}
		O <- line
	}
	close(O)
	oWg.Wait()
}

func indexOf(num int64, a []int64) int {
	for i := 0; i < len(a); i++ {
		if a[i] == num {
			return i
		}
	}
	return -1
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}


package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	cnt := map[int]int{}
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
		cnt[arr[i]]++
	}
	sort.Ints(arr)

	var dfs func(l, r int) int64
	dfs = func(l, r int) int64 {
		if l == r {
			i := sort.Search(k, func(i int) bool { return arr[i] >= l })
			if i < k && arr[i] == l {
				return b * int64(cnt[l])
			}
			return a
		}
		li := sort.Search(k, func(i int) bool { return arr[i] >= l })
		ri := sort.Search(k, func(i int) bool { return arr[i] >= r }) + cnt[r]
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		mid := (l + r) >> 1
		if newAns := dfs(l, mid) + dfs(mid+1, r); newAns < ans {
			ans = newAns
		}
		return ans
	}
	Fprint(out, dfs(1, 1<<uint(n)))
}

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

package main

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

var (
	START      int = 0
	cmap       map[int]int
	n, k, a, b int
)

func add(v int) {
	v += START
	for v > 0 {
		cmap[v]++
		v /= 2
	}
}
func solveC(root, len int) int64 {
	vc := cmap[root]

	if vc == 0 {
		//fmt.Printf("root=%d ans=%d\n",root,a)
		return int64(a)
	}
	ans := int64(len) * int64(b) * int64(vc)
	if len <= 1{
	//	fmt.Printf("root=%d ans=%d\n",root,ans)
		return ans
	}
	tmp := solveC(root*2, len/2) + solveC(root*2+1, len/2)
	if tmp < ans {
		ans = tmp
	}
	//fmt.Printf("root=%d ans=%d\n",root,ans)
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	//fmt.Printf("%d\n",(1 << 2))
	fmt.Fscanf(buf, "%d %d %d %d\n", &n, &k, &a, &b)
	len := (1 << uint32(n))
	START = len-1
	cmap = make(map[int]int)
	for i := 0; i < k; i++ {
		var value int
		fmt.Fscanf(buf, "%d", &value)
		add(value)
	//	fmt.Printf("--%v\n",cmap)
	}

	fmt.Printf("%d\n", solveC(1, len))
}

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	var f func(l, r int) int64
	f = func(l, r int) int64 {
		li := sort.Search(k, func(i int) bool { return arr[i] >= l })
		ri := sort.Search(k-li, func(i int) bool { return arr[i+li] >= r+1 }) + li
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		if l < r {
			mid := (l + r) >> 1
			if newAns := f(l, mid) + f(mid+1, r); newAns < ans {
				ans = newAns
			}
		}
		return ans
	}
	Fprint(out, f(1, 1<<uint(n)))
}

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

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	var f func(l, r int) int64
	f = func(l, r int) int64 {
		i, j := 0, k
		for i < j {
			h := int(uint(i+j) >> 1)
			if arr[h] < l {
				i = h + 1
			} else {
				j = h
			}
		}
		li := i
		i, j = 0, k-li
		for i < j {
			h := int(uint(i+j) >> 1)
			if arr[h+li] < r+1 {
				i = h + 1
			} else {
				j = h
			}
		}
		if i == 0 {
			return a
		}
		ans := b * int64(i) * int64(r-l+1)
		if l < r {
			mid := (l + r) >> 1
			if newAns := f(l, mid) + f(mid+1, r); newAns < ans {
				ans = newAns
			}
		}
		return ans
	}
	Fprint(out, f(1, 1<<uint(n)))
}

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

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	var f func(l, r int) int64
	f = func(l, r int) int64 {
		if l == r {
			li := sort.Search(k, func(i int) bool { return arr[i] >= l })
			if li < k && arr[li] == l {
				ri := sort.Search(k, func(i int) bool { return arr[i] >= l+1 })
				return b * int64(ri-li)
			}
			return a
		}
		li := sort.Search(k, func(i int) bool { return arr[i] >= l })
		ri := sort.Search(k, func(i int) bool { return arr[i] >= r+1 })
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		mid := (l + r) >> 1
		if newAns := f(l, mid) + f(mid+1, r); newAns < ans {
			ans = newAns
		}
		return ans
	}
	Fprint(out, f(1, 1<<uint(n)))
}

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

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	search := func(min int) int {
		i, j := 0, k
		for i < j {
			h := int(uint(i+j) >> 1)
			if arr[h] < min {
				i = h + 1
			} else {
				j = h
			}
		}
		return i
	}
	var f func(l, r int) int64
	f = func(l, r int) int64 {
		li := search(l)
		ri := search(r + 1)
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		if l < r {
			mid := (l + r) >> 1
			if newAns := f(l, mid) + f(mid+1, r); newAns < ans {
				ans = newAns
			}
		}
		return ans
	}
	Fprint(out, f(1, 1<<uint(n)))
}

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

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	var f func(l, r int) int64
	f = func(l, r int) int64 {
		li := sort.Search(k, func(i int) bool { return arr[i] >= l })
		ri := sort.Search(k, func(i int) bool { return arr[i] >= r+1 })
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		if l < r {
			mid := (l + r) >> 1
			if newAns := f(l, mid) + f(mid+1, r); newAns < ans {
				ans = newAns
			}
		}
		return ans
	}
	Fprint(out, f(1, 1<<uint(n)))
}

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

package main

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

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

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

var n, k, a, b, t1 int

var av []int

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func fun(l, r int) int64 {

	//fmt.Println(l, r)

	if l > r {
		return 0
	}

	lo, hi, mid := 0, k+1, 0

	//fmt.Println(av)

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] >= l {
			hi = mid - 1
		} else {
			lo = mid + 1
		}
	}

	ll := hi + 1

	lo, hi, mid = 0, k+1, 0

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] <= r {
			lo = mid + 1
		} else {
			hi = mid - 1
		}
	}

	rr := lo - 1
	// fmt.Println(av)
	// fmt.Println(ll, rr, av[ll], av[rr])

	cnt := 0

	if rr < ll {
		cnt = 0
	} else {
		cnt = rr - ll + 1
	}

	//fmt.Println(l, r, cnt)

	if l == r {

		if cnt >= 1 {
			return int64(b) * int64(cnt)
		} else {
			return int64(a)
		}

	}

	mid = int((int64(l) + int64(r)) / 2)

	if cnt == 0 {
		return int64(a)
	} else {
		return min(int64(b)*int64(cnt)*int64(r-l+1), fun(l, mid)+fun(mid+1, r))
	}

}

func main() {
	defer writer.Flush()

	av = []int{}

	scanf("%d %d %d %d\n", &n, &k, &a, &b)
	// fmt.Println(av)
	for i := 0; i < k; i++ {
		scanf("%d", &t1)
		av = append(av, t1)
	}

	// fmt.Println(av)
	av = append(av, -1)
	av = append(av, (1<<30)+10)

	sort.Ints(av)

	ans := fun(1, 1<<uint(n))

	printf("%d", ans)

}

package main

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

var (
	START      int = 0
	cmap       map[int]int
	n, k, a, b int
)

func add(v int) {
	v += START
	for v > 0 {
		cmap[v]++
		v /= 2
	}
}
func solveC(root, len int) int64 {
	vc := cmap[root]
	if vc == 0 {
		return int64(a)
	}
	ans := int64(len) * int64(b) * int64(vc)
	tmp := solveC(root*2, len/2) + solveC(root*2+1, len/2)
	if tmp < ans {
		ans = tmp
	}
	return ans
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	//fmt.Printf("%d\n",(1 << 2))
	fmt.Fscanf(buf, "%d %d %d %d\n", &n, &k, &a, &b)
	len := (1 << uint32(n))
	START = len-1
	cmap = make(map[int]int)
	for i := 0; i < n; i++ {
		var value int
		fmt.Fscanf(buf, "%d", &value)
		add(value)
	}

	fmt.Printf("%d\n", solveC(1, len))
}

package main

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

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

	var n, k int
	var a, b int64
	Fscan(in, &n, &k, &a, &b)
	n = 1 << uint(n)
	arr := make([]int, k)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	sort.Ints(arr)

	var dfs func(l, r int) int64
	dfs = func(l, r int) int64 {
		if l == r {
			i := sort.Search(k, func(i int) bool { return arr[i] >= l })
			if i < k && arr[i] == l {
				return b
			}
			return a
		}
		li := sort.Search(k, func(i int) bool { return arr[i] >= l })
		ri := sort.Search(k, func(i int) bool { return arr[i] >= r })
		if li == ri {
			return a
		}
		ans := b * int64(ri-li) * int64(r-l+1)
		mid := (l + r) >> 1
		if newAns := dfs(l, mid) + dfs(mid+1, r); newAns < ans {
			ans = newAns
		}
		return ans
	}
	Fprint(out, dfs(1, n))
}

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

package main

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

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

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

var n, k, a, b, t1 int

var av []int

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func fun(l, r int) int64 {

	//fmt.Println(l, r)

	if l > r {
		return 0
	}

	lo, hi, mid := 0, k+1, 0

	//fmt.Println(av)

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] >= l {
			hi = mid - 1
		} else {
			lo = mid + 1
		}
	}

	ll := hi + 1

	lo, hi, mid = 0, k+1, 0

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] <= r {
			lo = mid + 1
		} else {
			hi = mid - 1
		}
	}

	rr := lo - 1
	// fmt.Println(av)
	// fmt.Println(ll, rr, av[ll], av[rr])

	cnt := 0

	if rr < ll {
		cnt = 0
	} else {
		cnt = rr - ll + 1
	}

	//fmt.Println(l, r, cnt)

	if l == r {

		if cnt == 1 {
			return int64(b)
		} else {
			return int64(a)
		}

	}

	mid = int((int64(l) + int64(r)) / 2)

	if cnt == 0 {
		return int64(a)
	} else {
		return min(int64(b)*int64(cnt)*int64(r-l+1), fun(l, mid)+fun(mid+1, r))
	}

}

func main() {
	defer writer.Flush()

	av = []int{}

	scanf("%d %d %d %d\n", &n, &k, &a, &b)
	// fmt.Println(av)
	for i := 0; i < k; i++ {
		scanf("%d", &t1)
		av = append(av, t1)
	}

	// fmt.Println(av)
	av = append(av, -1)
	av = append(av, (1<<30)+10)

	sort.Ints(av)

	ans := fun(1, 1<<uint(n))

	printf("%d", ans)

}

package main

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

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

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

var n, k, a, b, t1 int

var av []int

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func fun(l, r int) int64 {

	//fmt.Println(l, r)

	if l > r {
		return 0
	}

	lo, hi, mid := 0, k+1, 0

	//fmt.Println(av)

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] >= l {
			hi = mid - 1
		} else {
			lo = mid + 1
		}
	}

	ll := hi + 1

	lo, hi, mid = 0, k+1, 0

	for lo <= hi {
		mid = (lo + hi) / 2
		if av[mid] <= r {
			lo = mid + 1
		} else {
			hi = mid - 1
		}
	}

	rr := lo - 1
	// fmt.Println(av)
	// fmt.Println(ll, rr, av[ll], av[rr])

	cnt := 0

	if rr < ll {
		cnt = 0
	} else {
		cnt = rr - ll + 1
	}

	//fmt.Println(l, r, cnt)

	if l == r {

		if cnt == 1 {
			return int64(b) * int64(cnt) * int64(r-l+1)
		} else {
			return int64(a)
		}

	}

	mid = (l + r) / 2

	if cnt == 0 {
		return int64(a)
	} else {
		return min(int64(b)*int64(cnt)*int64(r-l+1), fun(l, mid)+fun(mid+1, r))
	}

}

func main() {
	defer writer.Flush()

	av = []int{}

	scanf("%d %d %d %d\n", &n, &k, &a, &b)
	// fmt.Println(av)
	for i := 0; i < k; i++ {
		scanf("%d", &t1)
		av = append(av, t1)
	}

	// fmt.Println(av)
	av = append(av, -1)
	av = append(av, (1<<31)-1)

	sort.Ints(av)

	ans := fun(1, 1<<uint(n))

	printf("%d", ans)

}


package main

import "fmt"
import "os"
import "bufio"
import "strconv"

func min(a,b int)int {
    var res int
    if a<b {
        res=a
    } else {
        res=b;
    }
    return res;
}

func solve(){
    var s string
    s=readString()
    var n,i,r,c int
    n=len(s)
    r=1
    c=1
    for i=0;i<n;i++{
        if s[i]=='0'{
            fmt.Println(1,c)
            c=c+1
            if c==5{
                c=1
            }
        }else{
            fmt.Println(3,r)
            r=r+2
            if r==5{
                r=1
            }
        }
    }

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}
func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	s := ""
	fmt.Fscanf(in, "%s\n", &s)
	zs := 0
	os := 0
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			zs++
			zs %= 2
			if zs == 1 {
				fmt.Fprintf(out, "%d %d\n", 1, 1)
			} else {
				fmt.Fprintf(out, "%d %d\n", 3, 1)
			}
		} else {
			os++
			os %= 2
			if os == 1 {
				fmt.Fprintf(out, "%d %d\n", 4, 3)
			} else {
				fmt.Fprintf(out, "%d %d\n", 4, 1)
			}
		}
	}
	return
}

func gcd(a, b int) int {
	if a < b {
		return gcd(b, a)
	}
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func solve(ang int) int {
	_ans := 180 / gcd(ang, 180)
	ans := _ans
	for ans*ang/180 > ans-2 {
		ans = ans + _ans
	}
	return ans
}

package main

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

var (
	mod int64 = 1000000007
)

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

	str := make([]byte,1010)
	fmt.Fscanf(buf, "%s\n", &str)
	slen := len(string(str))
	flag0 := false
	flag1 := false
	for i := 0;i < slen;i++{
		if str[i] == '0'{
			if flag0==false{
				fmt.Printf("1 1\n")
				flag0 = true
			}else{
				fmt.Printf("3 1\n")
				flag0 = false
			}
		}else{
			if flag1==false{
				fmt.Printf("4 3\n")
				flag1 = true
			}else{
				fmt.Printf("4 1\n")
				flag1 = false
			}
		}
	}
}

package main

import "fmt"

func main() {

	var s string
	fmt.Scanf("%s", &s)

	zero := 0
	one := 0

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			zero++
			if zero%4 == 0 {
				fmt.Println("1 1")
			} else if zero%4 == 1 {
				fmt.Println("1 2")
			} else if zero%4 == 2 {
				fmt.Println("1 3")
			} else {
				fmt.Println("1 4")
			}

		} else {
			one++
			if one%2 == 0 {
				fmt.Println("3 1")
			} else {
				fmt.Println("3 3")
			}
		}
	}

}


package main

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

type Pair struct {
	XorSum   int64
	Position int32
}

type SortPair []*Pair

func (s SortPair) Len() int {
	return len(s)
}
func (s SortPair) Less(i, j int) bool {
	if s[i].XorSum != s[j].XorSum {
		return s[i].XorSum < s[j].XorSum
	} else {
		return s[i].Position < s[j].Position
	}
}
func (s SortPair) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	var n int
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	pairs := make([]*Pair, n+1, n+1)
	pairs[0] = &Pair{}
	for i := 0; i < n; i++ {
		var v int64
		fmt.Fscanf(buf, "%d", &v)
		pairs[i+1] = &Pair{}
		pairs[i+1].XorSum = pairs[i].XorSum ^ v
		pairs[i+1].Position = int32(i + 1)
	}
	sort.Sort(SortPair(pairs[1:]))
	result := int64(0)
	now := pairs[0]
	var other *Pair
	nowv, otherv := int64(1), int64(1)
	for i := 1; i <= n; i++ {
		if other == nil && (pairs[i].Position^pairs[0].Position)&1 == 1 {
			other = pairs[i]
		}
		if (now.Position^pairs[i].Position)&1 == 0 && now.Position != pairs[i].Position {
			if pairs[i].XorSum == now.XorSum {
				nowv ++
				//fmt.Printf("%d %d %d %d\n", pairs[i].XorSum, now.Position, pairs[i].Position, nowv)
			} else {
				result += nowv * (nowv -1) / 2
				nowv = 1
				now = pairs[i]
			}
		}
		if other != nil && (other.Position^pairs[i].Position)&1 == 0 && other.Position != pairs[i].Position {
			if other != nil && pairs[i].XorSum == other.XorSum {
				otherv ++
				//fmt.Printf("%d %d %d %d\n", pairs[i].XorSum, other.Position, pairs[i].Position, otherv)
			} else {
				result += otherv * (otherv -1) / 2
				otherv = 1
				other = pairs[i]
			}
		}
	}
	result = result + otherv * (otherv -1) / 2 + nowv * (nowv -1) / 2

	fmt.Printf("%d\n", result)
}

package main

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

var ans int
var ansX []int
var ansY []int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, 400000)
	for i := 0; i <= n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	evenMap := make(map[int]int)
	oddMap := make(map[int]int)
	evenMap[0] = 1
	evenCur := 0
	oddMap[0] = 1
	oddCur := 0
	ans := int64(0)
	for i := 1; i < n; i++ {
		if i%2 == 1 {
			ans += int64(evenMap[a[i]^a[i-1]^evenCur])
			evenMap[a[i]^a[i-1]^evenCur]++
			evenCur ^= (a[i] ^ a[i-1])
		} else {
			ans += int64(oddMap[a[i]^a[i-1]^oddCur])
			oddMap[a[i]^a[i-1]^oddCur]++
			oddCur ^= (a[i] ^ a[i-1])
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

func solve(x []int, y []int) (int, []int, []int) {
	ans = 0
	ansX = make([]int, 0)
	ansY = make([]int, 0)
	ansX = append(ansX, x[0])
	ansY = append(ansY, y[0])
	ans++
	ansX = append(ansX, x[1])
	ansY = append(ansY, y[1])
	ans++
	fill(x[0], y[0], x[1], y[1])
	//fmt.Println(ans)
	dis := -1
	bestX := 0
	bestY := 0
	for i := 0; i < ans; i++ {
		dish := abs(ansX[i]-x[2]) + abs(ansY[i]-y[2])
		if dis == -1 || dis > dish {
			if dish == 0 {
				//outputAns(out)
				return ans, ansX, ansY
			}
			dis = dish
			bestX = ansX[i]
			bestY = ansY[i]
		}
	}
	ansX = append(ansX, x[2])
	ansY = append(ansY, y[2])
	ans++
	//fmt.Println(ans)
	fill(bestX, bestY, x[2], y[2])
	//outputAns(out)
	return ans, ansX, ansY
}

func outputAns(out io.Writer) {
	fmt.Fprintf(out, "%d\n", ans)
	for i := 0; i < ans; i++ {
		fmt.Fprintf(out, "%d %d\n", ansX[i], ansY[i])
	}
	return
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fill(x1, y1, x2, y2 int) {
	if x1 > x2 {
		fill(x2, y2, x1, y1)
		return
	}
	if x1 == x2 {
		if y1 < y2 {
			for i := y1 + 1; i < y2; i++ {
				ansX = append(ansX, x1)
				ansY = append(ansY, i)
				ans++
			}
			return
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x1)
			ansY = append(ansY, i)
			ans++
		}
		return
	}
	if y1 < y2 {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y1 + 1; i < y2; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	} else if y1 == y2 {
		for i := x1 + 1; i < x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
	} else {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	}
}

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, t1, cur int
	scanf("%d\n", &n)
	even := make(map[int]int64)
	odd := make(map[int]int64)
	odd[0] = 1
	ans := int64(0)
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		cur = cur ^ t1
		if i%2 == 0 {
			ans += even[cur]
			even[cur]++
		} else {
			ans += odd[cur]
			odd[cur]++

		}
		// fmt.Println(cur)
	}
	printf("%d", ans)
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("in.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}

	var n, x, curr int
	scanf("%d\n", &n)

	var num [2][1048576]int

	num[1][0]++

	var res int64

	for i := 0; i < n; i++ {
		scanf("%d", &x)
		curr ^= x
		res += int64(num[i%2][curr])
		num[i%2][curr]++
	}

	printf("%d\n", res)
}

package main

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

var ans int
var ansX []int
var ansY []int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, 400000)
	for i := 0; i <= n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	evenMap := make(map[int]int)
	oddMap := make(map[int]int)
	evenMap[0] = 1
	evenCur := 0
	oddMap[0] = 1
	oddCur := 0
	ans := 0
	for i := 1; i < n; i++ {
		if i%2 == 1 {
			ans += evenMap[a[i]^a[i-1]^evenCur]
			evenMap[a[i]^a[i-1]^evenCur]++
			evenCur ^= (a[i] ^ a[i-1])
		} else {
			ans += oddMap[a[i]^a[i-1]^oddCur]
			oddMap[a[i]^a[i-1]^oddCur]++
			oddCur ^= (a[i] ^ a[i-1])
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

func solve(x []int, y []int) (int, []int, []int) {
	ans = 0
	ansX = make([]int, 0)
	ansY = make([]int, 0)
	ansX = append(ansX, x[0])
	ansY = append(ansY, y[0])
	ans++
	ansX = append(ansX, x[1])
	ansY = append(ansY, y[1])
	ans++
	fill(x[0], y[0], x[1], y[1])
	//fmt.Println(ans)
	dis := -1
	bestX := 0
	bestY := 0
	for i := 0; i < ans; i++ {
		dish := abs(ansX[i]-x[2]) + abs(ansY[i]-y[2])
		if dis == -1 || dis > dish {
			if dish == 0 {
				//outputAns(out)
				return ans, ansX, ansY
			}
			dis = dish
			bestX = ansX[i]
			bestY = ansY[i]
		}
	}
	ansX = append(ansX, x[2])
	ansY = append(ansY, y[2])
	ans++
	//fmt.Println(ans)
	fill(bestX, bestY, x[2], y[2])
	//outputAns(out)
	return ans, ansX, ansY
}

func outputAns(out io.Writer) {
	fmt.Fprintf(out, "%d\n", ans)
	for i := 0; i < ans; i++ {
		fmt.Fprintf(out, "%d %d\n", ansX[i], ansY[i])
	}
	return
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func fill(x1, y1, x2, y2 int) {
	if x1 > x2 {
		fill(x2, y2, x1, y1)
		return
	}
	if x1 == x2 {
		if y1 < y2 {
			for i := y1 + 1; i < y2; i++ {
				ansX = append(ansX, x1)
				ansY = append(ansY, i)
				ans++
			}
			return
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x1)
			ansY = append(ansY, i)
			ans++
		}
		return
	}
	if y1 < y2 {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y1 + 1; i < y2; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	} else if y1 == y2 {
		for i := x1 + 1; i < x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
	} else {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type Pair struct {
	XorSum   int64
	Position int32
}

type SortPair []*Pair

func (s SortPair) Len() int {
	return len(s)
}
func (s SortPair) Less(i, j int) bool {
	if s[i].XorSum != s[j].XorSum {
		return s[i].XorSum < s[j].XorSum
	} else {
		return s[i].Position < s[j].Position
	}
}
func (s SortPair) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	pairs := make([]*Pair, n+1, n+1)
	pairs[0] = &Pair{}
	for i := 0; i < n; i++ {
		var v int64
		fmt.Scanf("%d", &v)
		pairs[i+1] = &Pair{}
		pairs[i+1].XorSum = pairs[i].XorSum ^ v
		pairs[i+1].Position = int32(i + 1)
	}
	sort.Sort(SortPair(pairs[1:]))
	result := int64(0)
	now := pairs[0]
	var other *Pair
	for i := 1; i <= n; i++ {
		if other == nil && (pairs[i].Position^pairs[0].Position)&1 == 1 {
			other = pairs[i]
		}
		if (now.Position^pairs[i].Position)&1 == 0 && now.Position != pairs[i].Position {
			if pairs[i].XorSum == now.XorSum {
				result++
				//fmt.Printf("%d %d %d\n", pairs[i].XorSum, now.Position, pairs[i].Position)
			} else {
				now = pairs[i]
			}
		}
		if other != nil && (other.Position^pairs[i].Position)&1 == 0 && other.Position != pairs[i].Position {
			if other != nil && pairs[i].XorSum == other.XorSum {
				//	fmt.Printf("%d %d %d\n", pairs[i].XorSum, other.Position, pairs[i].Position)
				result++
			} else {
				other = pairs[i]
			}
		}
	}
	fmt.Printf("%d\n", result)
}

package main

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

type Pair struct {
	XorSum   int64
	Position int32
}

type SortPair []*Pair

func (s SortPair) Len() int {
	return len(s)
}
func (s SortPair) Less(i, j int) bool {
	if s[i].XorSum != s[j].XorSum {
		return s[i].XorSum < s[j].XorSum
	} else {
		return s[i].Position < s[j].Position
	}
}
func (s SortPair) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	var n int
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	pairs := make([]*Pair, n+1, n+1)
	pairs[0] = &Pair{}
	for i := 0; i < n; i++ {
		var v int64
		fmt.Fscanf(buf, "%d", &v)
		pairs[i+1] = &Pair{}
		pairs[i+1].XorSum = pairs[i].XorSum ^ v
		pairs[i+1].Position = int32(i + 1)
	}
	sort.Sort(SortPair(pairs[1:]))
	result := int64(0)
	now := pairs[0]
	var other *Pair
	for i := 1; i <= n; i++ {
		if other == nil && (pairs[i].Position^pairs[0].Position)&1 == 1 {
			other = pairs[i]
		}
		if (now.Position^pairs[i].Position)&1 == 0 && now.Position != pairs[i].Position {
			if pairs[i].XorSum == now.XorSum {
				result++
				//fmt.Printf("%d %d %d\n", pairs[i].XorSum, now.Position, pairs[i].Position)
			} else {
				now = pairs[i]
			}
		}
		if other != nil && (other.Position^pairs[i].Position)&1 == 0 && other.Position != pairs[i].Position {
			if other != nil && pairs[i].XorSum == other.XorSum {
				//	fmt.Printf("%d %d %d\n", pairs[i].XorSum, other.Position, pairs[i].Position)
				result++
			} else {
				other = pairs[i]
			}
		}
	}
	fmt.Printf("%d\n", result)
}