package main

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

func contest(in io.Reader) {
	var s string
	if _, err := fmt.Fscanln(in, &s); err != nil {
		panic(err)
	}
	n := len(s)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = int(s[i] - '0')
	}
	for i := 0; i < n; i++ {
		if d[i]%2 == 0 && d[i] < d[n-1] {
			d[i], d[n-1] = d[n-1], d[i]
			for i := 0; i < n; i++ {
				fmt.Print(d[i])
			}
			fmt.Println()
			return
		}
	}
	for i := n - 1; i >= 0; i-- {
		if d[i]%2 == 0 {
			d[i], d[n-1] = d[n-1], d[i]
			for i := 0; i < n; i++ {
				fmt.Print(d[i])
			}
			fmt.Println()
			return
		}
	}
	fmt.Println(-1)
}

func main() {
	contest(os.Stdin)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var n int
		for n = 0; str[n] != '\n' && str[n] != '\r'; n++ {
		}

		s := make([]byte, n)

		var last_digit byte = str[n-1] - '0'
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			s[i] = str[i] - '0'
			if s[i]%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d", s[i])
		}
		fmt.Println()
	}
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s, _ := reader.ReadBytes('\n')
	s = bytes.TrimSpace(s)
	n := len(s) - 1

	for i := 0; i < n; i++ {
		if (s[i] - '0') % 2 == 0 && s[i] < s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	for i := n-1; i >= 0; i-- {
		if (s[i] % 2) == 0 && s[i] > s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	println(-1)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"bytes"
	"io/ioutil"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s, _ := ioutil.ReadAll(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	s = bytes.TrimSpace(s)
	n := len(s) - 1

	for i := 0; i < n; i++ {
		if (s[i] - '0') % 2 == 0 && s[i] < s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	for i := n-1; i >= 0; i-- {
		if (s[i] % 2) == 0 && s[i] > s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	println(-1)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

var (
	n      string
	result string
)

func in() {
	read(&n)
}

func out() {
	println(result)
	defer output.Flush()
}

func run() {
	arr := []byte(n)
	l := len(arr)
	last := arr[l-1]
	switched := false
	for i := 0; i < l-1; i++ {
		if arr[i]%2 == 0 && arr[i] < last {
			arr[i], arr[l-1] = arr[l-1], arr[i]
			switched = true
			break
		}
	}

	if !switched {
		for i := l - 2; i >= 0; i-- {
			if arr[i]%2 == 0 {
				arr[i], arr[l-1] = arr[l-1], arr[i]
				switched = true
				break
			}
		}
	}

	if switched {
		result = string(arr)
	} else {
		result = "-1"
	}
}

/** main **/
func main() {
	in()
	run()
	out()
}

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

func println(a ...interface{}) {
	fmt.Fprintln(output, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(output, format, a...)
}

package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	N := len(S)
	D := make([]int, N)
	for i, r := range S {
		D[i] = int(r - '0')
	}
	odd := 1
	for _, d := range D {
		odd &= d & 1
	}
	if odd == 1 {
		fmt.Println(-1)
		return
	}
	odd = D[N-1]
	for i, d := range D {
		if (d&1) == 0 && d < odd {
			D[i], D[N-1] = odd, d
			for j := 0; j < N; j++ {
				fmt.Printf("%d", D[j])
			}
			fmt.Println()
			return
		}
	}
	for i := N - 2; i >= 0; i-- {
		d := D[i]
		if (d & 1) == 0 {
			D[i], D[N-1] = odd, d
			for j := 0; j < N; j++ {
				fmt.Printf("%d", D[j])
			}
			fmt.Println()
			return
		}
	}
	fmt.Println(-1)
}

package main

import "fmt"

func main() {
	var a string
	fmt.Scan(&a)
	l := len(a) - 1
	for i := 0; i < len(a); i++ {
		if ((a[i]-'0')%2 == 0) && (a[i] < a[l]) {
			for j := 0; j < len(a)-1; j++ {
				if j == i {
					fmt.Printf("%c", a[l])
				} else {
					fmt.Printf("%c", a[j])
				}
			}
			fmt.Printf("%c\n", a[i])
			return
		}
	}

	for i := len(a) - 2; i >= 0; i-- {
		if (a[i]-'0')%2 == 0 {
			for j := 0; j < len(a)-1; j++ {
				if j == i {
					fmt.Printf("%c", a[l])
				} else {
					fmt.Printf("%c", a[j])
				}
			}
			fmt.Printf("%c\n", a[i])
			return
		}
	}

	fmt.Println(-1)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "bytes"
	// "io/ioutil"
)

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	t := ""
	scan(&t)

	// s, _ := ioutil.ReadAll(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = bytes.TrimSpace(s)
	s := []byte(t)
	n := len(s) - 1

	for i := 0; i < n; i++ {
		if (s[i] - '0') % 2 == 0 && s[i] < s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	for i := n-1; i >= 0; i-- {
		if (s[i] % 2) == 0 && s[i] > s[n] {
			s[i], s[n] = s[n], s[i]
			println(string(s))
			return
		}
	}

	println(-1)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

func cToI(c byte) int {
  return int(c - '0')
}

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

  line, _ := reader.ReadString('\n')
  bytes := []byte(strings.TrimSpace(line))
  n := len(bytes)
  last := cToI(bytes[n-1])
  for i := 0; i < n; i++ {
    current := cToI(bytes[i])
    if current%2 == 0 && current < last {
      bytes[i], bytes[n-1] = bytes[n-1], bytes[i]
      writer.Write(bytes)
      writer.WriteString("\n")
      return
    }
  }
  for i := n-2; i >= 0; i-- {
    current := cToI(bytes[i])
    if current%2 == 0 {
      bytes[i], bytes[n-1] = bytes[n-1], bytes[i]
      writer.Write(bytes)
      writer.WriteString("\n")
      return
    }
  }

  writer.WriteString("-1\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"io/ioutil"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = s[:len(s)-1]

	s, _ := ioutil.ReadAll(os.Stdin)
	println(s)
	s = s[:len(s)-1]
	println(s)

	// // t := ""
	// // fmt.Scan(&t)
	// // s := []uint8(t)
	// n := len(s)
	// lastI := -1

	// for i := 0; i < n; i++ {
	// 	if ((s[i] - '0') % 2 == 0) {
	// 		if (s[i] < s[n-1]) {
	// 			lastI = i
	// 			break
	// 		} else {
	// 			if lastI == -1 {
	// 				lastI = i
	// 			} else {
	// 				if s[lastI] > s[i] {
	// 					lastI = i
	// 				}
	// 			}
	// 		}
	// 	}
	// }

	// if lastI != -1 {
	// 	s[lastI], s[n-1] = s[n-1], s[lastI]
	// 	println(string(s))
	// } else {
	// 	println(-1)
	// }

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"io/ioutil"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = s[:len(s)-1]

	s, _ := ioutil.ReadAll(os.Stdin)
	s = s[:len(s)-1]

	// t := ""
	// fmt.Scan(&t)
	// s := []uint8(t)
	n := len(s)
	lastI := -1

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

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "io/ioutil"
	"bytes"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = s[:len(s)-1]

	s, _ := reader.ReadBytes('\n')
	// s, _ := ioutil.ReadAll(os.Stdin)
	s = bytes.TrimSpace(s)
	n := len(s)
	lastI := -1

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

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"io/ioutil"
	"bytes"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = s[:len(s)-1]

	s, _ := ioutil.ReadAll(os.Stdin)
	println(s)
	s = bytes.TrimSpace(s)
	println(s)
	// // t := ""
	// // fmt.Scan(&t)
	// // s := []uint8(t)
	// n := len(s)
	// lastI := -1

	// for i := 0; i < n; i++ {
	// 	if ((s[i] - '0') % 2 == 0) {
	// 		if (s[i] < s[n-1]) {
	// 			lastI = i
	// 			break
	// 		} else {
	// 			if lastI == -1 {
	// 				lastI = i
	// 			} else {
	// 				if s[lastI] > s[i] {
	// 					lastI = i
	// 				}
	// 			}
	// 		}
	// 	}
	// }

	// if lastI != -1 {
	// 	s[lastI], s[n-1] = s[n-1], s[lastI]
	// 	println(string(s))
	// } else {
	// 	println(-1)
	// }

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	t := ""
	fmt.Scan(&t)
	s := []uint8(t)
	n := len(s)
	lastI := -1

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

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	reader := bufio.NewReader(os.Stdin)

	s, _ := reader.ReadBytes('\n')
	n := len(s)
	// fmt.Scan(&t)
	// s := []uint8(t)
	lastI := -1

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

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"io/ioutil"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s, _ := ioutil.ReadAll(os.Stdin)
	n := len(s)
	i := 0

	for ; i < n; i++ {
		if ((s[i] - '0') % 2 == 0) {
			break
		}
	}

	if i != n {
		s[i], s[n-1] = s[n-1], s[i]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadBytes('\n')
	s = s[:len(s)-1]
	// t := ""
	// fmt.Scan(&t)
	// s := []uint8(t)
	n := len(s)
	lastI := -1
	// lastT := ""

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

			// s[i], s[n-1] = s[n-1], s[i]
			// t = string(s)

			// if lastT == "" {
			// 	lastT = t
			// } else if t > lastT {
			// 	lastT = t
			// }

			// s[i], s[n-1] = s[n-1], s[i]
		}
	}

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

	// if lastT == "" {
	// 	println(-1)
	// } else {
	// 	println(lastT)
	// }

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "io/ioutil"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	t := ""
	fmt.Scan(&t)
	s := []uint8(t)
	// s, _ := ioutil.ReadAll(os.Stdin)
	// println(t)
	n := len(s)
	i := 0

	for ; i < n; i++ {
		if ((s[i] - '0') % 2 == 0) {
			break
		}
	}

	if i != n {
		s[i], s[n-1] = s[n-1], s[i]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"io/ioutil"
	"bytes"
)

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadBytes('\n')
	// s = s[:len(s)-1]

	s, _ := ioutil.ReadAll(os.Stdin)
	s = bytes.TrimSpace(s)
	n := len(s)
	lastI := -1

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

	if lastI != -1 {
		s[lastI], s[n-1] = s[n-1], s[lastI]
		println(string(s))
	} else {
		println(-1)
	}

}

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

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

func cToI(c byte) int {
  return int(c - '0')
}

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

  line, _ := reader.ReadString('\n')
  bytes := []byte(strings.TrimSpace(line))
  n := len(bytes)
  last := cToI(bytes[n-1])
  for i := 0; i < n; i++ {
    current := cToI(bytes[i])
    if current%2 == 0 && current > last {
      bytes[i], bytes[n-1] = bytes[n-1], bytes[i]
      writer.Write(bytes)
      writer.WriteString("\n")
      return
    }
  }
  for i := n-2; i >= 0; i-- {
    current := cToI(bytes[i])
    if current%2 == 0 {
      bytes[i], bytes[n-1] = bytes[n-1], bytes[i]
      writer.Write(bytes)
      writer.WriteString("\n")
      return
    }
  }

  writer.WriteString("-1\n")
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var n int
		for n = 0; str[n] != '\n' && str[n] != '\r'; n++ {
		}

		s := make([]byte, n)

		var last_digit byte = str[n-1] - '0'
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			s[i] = str[i] - '0'
			if s[i]%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d\n", s[i])
		}
		fmt.Println()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var n int
		for n = 0; str[n] != '\n'; n++ {
		}

		s := make([]byte, n)

		var last_digit byte = str[n-1] - '0'
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			s[i] = str[i] - '0'
			if s[i]%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d\n", s[i])
		}
		fmt.Println()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var n int
		for n = 0; str[n] != '\n'; n++ {
		}

		s := make([]byte, n)

		var last_digit byte = str[n-1] - '0'
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			s[i] = str[i] - '0'
			if s[i]%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d", s[i])
		}
		fmt.Println()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		n := len(str) - 1
		if str[len(str)-1] == '\r' {
			n -= 1
		}
		s := make([]byte, n)
		copy(s, str[0:n])

		var last_digit byte = s[n-1]
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			if (s[i]-'0')%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		fmt.Printf("%s\n", s)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var n int
		for n = 0; str[n] != '\n'; n++ {
		}

		s := make([]byte, n)
		copy(s, str[0:n])

		var last_digit byte = s[n-1]
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			if (s[i]-'0')%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		fmt.Printf("%s\n", s)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	if str, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		n := len(str) - 1
		s := make([]byte, n)
		copy(s, str[0:n])

		var last_digit byte = s[n-1]
		var last_even_idx int = -1
		var swapped_idx int = -1

		for i := 0; i < n-1; i++ {
			if (s[i]-'0')%2 == 0 {
				last_even_idx = i
				if s[i] < last_digit && swapped_idx < 0 {
					s[n-1] = s[i]
					s[i] = last_digit
					swapped_idx = i
				}
			}
		}
		if swapped_idx < 0 {
			if last_even_idx < 0 {
				fmt.Println("-1")
				return
			} else {
				s[n-1] = s[last_even_idx]
				s[last_even_idx] = last_digit
			}
		}
		fmt.Printf("%s\n", s)
	}
}

package main

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

var (
	n      string
	result string
)

func in() {
	read(&n)
}

func out() {
	println(result)
	defer output.Flush()
}

func run() {
	arr := []byte(n)
	l := len(arr)
	last := arr[l-1]
	switched := false
	for i := 0; i < l-1; i++ {
		if arr[i]%2 == 0 && arr[i] < last {
			arr[i], arr[l-1] = arr[l-1], arr[i]
			switched = true
		}
	}

	if !switched {
		max := byte(0)
		max_i := -1
		for i := 0; i < l-1; i++ {
			if arr[i]%2 == 0 && arr[i] >= max {
				max, max_i = arr[i], i
			}
		}
		if max_i >= 0 {
			arr[max_i], arr[l-1] = arr[l-1], arr[max_i]
			switched = true
		}
	}
	if switched {
		result = string(arr)
	} else {
		result = "-1"
	}
}

/** main **/
func main() {
	in()
	run()
	out()
}

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

func println(a ...interface{}) {
	fmt.Fprintln(output, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(output, format, a...)
}

package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	N := len(S)
	D := make([]int, N)
	for i, r := range S {
		D[i] = int(r - '0')
	}
	odd := 1
	for _, d := range D {
		odd &= d & 1
	}
	if odd == 1 {
		fmt.Println(-1)
		return
	}
	odd = D[N-1]
	for i, d := range D {
		if (d&1) == 0 && d < odd {
			D[i], D[N-1] = odd, d
			for j := 0; j < N; j++ {
				fmt.Printf("%d", D[j])
			}
			fmt.Println()
			return
		}
	}
	for i := N - 2; i >= 0; i-- {
		d := D[i]
		if (d & 1) == 0 {
			D[i], D[N-1] = odd, d
			for j := 0; j < N; j++ {
				fmt.Printf("%d", D[j])
			}
			fmt.Println()
		}
	}
}


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
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ca, cc int
		for i := range s1 {
			if s1[i] == 'a' {
				ca++
			} else if (s1[i] == 'c' || s2[i] == 'c') && ca != 0 {
				f = false
				break
			}

			if s2[i] == 'a' {
				ca--
			}
			if ca < 0 {
				f = false
				break
			}
		}

		for i := range s1 {
			if s2[i] == 'c' {
				cc++
			} else if (s1[i] == 'a' || s2[i] == 'a') && cc != 0 {
				f = false
				break
			}

			if s1[i] == 'c' {
				cc--
			}
			if cc < 0 {
				f = false
				break
			}
		}
		if !f || ca > 0 || cc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	var s, t string
	fmt.Fscan(r, &s, &t)
	cnt := make([]int, 3)
	cnt_a := 0
	for i := range s {
		if s[i] == 'a' {
			cnt_a++
		} else if (s[i] == 'c'|| t[i] == 'c') && cnt_a != 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		if t[i] == 'a' {
			cnt_a--
		}
		if cnt_a < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		cnt[s[i]-'a']++
		cnt[t[i]-'a']--
	}
	cnt_c := 0
	for i:=n-1;i>=0;i-- {
		if s[i] == 'c' {
			cnt_c++
		} else if (s[i] == 'a' || t[i] == 'a') && cnt_c != 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		if t[i] == 'c' {
			cnt_c--
		}
		if cnt_c < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	if cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

	var T, n int
	var s, t string
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		if strings.ReplaceAll(s, "b", "") != strings.ReplaceAll(t, "b", "") {
			Fprintln(out, "NO")
			continue
		}
		j := 0
		for i, c := range s {
			if c != 'b' {
				for t[j] == 'b' {
					j++
				}
				if i != j && c == 'c' == (i < j) {
					Fprintln(out, "NO")
					continue o
				}
				j++
			}
		}
		Fprintln(out, "YES")
	}
}

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

package main

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

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====

acabcca
1020003

*/

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

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
		}
		if i != 0 {
			aCnt[i] += aCnt[i-1]
		}

		if s[i] == 'c' {
			cCnt[i]++
		}
		if i != 0 {
			cCnt[i] += cCnt[i-1]
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if s[i] == 'a' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if s[j] == 'c' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	b1, b2 := 0, 0
	for _, v := range s {
		if v == 'b' {
			b1++
		}
	}
	for _, v := range t {
		if v == 'b' {
			b2++
		}
	}
	if b1 != b2 {
		return false
	}
	var i, j int
	for ; i < len(t); i++ {
		c := t[i]
		switch c {
		case 'a':
			for ; j < len(s); j++ {
				if s[j] == 'c' {
					return false
				}
				if s[j] == 'a' {
					if j > i {
						return false
					}
					j++
					break
				}
			}
		case 'c':
			for ; j < len(s); j++ {
				if s[j] == 'a' {
					return false
				}
				if s[j] == 'c' {
					if j < i {
						return false
					}
					j++
					break
				}
			}
		}
	}
	return true
}

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

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	// a, b []byte
	// )
	// a = []byte("aa")
	// b = []byte("ab")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scanln(&T)
	for tt := 0; tt < T; tt++ {
		var n int
		var a, b string
		fmt.Scanln(&n)
		fmt.Scanln(&a)
		fmt.Scanln(&b)

		a_count := 0
		b_count := 0

	    for i := 0; i < n; i++ {
		    if a[i] == 98 {
                a_count += 1
            }
            if b[i] == 98 {
                b_count += 1
            }
        }

        if a_count != b_count {
            fmt.Println("NO")
            continue;
		}
// 		fmt.Println("quack")
		j := 0
		printed := false
		for i := 0; i < n; i++ {
            if a[i] == 98 {
                continue;
            }
            for j < n && b[j] == 98 {
                j += 1
            }
		    //fmt.Printf("%d %d\n", i, j)
		    if a[i] != b[j] || (a[i] == 97 && i > j) || (a[i] == 99 && i < j) {
                fmt.Println("NO")
                printed = true
                break
            }
            j += 1
		}
		if !printed {
            fmt.Println("YES")
		}
// 		fmt.Println(a)
// 		fmt.Println(b)
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

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

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

	var T int
	Fscan(in, &T)

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

		var sss, st string
		Fscan(in, &sss, &st)

		s := []rune(sss)
		t := []rune(st)

		fl := true
		nx := n - 1
		for cur := n - 1; cur >= 0; cur-- {
			for s[cur] != t[cur] {
				if t[cur]+1 == s[cur] {
					if cur-1 < nx {
						nx = cur - 1
					}
					for nx >= 0 && (s[nx] == s[cur]-1 || s[nx] == s[cur]) && s[nx] != t[cur] {
						nx--
					}

					if nx >= 0 && s[nx] == t[cur] && (s[nx] == s[cur]-1 || s[nx] == s[cur]) {
						s[cur], s[nx] = s[nx], s[cur]
					} else {
						fl = false
						break
					}

				} else {
					fl = false
					break
				}
			}

		}
		if fl {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

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

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

var n,m int
var turn int
var s,t string
func solve(){
	var l int
	Fscan(r,&l)
	Fscan(r,&s,&t)
	if strings.ReplaceAll(s,"b","") !=strings.ReplaceAll(t,"b",""){
		Fprintln(w,"NO")
		return
	}
	// 'a' means move_right
	// 'c' means move_left
	ptr_1,ptr_2:=0,0
	for ptr_1<l{
		if s[ptr_1]=='b'{
			ptr_1++
			continue
		}
		if t[ptr_2]=='b'{
			ptr_2++
			continue
		}
		if s[ptr_1]=='a' && ptr_1>ptr_2{
			Fprintln(w,"NO")
			return
		}
		if s[ptr_1]=='c' && ptr_1<ptr_2{
			Fprintln(w,"NO")
			return
		}
		ptr_1++
		ptr_2++
	}
	Fprintln(w,"YES")
	return
}

func main(){
	defer w.Flush()
	//Fscan(r,&n,&m)
	Fscan(r,&turn)

	for i:=0;i<turn;i++{
	    solve()
	}
}

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var s1, t1 string
		Fscan(in, &s1, &t1)
		s, t := []byte(s1), []byte(t1)
		// cnt := make([]int, 26)
		// for i := 0; i < n; i++ {
		// 	cnt[int(s[i])-97]++
		// }
		// for i := 0; i < n; i++ {
		// 	cnt[int(t[i])-97]--
		// 	if cnt[int(t[i])-97] < 0 {
		// 		Fprintln(out, "NO")
		// 		return
		// 	}
		// }
		jump := make(map[int]int)
		for i := 0; i < n; i++ {
			if s[i] == t[i] {
				continue
			} else {
				if s[i] == 'c' || i+1 == n {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'a' && t[i] != 'b' {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'b' && t[i] != 'c' {
					Fprintln(out, "NO")
					return
				}
				var j int
				// if _, ok := jump[i]; ok {
				// 	j = jump[i]
				// } else {
				// 	j = i + 1
				// }
				j = i + 1
				for j < n && s[j] == s[i] {
					j++
				}
				if j < n && s[j] == t[i] {
					s[i], s[j] = s[j], s[i]
					jump[i+1] = j + 1
				} else {
					Fprintln(out, "NO")
					return
				}
			}
		}
		Fprintln(out, "Yes")
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var s1, t1 string
		Fscan(in, &s1, &t1)
		s, t := []byte(s1), []byte(t1)
		// cnt := make([]int, 26)
		// for i := 0; i < n; i++ {
		// 	cnt[int(s[i])-97]++
		// }
		// for i := 0; i < n; i++ {
		// 	cnt[int(t[i])-97]--
		// 	if cnt[int(t[i])-97] < 0 {
		// 		Fprintln(out, "NO")
		// 		return
		// 	}
		// }
		jump := make(map[int]int)
		for i := 0; i < n; i++ {
			if s[i] == t[i] {
				continue
			} else {
				if s[i] == 'c' || i+1 == n {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'a' && t[i] != 'b' {
					Fprintln(out, "NO")
					return
				}
				if s[i] == 'b' && t[i] != 'c' {
					Fprintln(out, "NO")
					return
				}
				var j int
				if _, ok := jump[i]; ok {
					j = jump[i]
				} else {
					j = i + 1
				}
				for j < n && s[j] == s[i] {
					j++
				}
				if j < n && s[j] == t[i] {
					s[i], s[j] = s[j], s[i]
					jump[i+1] = j + 1
				} else {
					Fprintln(out, "NO")
					return
				}
			}
		}
		Fprintln(out, "Yes")
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

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

var n,m int
var tt int
var s,t string
func solve(){
	var l int
	Fscan(r,&l)
	Fscan(r,&s,&t)
	if strings.ReplaceAll(s,"b","") !=strings.ReplaceAll(t,"b",""){
		Fprintln(w,"NO")
		return
	}
	// 'a' means move_right
	// 'c' means move_left
	ptr_1,ptr_2:=0,0
	for ptr_1<l{
		if s[ptr_1]=='b'{
			ptr_1++
			continue
		}
		if t[ptr_2]=='b'{
			ptr_2++
			continue
		}
		if s[ptr_1]=='a' && ptr_1>ptr_2{
			Fprintln(w,"NO")
			return
		}
		if s[ptr_1]=='c' && ptr_1<ptr_2{
			Fprintln(w,"NO")
			return
		}
		ptr_1++
		ptr_2++
	}
	Fprintln(w,"YES")
	return
}

func main(){
	defer w.Flush()
	//Fscan(r,&n,&m)
	Fscan(r,&tt)

	for tt>=0{
		tt--
		solve()
	}
}

package main

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

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====

acabcca
1020003

*/

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

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if s[i] == 'a' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if s[j] == 'c' {
				cnt++
			}
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====
*/

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

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[i] - cCnt[j]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
8
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
11
cabccaabcac
caccbabacac
6
aaabba
aabbaa
6
abcabc
bacacb
6
acaaab
abcaaa
---
YES
NO
YES
NO
YES
YES
YES
NO
=========
2
9
cbccbabaa
cccbbbaaa
5
acabb
acbab
---
YES
YES
========
5
2
cb
bc
2
bc
cb
1
a
a
1
b
b
1
c
c
---
NO
YES
YES
YES
YES
======
3
7
acabcca
acbacca
7
acabcca
abcacca
7
acabcca
acaccba
---
YES
NO
YES
=======
1
4
aaaaaaabbb
bbbaaaaaaa
=====
*/

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

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	aCnt := make([]int, n)
	cCnt := make([]int, n)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}

		if s[i] == 'a' {
			aCnt[i]++
			if i != 0 {
				aCnt[i] += aCnt[i-1]
			}
		}

		if s[i] == 'c' {
			cCnt[i]++
			if i != 0 {
				cCnt[i] += cCnt[i-1]
			}
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {
		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			cnt := aCnt[j] - aCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			cnt := cCnt[j] - cCnt[i]
			if cnt > 0 {
				fmt.Fprintln(writer, "NO")
				return
			}
		}

		i++
		j++
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

/*
1
8
acbabcba
bacbabcc
---

========
2
6
aaabbb
ababab
9
aaabbbccc
bbbcccaaa
---
YES aaabbb -> ababab
NO aaabbbccc -> aaacccbbb -> aaabcccbb -> baaabcccb

=======
4
5
aabaa
abaaa
5
aabaa
aaaba
5
ccbcc
cccbc
5
ccbcc
cbccc
---
YES
NO
YES
NO
*/

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

	var s, t string
	scanf("%s\n%s\n", &s, &t)

	rToCntS := make(map[byte]int)
	rToCntT := make(map[byte]int)

	s1 := make([]byte, 0)
	t1 := make([]byte, 0)

	for i := 0; i < n; i++ {
		rToCntS[s[i]]++
		rToCntT[t[i]]++

		if s[i] != 'b' {
			s1 = append(s1, s[i])
		}

		if t[i] != 'b' {
			t1 = append(t1, t[i])
		}
	}

	if rToCntS['a'] != rToCntT['a'] || rToCntS['b'] != rToCntT['b'] || rToCntS['c'] != rToCntT['c'] {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(s1); i++ {
		if s1[i] != t1[i] {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	i := 0
	j := 0
	for k := 0; k < rToCntS['b']; k++ {

		for s[i] != 'b' {
			i++
		}
		for t[j] != 'b' {
			j++
		}

		if i < j {
			onlyC := true
			for l := i + 1; l <= j; l++ {
				if s[l] != 'c' {
					onlyC = false
				}
			}
			if !onlyC {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else if i > j {
			onlyA := true
			for l := i - 1; l >= j; l-- {
				if s[l] != 'a' {
					onlyA = false
				}
			}
			if !onlyA {
				fmt.Fprintln(writer, "NO")
				return
			}
		} else {
			i++
			j++
		}
	}

	fmt.Fprintln(writer, "YES")
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

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

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

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ca, cc int
		for i := range s1 {
			if s1[i] == 'a' {
				ca++
			} else if s1[i] == 'c' && s2[i] == 'c' || ca > 0 {
				f = false
				break
			}

			if s2[i] == 'a' {
				ca--
			}
			if ca < 0 {
				f = false
				break
			}
		}

		for i := range s1 {
			if s1[i] == 'c' {
				cc++
			} else if s1[i] == 'a' && s2[i] == 'c' || cc > 0 {
				f = false
				break
			}

			if s2[i] == 'c' {
				cc--
			}
			if cc < 0 {
				f = false
				break
			}
		}
		if !f || ca > 0 || cc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

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
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ab, bc int
		for i := range s1 {
			c1 := s1[i]
			c2 := s2[i]
			if c1 == 'a' && c2 == 'a' {
				if bc != 0 {
					f = false
					break
				}
			} else if c1 == 'c' && c2 == 'c' {
				if ab != 0 {
					f = false
					break
				}
			} else if c1 == 'a' && c2 == 'c' || c1 == 'c' && c2 == 'a' {
				f = false
				break
			} else if c1 == 'a' && c2 == 'b' {
				ab++
			} else if c1 == 'b' && c2 == 'a' {
				ab--
				if ab < 0 {
					f = false
					break
				}
			} else if c1 == 'b' && c2 == 'c' {
				bc++
			} else if c1 == 'c' && c2 == 'b' {
				bc--
				if bc < 0 {
					f = false
					break
				}
			}
		}

		if !f || ab > 0 || bc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

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
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		m1 := make([]int, 26)
		m2 := make([]int, 26)
		for i := range s1 {
			m1[s1[i]-'a']++
			m2[s2[i]-'a']++
		}

		f := true
		for i := range m1 {
			if m1[i] != m2[i] {
				f = false
				break
			}
		}

		var ab, bc int
		for i := range s1 {
			c1 := s1[i]
			c2 := s2[i]
			if c1 == 'a' && c2 == 'a' {
				bc = 0
			} else if c1 == 'c' && c2 == 'c' {
				ab = 0
			} else if c1 == 'a' && c2 == 'c' || c1 == 'c' && c2 == 'a' {
				f = false
				break
			} else if c1 == 'a' && c2 == 'b' {
				ab++
			} else if c1 == 'b' && c2 == 'a' {
				ab--
				if ab < 0 {
					f = false
					break
				}
			} else if c1 == 'b' && c2 == 'c' {
				bc++
			} else if c1 == 'c' && c2 == 'b' {
				bc--
				if bc < 0 {
					f = false
					break
				}
			}
		}

		if !f || ab > 0 || bc > 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	if len(s) == 1 {
		return s[0] == t[0]
	}
	for i := 0; i < len(s)-1; i++ {
		c1, c2 := s[i], s[i+1]
		t1, t2 := t[i], t[i+1]
		if c1 == t1 {
			continue
		}
		if c1 == 'a' && c2 == 'b' && t1 == 'b' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if c1 == 'b' && c2 == 'c' && t1 == 'c' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if t1 == 'b' && t2 == 'a' && c1 == 'a' {
			t[i], t[i+1] = t2, t1
			continue
		}
		if t1 == 'c' && t2 == 'b' && c1 == 'b' {
			t[i], t[i+1] = t2, t1
			continue
		}
		return false
	}
	return s[len(s)-1] == t[len(t)-1]
}

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

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	// a, b []byte
	// )
	// a = []byte("aa")
	// b = []byte("ab")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

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

// s: ab -> ba ; bc -> cb
// t: ba -> ab ; cb -> bc
func solve(s, t []byte) bool {
	if len(s) == 1 {
		return s[0] == t[0]
	}
	for i := 0; i < len(s)-1; i++ {
		c1, c2 := s[i], s[i+1]
		t1, t2 := t[i], t[i+1]
		if c1 == t1 {
			continue
		}
		if c1 == 'a' && c2 == 'b' && t1 == 'b' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if c1 == 'b' && c2 == 'c' && t1 == 'c' {
			s[i], s[i+1] = c2, c1
			continue
		}
		if t1 == 'b' && t2 == 'a' && c1 == 'a' {
			t[i], t[i+1] = t2, t1
			continue
		}
		if t1 == 'c' && t2 == 'b' && c1 == 'b' {
			t[i], t[i+1] = t2, t1
			continue
		}
		return false
	}
	return true
}

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

	var q int
	var n int
	var s, t string
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &n)
		Fscan(in, &s, &t)
		if solve([]byte(s), []byte(t)) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	p1697c(os.Stdin, os.Stdout)
	// var (
	//     a, b []byte
	// )
	// a = []byte("bc")
	// b = []byte("cb")
	// ans := solve(a, b)
	// fmt.Println(ans)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

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

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

	var T int
	Fscan(in, &T)

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

		var sss, st string
		Fscan(in, &sss, &st)

		s := []rune(sss)
		t := []rune(st)

		fl := true
		for cur := n - 1; cur >= 0; cur-- {
			for s[cur] != t[cur] {
				if t[cur] < s[cur] {
					nx := cur - 1
					for nx >= 0 && (s[nx] == s[cur]-1 || s[nx] == s[cur]) && s[nx] != t[cur] {
						nx--
					}

					if nx >= 0 && s[nx] == t[cur] {
						s[cur], s[nx] = s[nx], s[cur]
					} else {
						fl = false
						break
					}

				} else {
					fl = false
					break
				}
			}

		}
		if fl {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

type Void struct{}

var void Void

type HashSet struct {
	ma map[Int]Void
}

func NewHashSet() *HashSet {
	return &HashSet{
		ma: make(map[Int]Void),
	}
}

func (s *HashSet) add(x Int) bool {
	_, exists := s.ma[x]
	if !exists {
		s.ma[x] = void
		return true
	} else {
		return false
	}
}

func (s *HashSet) del(x Int) {
	delete(s.ma, x)
}

func (s *HashSet) exist(x Int) bool {
	_, exists := s.ma[x]
	return exists
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	var s, t string
	fmt.Fscan(r, &s, &t)
	cnt := make([]int, 3)
	cnt_a := 0
	for i := range s {
		if s[i] == 'a' {
			cnt_a++
		} else if s[i] == 'c' {
			cnt_a = 0
		}
		if t[i] == 'a' {
			cnt_a--
		}
		if cnt_a < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
		cnt[s[i]-'a']++
		cnt[t[i]-'a']--
	}
	cnt_c := 0
	for i:=n-1;i>=0;i-- {
		if s[i] == 'c' {
			cnt_c++
		} else if s[i] == 'a' {
			cnt_c = 0
		}
		if t[i] == 'c' {
			cnt_c--
		}
		if cnt_c < 0 {
			fmt.Fprintln(w, "NO")
			return
		}
	}
	if cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[j].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		if s.x-prev.x > n {
			fmt.Println(-1)
			return
		}
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

// Codeforces 635 E
package main

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

type zaprav struct {
    x int64
    p int64
}
// Array of zaprav.
type Zaps []zaprav

func (slice Zaps) Len() int {
	return len(slice)
}
func (slice Zaps) Less(i, j int) bool {
	return slice[i].x < slice[j].x;
}
func (slice Zaps) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z Zaps
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = Zaps(make([]zaprav, m))
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // sort zapravki by x
    sort.Sort(z)
    //fmt.Println(z)

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)
    if stopped {
        cost = -1
    }

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

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[i].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		if s.x-prev.x > n {
			fmt.Println(-1)
			return
		}
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

type station struct {
	x, p int
}

type byX []station

func (s byX) Len() int           { return len(s) }
func (s byX) Less(i, j int) bool { return s[i].x < s[i].x }
func (s byX) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

type toFuel struct {
	price, amount int
}

type toFuelHeap []toFuel

func (s toFuelHeap) Len() int            { return len(s) }
func (s toFuelHeap) Less(i, j int) bool  { return s[i].price < s[j].price }
func (s toFuelHeap) Swap(i, j int)       { s[i], s[j] = s[j], s[i] }
func (s *toFuelHeap) Push(x interface{}) { *s = append(*s, x.(toFuel)) }
func (s *toFuelHeap) Pop() interface{} {
	*s = (*s)[:len(*s)-1]
	return nil
}

func main() {
	in.Split(bufio.ScanWords)

	d := readInt()
	n := readInt()
	m := readInt()

	st := make([]station, m+1, m+2)
	for i := range st[1:] {
		st[i+1].x = readInt()
		st[i+1].p = readInt()
	}
	sort.Sort(byX(st))
	st = append(st, station{d, -1})

	cur := n
	res := int64(0)
	totFueled := 0
	var tf toFuelHeap
	for i, s := range st[1:] {
		prev := st[i]
		for cur < s.x-prev.x {
			if len(tf) == 0 {
				fmt.Println(-1)
				return
			}
			fuel := (s.x - prev.x) - cur
			if fuel > tf[0].amount-totFueled {
				fuel = tf[0].amount - totFueled
			}
			if fuel > 0 {
				cur += fuel
				totFueled += fuel
				res += int64(tf[0].price) * int64(fuel)
			} else {
				heap.Pop(&tf)
			}
		}
		cur -= s.x - prev.x
		heap.Push(&tf, toFuel{price: s.p, amount: n - cur + totFueled})
	}
	fmt.Println(res)
}

// Codeforces 635 E
package main

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

type zaprav struct {
    x int64
    p int64
}
type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z []zaprav
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = make([]zaprav, m)
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            cost = -1
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)

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

// Codeforces 635 E
package main

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

type zaprav struct {
    x int64
    p int64
}
// Array of zaprav.
type Zaps []zaprav

func (slice Zaps) Len() int {
	return len(slice)
}
func (slice Zaps) Less(i, j int) bool {
	return slice[i].x < slice[j].x;
}
func (slice Zaps) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

type portion struct {
    vol int64
    p int64
}

var d,n int64
var m int
var z Zaps
var bak []portion // portions of gaz, low to high price
var np int        // number of portions
var cost int64
var stopped bool

func spend(di int64) {
    //fmt.Printf("beg spend di = %d\n",di)
    var nused int
    for i:=0; i<np; i++ {
        if (di == 0) {
            break
        } else if (di >= bak[i].vol) {
            di -= bak[i].vol
            cost += bak[i].vol * bak[i].p
            bak[i].vol = 0
            nused ++;
        } else {
            bak[i].vol -= di
            cost += di * bak[i].p
            di = 0
        }
    }
    for i:=nused; i<np; i++ {
        bak[i-nused] = bak[i]
    }
    np -= nused
    //fmt.Printf("end of spend, di = %d\n",di)
    if (di>0) {
        stopped = true
    }
}

// replace fuel more expensive than p with p.
func replace(p int64, di int64) {
    var vrep int64
    for i:=np-1; i>=0; i-- {
        if bak[i].p <= p {
            break;
        } else {
            vrep += bak[i].vol
            bak[i].vol = 0
            np = i
        }
    }
    // adding bought fuel
    bak[np].p = p
    bak[np].vol = vrep + di
    np++
    //fmt.Printf("replaced %d\n",di)
}

func miconv(s string) int64 {
    i,err := strconv.Atoi(s)
    if err != nil {
        fmt.Println("error in converting " + s)
    }
    iret := int64(i)
    return iret
}

func main() {
    // reading n
    in    := bufio.NewReader(os.Stdin)
    s,err := in.ReadString('\n')
    if err != nil {
        fmt.Println("first read failure", err)
    }
    ss := strings.Split(strings.Trim(s," \n\r")," ")
    d = miconv(ss[0])
    n = miconv(ss[1])
    m = int(miconv(ss[2]))

    stopped = false
    z = Zaps(make([]zaprav, m))
    for i:=0; i<m; i++ {
        s,_ = in.ReadString('\n')
        ss := strings.Split(strings.Trim(s," \n\r")," ")
        z[i].x = miconv(ss[0])
        z[i].p = miconv(ss[1])
		if err != nil {
		    fmt.Println("read failure", err)
		}
    }

    // sort zapravki by x
    sort.Sort(z)

    // driving
    var xs int64
    var di int64
    bak = make([]portion, m+1)
    bak[0].vol = n
    bak[0].p = 0
    np = 1
    for i:=0; i<m; i++ {
        var di = z[i].x - xs
        xs = z[i].x
        spend(di)
        if stopped {
            cost = -1
            break
        }
        replace(z[i].p, di)
    }
    di = d - xs
    spend(di)

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


package main

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

func PrepareInput() (int, int, []int) {
    var totalComputers int
    var totalParticipants int

    fmt.Fscan(os.Stdin, &totalComputers)
    fmt.Fscan(os.Stdin, &totalParticipants)

    computers := make([]int, totalComputers)

    for i := 0; i < totalComputers; i++ {
        fmt.Fscan(os.Stdin, &computers[i])
    }

    return totalComputers, totalParticipants, computers
}

func LowerToMaxPossibleSpeed(totalComputers int, totalParticipants int , computers []int) int {
    var computerCount map[int]int
    var maxAllowed int

    computerCount = make(map[int]int)

    for i := 0; i < totalComputers; i += 1 {
        computerCount[computers[i]] = 0
    }

    for i := 0; i < totalComputers; i += 1 {
        computerCount[computers[i]] += 1
    }

    keys := make([]int, len(computerCount))

    i := 0
    for k := range computerCount {
        keys[i] = k
        i += 1
    }

    sort.Sort(sort.Reverse(sort.IntSlice(keys)))

    maxAllowed = 0

    for i := 0; i < len(computerCount); i++ {
        if i == len(computerCount) - 1 {
            maxAllowed = keys[i]
            break
        }

        if computerCount[keys[i]] >= totalParticipants {
            maxAllowed = keys[i]
            break
        }

        computerCount[keys[i+1]] += computerCount[keys[i]]
    }

    return maxAllowed
}

func main() {
    totalComputers, totalParticipants, computers := PrepareInput()
    fmt.Println(LowerToMaxPossibleSpeed(totalComputers, totalParticipants, computers))
}

// 412B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Print(a[n-k])
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, k := getI(), getI()
  speeds := make([]int, n)
  for i := 0; i < n; i++ {
    speeds[i] = getI()
  }
  sort.Ints(speeds)
  pos, same := n, 0
  for same < k {
    pos--
    seek := pos
    for seek > 0 && speeds[seek-1] == speeds[pos] {
      seek--
    }
    same += pos-seek+1
    pos = seek
  }
  writer.WriteString(fmt.Sprintf("%d\n", speeds[pos]))
}

//412B
package main
import "fmt"

func main() {
	var nn, kk, x, y int32
	var aa[105]int32
	fmt.Scan(&nn, &kk)
	x=0
	for i:=1; int32(i)<=nn; i++ {
		fmt.Scan(&aa[i])
		x=x+aa[i]
	}
	for i:=1; int32(i)<=nn; i++ {
		for j:=i+1; int32(j)<=nn; j++ {
			if aa[i]>aa[j] {
				y=aa[j]
				aa[j]=aa[i]
				aa[i]=y
			}
		}
	}
	fmt.Println(aa[nn-kk+1])
}