This problem is different from the easy version. In this version Ujan makes at most $$$2n$$$ swaps. In addition, $$$k \le 1000, n \le 50$$$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.Ujan has two distinct strings $$$s$$$ and $$$t$$$ of length $$$n$$$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation at most $$$2n$$$ times: he takes two positions $$$i$$$ and $$$j$$$ ($$$1 \le i,j \le n$$$, the values $$$i$$$ and $$$j$$$ can be equal or different), and swaps the characters $$$s_i$$$ and $$$t_j$$$.Ujan's goal is to make the strings $$$s$$$ and $$$t$$$ equal. He does not need to minimize the number of performed operations: any sequence of operations of length $$$2n$$$ or shorter is suitable.

The first line contains a single integer $$$k$$$ ($$$1 \leq k \leq 1000$$$), the number of test cases. For each of the test cases, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 50$$$), the length of the strings $$$s$$$ and $$$t$$$.  Each of the next two lines contains the strings $$$s$$$ and $$$t$$$, each having length exactly $$$n$$$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.

For each test case, output "Yes" if Ujan can make the two strings equal with at most $$$2n$$$ operations and "No" otherwise. You can print each letter in any case (upper or lower). In the case of "Yes" print $$$m$$$ ($$$1 \le m \le 2n$$$) on the next line, where $$$m$$$ is the number of swap operations to make the strings equal. Then print $$$m$$$ lines, each line should contain two integers $$$i, j$$$ ($$$1 \le i, j \le n$$$) meaning that Ujan swaps $$$s_i$$$ and $$$t_j$$$ during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than $$$2n$$$ is suitable.

4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca

package main

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

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

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

type Swaper struct {
	I int
	J int
}

var swaper []Swaper

func ValidateStrings(s, t string) bool {
	count := make(map[uint8]int)
	for i := range s {
		count[s[i]]++
		count[t[i]]++
	}
	for _, v := range count {
		if v%2 == 1 {
			return false
		}
	}
	return true
}

func FindUnequalIndex(s, t string) []int {
	var index []int
	for i := range s {
		if s[i] != t[i] {
			index = append(index, i)
		}
	}
	return index
}

func Swap(s, t string) (string, string) {
	index := FindUnequalIndex(s, t)
	for _, i := range index {
		for _, j := range index {
			if i == j {
				continue
			}
			if s[i] == s[j] {
				swaper = append(swaper, Swaper{i+1, j+1})
				return s[:i] + string(t[j]) + s[i+1:], t[:j] + string(s[i]) + t[j+1:]
			}
		}
	}
	swaper = append(swaper, Swaper{index[0]+1, index[0]+1})
	return s[:index[0]] + string(t[index[0]]) + s[index[0]+1:], t[:index[0]] + string(s[index[0]]) + t[index[0]+1:]
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var k, n int
	scanf("%d\n", &k)
	for ; k > 0; k-- {
		var s, t string
		ans = "No"
		swaper = []Swaper{}
		scanf("%d\n", &n)
		scanf("%s\n", &s)
		scanf("%s\n", &t)

		if ValidateStrings(s, t) {
			ans = "Yes\n"
			for s != t {
				s, t = Swap(s, t)
			}
			ans += fmt.Sprintf("%d\n", len(swaper))
			for i, v := range swaper {
				if i == len(swaper)-1 {
					ans += fmt.Sprintf("%d %d", v.I, v.J)
				} else{
					ans += fmt.Sprintf("%d %d\n", v.I, v.J)
				}
			}
		}

		//var sdif, tdif []int
		//for i := range s {
		//	if s[i] != t[i] {
		//		sdif = append(sdif, i)
		//		tdif = append(tdif, i)
		//	}
		//}
		//if len(sdif) == 2 {
		//	s, t = s[:sdif[0]]+string(t[tdif[1]])+s[sdif[0]+1:], t[:tdif[1]]+string(s[sdif[0]])+t[tdif[1]+1:]
		//	if s == t {
		//		ans = "Yes"
		//	}
		//}
		if k != 1 {
			printf("%s\n", ans)
		} else {
			printf(ans)
		}

	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

	return res
}

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

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var k int
var n int
var S, T []rune

func main() {
	k = ReadInt()
	for tc := 0; tc < k; tc++ {
		n = ReadInt()
		S = ReadRuneSlice()
		T = ReadRuneSlice()
		solve()
	}
}

func solve() {
	memo := make([]rune, ALPHABET_NUM)
	for i := 0; i < n; i++ {
		s, t := S[i], T[i]
		memo[s-'a']++
		memo[t-'a']++
	}

	for i := 0; i < len(memo); i++ {
		if memo[i]%2 == 1 {
			fmt.Println("No")
			return
		}
	}

	answers := [][]int{}
	for i := 0; i < n; i++ {
		if S[i] == T[i] {
			continue
		}

		for j := i + 1; j < n; j++ {
			if S[i] == S[j] {
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, i})
				break
			} else if S[i] == T[j] {
				S[j], T[j] = T[j], S[j]
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, j})
				answers = append(answers, []int{j, i})
				break
			}
		}
	}

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

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

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

package main

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

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

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

func ValidateStrings(s, t string) bool {
	count := make(map[uint8]int)
	for i := range s {
		count[s[i]]++
		count[t[i]]++
	}
	for _, v := range count {
		if v%2 == 1 {
			return false
		}
	}
	return true
}

func FindUnequalIndex(s, t string) []int {
	var index []int
	for i := range s {
		if s[i] != t[i] {
			index = append(index, i)
		}
	}
	return index
}

func Swap(s, t string) (string, string) {
	index := FindUnequalIndex(s, t)
	for _, i := range index {
		for _, j := range index {
			if i == j {
				continue
			}
			if s[i] == s[j] {
				ans = ans + fmt.Sprintf("%d %d", i+1, j+1)
				return s[:i] + string(t[j]) + s[i+1:], t[:j] + string(s[i]) + t[j+1:]
			}
		}
	}
	ans = ans + fmt.Sprintf("%d %d", index[0]+1, index[0]+1)
	return s[:index[0]] + string(t[index[0]]) + s[index[0]+1:], t[:index[0]] + string(s[index[0]]) + t[index[0]+1:]
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var k, n int
	scanf("%d\n", &k)
	for ; k > 0; k-- {
		var s, t string
		ans = "No"
		scanf("%d\n", &n)
		scanf("%s\n", &s)
		scanf("%s\n", &t)

		if ValidateStrings(s, t) {
			ans = "Yes"
			for s != t {
				ans += "\n"
				s, t = Swap(s, t)
			}
		}

		//var sdif, tdif []int
		//for i := range s {
		//	if s[i] != t[i] {
		//		sdif = append(sdif, i)
		//		tdif = append(tdif, i)
		//	}
		//}
		//if len(sdif) == 2 {
		//	s, t = s[:sdif[0]]+string(t[tdif[1]])+s[sdif[0]+1:], t[:tdif[1]]+string(s[sdif[0]])+t[tdif[1]+1:]
		//	if s == t {
		//		ans = "Yes"
		//	}
		//}
		if k != 1{
			printf("%s\n",ans)
		} else {
			printf(ans)
		}

	}
}

package main

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

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

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

func ValidateStrings(s, t string) bool {
	count := make(map[uint8]int)
	for i := range s {
		count[s[i]]++
		count[t[i]]++
	}
	for _, v := range count {
		if v%2 == 1 {
			return false
		}
	}
	return true
}

func FindUnequalIndex(s, t string) []int {
	var index []int
	for i := range s {
		if s[i] != t[i] {
			index = append(index, i)
		}
	}
	return index
}

func Swap(s, t string) (string, string) {
	index := FindUnequalIndex(s, t)
	for _, i := range index {
		for _, j := range index {
			if i == j {
				continue
			}
			if s[i] == s[j] {
				ans = ans + fmt.Sprintf("%d %d\n", i+1, j+1)
				return s[:i] + string(t[j]) + s[i+1:], t[:j] + string(s[i]) + t[j+1:]
			}
		}
	}
	ans = ans + fmt.Sprintf("%d %d\n", index[0]+1, index[0]+1)
	return s[:index[0]] + string(t[index[0]]) + s[index[0]+1:], t[:index[0]] + string(s[index[0]]) + t[index[0]+1:]
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var k, n int
	scanf("%d\n", &k)
	for ; k > 0; k-- {
		var s, t string
		ans = "No\n"
		scanf("%d\n", &n)
		scanf("%s\n", &s)
		scanf("%s\n", &t)

		if ValidateStrings(s, t) {
			ans = "YES\n"
			for s != t {
				s, t = Swap(s, t)
			}
		}

		//var sdif, tdif []int
		//for i := range s {
		//	if s[i] != t[i] {
		//		sdif = append(sdif, i)
		//		tdif = append(tdif, i)
		//	}
		//}
		//if len(sdif) == 2 {
		//	s, t = s[:sdif[0]]+string(t[tdif[1]])+s[sdif[0]+1:], t[:tdif[1]]+string(s[sdif[0]])+t[tdif[1]+1:]
		//	if s == t {
		//		ans = "Yes"
		//	}
		//}
		printf(ans)
	}
}

package main

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

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

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

func ValidateStrings(s, t string) bool {
	count := make(map[uint8]int)
	for i := range s {
		count[s[i]]++
		count[t[i]]++
	}
	for _, v := range count {
		if v%2 == 1 {
			return false
		}
	}
	return true
}

func FindUnequalIndex(s, t string) []int {
	var index []int
	for i := range s {
		if s[i] != t[i] {
			index = append(index, i)
		}
	}
	return index
}

func Swap(s, t string) (string, string) {
	index := FindUnequalIndex(s, t)
	for _, i := range index {
		for _, j := range index {
			if i == j {
				continue
			}
			if s[i] == s[j] {
				ans = ans + fmt.Sprintf("%d %d", i+1, j+1)
				return s[:i] + string(t[j]) + s[i+1:], t[:j] + string(s[i]) + t[j+1:]
			}
		}
	}
	ans = ans + fmt.Sprintf("%d %d", index[0]+1, index[0]+1)
	return s[:index[0]] + string(t[index[0]]) + s[index[0]+1:], t[:index[0]] + string(s[index[0]]) + t[index[0]+1:]
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var k, n int
	scanf("%d\n", &k)
	for ; k > 0; k-- {
		var s, t string
		ans = "No"
		scanf("%d\n", &n)
		scanf("%s\n", &s)
		scanf("%s\n", &t)

		if ValidateStrings(s, t) {
			ans = "YES"
			for s != t {
				ans += "\n"
				s, t = Swap(s, t)
			}
		}

		//var sdif, tdif []int
		//for i := range s {
		//	if s[i] != t[i] {
		//		sdif = append(sdif, i)
		//		tdif = append(tdif, i)
		//	}
		//}
		//if len(sdif) == 2 {
		//	s, t = s[:sdif[0]]+string(t[tdif[1]])+s[sdif[0]+1:], t[:tdif[1]]+string(s[sdif[0]])+t[tdif[1]+1:]
		//	if s == t {
		//		ans = "Yes"
		//	}
		//}
		if k != 1{
			printf("%s\n",ans)
		} else {
			printf(ans)
		}

	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

	return res
}

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

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var k int
var n int
var S, T []rune

func main() {
	k = ReadInt()
	for tc := 0; tc < k; tc++ {
		n = ReadInt()
		S = ReadRuneSlice()
		T = ReadRuneSlice()
		solve()
	}
}

func solve() {
	memo := make([]rune, ALPHABET_NUM)
	for i := 0; i < n; i++ {
		s, t := S[i], T[i]
		memo[s-'a']++
		memo[t-'a']++
	}

	for i := 0; i < len(memo); i++ {
		if memo[i]%2 == 1 {
			fmt.Println("No")
			return
		}
	}

	answers := [][]int{}
	for i := 0; i < n; i++ {
		if S[i] == T[i] {
			continue
		}

		for j := i + 1; j < n; j++ {
			if S[i] == S[j] {
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, i})
			} else if S[i] == T[j] {
				S[j], T[j] = T[j], S[j]
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, j})
				answers = append(answers, []int{j, i})
			}
		}
	}

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

	return res
}

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

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var k int
var n int
var S, T []rune

func main() {
	k = ReadInt()
	for tc := 0; tc < k; tc++ {
		n = ReadInt()
		S = ReadRuneSlice()
		T = ReadRuneSlice()
		solve()
	}
}

func solve() {
	memo := make([]rune, ALPHABET_NUM)
	for i := 0; i < n; i++ {
		s, t := S[i], T[i]
		memo[s-'a']++
		memo[t-'a']++
	}

	for i := 0; i < len(memo); i++ {
		if memo[i]%2 == 1 {
			fmt.Println("No")
			return
		}
	}

	answers := [][]int{}
	for i := 0; i < n; i++ {
		if S[i] == T[i] {
			continue
		}

		for j := i + 1; j < n; j++ {
			if S[i] == S[j] {
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, i})
			} else if S[i] == T[j] {
				S[j], T[j] = T[j], S[j]
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, j})
				answers = append(answers, []int{j, i})
			}
		}
	}

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

	return res
}

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

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

var k int
var n int
var S, T []rune

func main() {
	k = ReadInt()
	for tc := 0; tc < k; tc++ {
		n = ReadInt()
		S = ReadRuneSlice()
		T = ReadRuneSlice()
		solve()
	}
}

func solve() {
	memo := make([]rune, ALPHABET_NUM)
	for i := 0; i < n; i++ {
		s, t := S[i], T[i]
		memo[s-'a']++
		memo[t-'a']++
	}

	for i := 0; i < len(memo); i++ {
		if memo[i]%2 == 1 {
			fmt.Println("No")
			return
		}
	}

	answers := [][]int{}
	for i := 0; i < n; i++ {
		if S[i] == T[i] {
			continue
		}

		for j := i + 1; j < n; j++ {
			if S[i] == S[j] {
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, i})
			} else if S[i] == T[j] {
				S[j], T[j] = T[j], S[j]
				S[j], T[i] = T[i], S[j]
				answers = append(answers, []int{j, j})
				answers = append(answers, []int{j, i})
			}
		}
	}

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

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

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


The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.The Two-dimensional kingdom has a regular army of n people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the i-th soldier indicated size ai. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from ai - x to ai + y, inclusive (numbers x, y ≥ 0 are specified). The Two-dimensional kingdom has m vests at its disposal, the j-th vest's size equals bj. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The i-th soldier can put on the j-th vest, if ai - x ≤ bj ≤ ai + y.

The first input line contains four integers n, m, x and y (1 ≤ n, m ≤ 105, 0 ≤ x, y ≤ 109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) in non-decreasing order, separated by single spaces — the desired sizes of vests.  The third line contains m integers b1, b2, ..., bm (1 ≤ bj ≤ 109) in non-decreasing order, separated by single spaces — the sizes of the available vests.

In the first line print a single integer k — the maximum number of soldiers equipped with bulletproof vests.  In the next k lines print k pairs, one pair per line, as "ui vi" (without the quotes). Pair (ui, vi) means that soldier number ui must wear vest number vi. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them.

NoteIn the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.

//http://codeforces.com/problemset/problem/161/A

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, x, y := reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
	}
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = reader.ReadInt()
	}

	type Pairs struct {
		u, v int
	}

	ls := make([]*Pairs, n)

	bi := 0
	lsi := 0
	for ai := 0; ai < n; ai++ {
		for bi < m && a[ai]-x > b[bi] {
			bi++
		}
		if bi == m {
			break
		}
		if b[bi] <= a[ai]+y {
			ls[lsi] = &Pairs{ai + 1, bi + 1}
			lsi++
			bi++
		}
	}

	fmt.Println(lsi)
	for i := 0; i < lsi; i++ {
		p := ls[i]
		fmt.Println(p.u, p.v)
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

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

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

	var n int64
	var m int64
	var x int64
	var y int64
	var i int64 = 0
	var j int64 = 0
	var desiredSizesTmp []string
	var desiredSizes []int64
	var sizesOfAvailableVestsTmp []string
	var sizesOfAvailableVests []int64
	var listFit []string

	inputLine1, _ := reader.ReadString('\n')
	tmp := strings.Split(strings.TrimSpace(inputLine1), " ")
	n, _ = strconv.ParseInt(string(tmp[0]), 10, 64)
	m, _ = strconv.ParseInt(string(tmp[1]), 10, 64)
	x, _ = strconv.ParseInt(string(tmp[2]), 10, 64)
	y, _ = strconv.ParseInt(string(tmp[3]), 10, 64)

	inputLine2, _ := reader.ReadString('\n')
	desiredSizesTmp = strings.Split(strings.TrimSpace(inputLine2), " ")
	desiredSizes = convertStringToInt64(desiredSizesTmp)

	inputLine3, _ := reader.ReadString('\n')
	sizesOfAvailableVestsTmp = strings.Split(strings.TrimSpace(inputLine3), " ")
	sizesOfAvailableVests = convertStringToInt64(sizesOfAvailableVestsTmp)

	for i = 0; i < n; i++ {

		for (j < m) && (sizesOfAvailableVests[j] <= desiredSizes[i] + y)  {
			if (desiredSizes[i] - x <= sizesOfAvailableVests[j]) && (desiredSizes[i] + y >= sizesOfAvailableVests[j]) {
				listFit = append(listFit, fmt.Sprintf("%v %v", i + 1, j + 1))
				j++
				break
			}
			j++
		}
	}

	fmt.Println(len(listFit))
	for _, value := range listFit {
		fmt.Println(value)
	}
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,m,x,y int
    var a,b [100010]int
    ans := make([]string,0,100010)
    fmt.Scan(&n,&m,&x,&y)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    for i := 0; i < m; i++ {
        scanner.Scan()
        b[i], _ = strconv.Atoi(scanner.Text())
    }
    for i, j := 0, 0; (i < n) && (j < m); {
        if (a[i]-x) > b[j] {
            j++
        } else if (a[i]+y) < b[j] {
            i++
        } else {
            ans = append(ans,strconv.Itoa(i+1)+" "+strconv.Itoa(j+1))
            i++; j++;
        }
    }
    writer.WriteString(strconv.Itoa(len(ans))+"\n")
    for i := 0; i < len(ans); i++ {
        writer.WriteString(ans[i]+"\n")
    }
    writer.Flush()
}

package main

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

func solve(want []int, have []int, x int, y int, m int, n int) {
	count := 0
	result := []int{}
	w := 0
	h := 0
	for w < n && h < m {
		if want[w]-x <= have[h] && want[w]+y >= have[h] {
			count++
			result = append(result, w+1, h+1)
			w++
			h++
		} else if have[h] < want[w]-x {
			h++
		} else {
			w++
		}
	}

	fmt.Println(count)
	for i := 0; i < len(result); i += 2 {
		fmt.Println(result[i], result[i+1])
	}
}

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

	var n, m, x, y int

	fmt.Fscanf(r, "%d %d %d %d\n", &n, &m, &x, &y)

	want := make([]int, n)
	have := make([]int, m)

	for i := range want {
		if i == n-1 {
			fmt.Fscanf(r, "%d\n", &want[i])
		} else {
			fmt.Fscanf(r, "%d", &want[i])
		}
	}

	for i := range have {
		fmt.Fscanf(r, "%d ", &have[i])
	}

	solve(want, have, x, y, m, n)
}

package main

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

func solve(want []int, have []int, x int, y int, m int, n int) {
	count := 0
	result := []int{}
	w := 0
	h := 0
	for w < n && h < m {
		if want[w]-x <= have[h] && want[w]+y >= have[h] {
			count++
			result = append(result, w+1, h+1)
			w++
			h++
		} else if have[h] < want[w]-x {
			h++
		} else {
			w++
		}
	}

	fmt.Fprintf(os.Stdout, "%d\n", count)
	for i := 0; i < len(result); i += 2 {
		fmt.Fprintf(os.Stdout, "%d %d\n", result[i], result[i+1])
	}
}

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

	var n, m, x, y int

	fmt.Fscanf(r, "%d %d %d %d\n", &n, &m, &x, &y)

	want := make([]int, n)
	have := make([]int, m)

	for i := range want {
		if i == n-1 {
			fmt.Fscanf(r, "%d\n", &want[i])
		} else {
			fmt.Fscanf(r, "%d", &want[i])
		}
	}

	for i := range have {
		fmt.Fscanf(r, "%d ", &have[i])
	}

	solve(want, have, x, y, m, n)
}

// 161A-mic_rizal
package main

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

func main() {
    var n, m, x, y, i, j, k, l int
    var a, b [100010]int
    z := bufio.NewReader(os.Stdin)
    var p []int
    fmt.Fscan(z, &n, &m, &x, &y)
    for i = 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
    }
    for i = 0; i < m; i++ {
        fmt.Fscan(z, &b[i])
    }
    for i = 0; i < n && j < m; i++ {
        if a[i]-x <= b[j] && b[j] <= a[i]+y {
            k++
            p = append(p, i+1)
            l++
            p = append(p, j+1)
            l++
            j++
        } else if b[j] < a[i]-x {
            j++
            i--
        }
    }
    fmt.Println(k)
    for i = 0; i < l; i += 2 {
        fmt.Println(p[i], p[i+1])
    }
}

package main

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

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

	var n int64
	var m int64
	var x int64
	var y int64
	var i int64 = 0
	var j int64 = 0
	var desiredSizesTmp []string
	var desiredSizes []int64
	var sizesOfAvailableVestsTmp []string
	var sizesOfAvailableVests []int64
	var listFit []string

	inputLine1, _ := reader.ReadString('\n')
	tmp := strings.Split(strings.TrimSpace(inputLine1), " ")
	n, _ = strconv.ParseInt(string(tmp[0]), 10, 64)
	m, _ = strconv.ParseInt(string(tmp[1]), 10, 64)
	x, _ = strconv.ParseInt(string(tmp[2]), 10, 64)
	y, _ = strconv.ParseInt(string(tmp[3]), 10, 64)

	inputLine2, _ := reader.ReadString('\n')
	desiredSizesTmp = strings.Split(strings.TrimSpace(inputLine2), " ")
	desiredSizes = convertStringToInt64(desiredSizesTmp)

	inputLine3, _ := reader.ReadString('\n')
	sizesOfAvailableVestsTmp = strings.Split(strings.TrimSpace(inputLine3), " ")
	sizesOfAvailableVests = convertStringToInt64(sizesOfAvailableVestsTmp)

	for i = 0; i < n; i++ {

		for (j < m) && (sizesOfAvailableVests[j] <= desiredSizes[i] + y)  {
			if (desiredSizes[i] - x <= sizesOfAvailableVests[j]) && (desiredSizes[i] + y >= sizesOfAvailableVests[j]) {
				listFit = append(listFit, fmt.Sprintf("%v %v", i + 1, j + 1))
				break
			}
			j++
		}
	}

	fmt.Println(len(listFit))
	for _, value := range listFit {
		fmt.Println(value)
	}
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func solve(want []int, have []int, x int, y int, m int, n int) {
	count := 0
	result := []int{}
	j := 0

	for i := range want {
		if j < m && (want[i]-x <= have[j] && want[i]+y >= have[j]) {
			count++
			result = append(result, i+1, j+1)
			j++
		}
	}

	fmt.Println(count)

	for i := 0; i < len(result); i += 2 {
		fmt.Println(result[i], result[i+1])
	}
}

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

	var n, m, x, y int

	fmt.Fscanf(r, "%d %d %d %d\n", &n, &m, &x, &y)

	want := make([]int, n)
	have := make([]int, m)

	for i := range want {
		if i == n-1 {
			fmt.Fscanf(r, "%d\n", &want[i])
		} else {
			fmt.Fscanf(r, "%d", &want[i])
		}
	}

	for i := range have {
		fmt.Fscanf(r, "%d ", &have[i])
	}

	solve(want, have, x, y, m, n)
}

//http://codeforces.com/problemset/problem/161/A

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, x, y := reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
	}

	type Pairs struct {
		u, v int
	}

	ls := list.New()

	ai := 0
	for i := 0; i < m; i++ {
		b := reader.ReadInt()
		for {
			if a[ai]-x <= b && b <= a[ai]+y {
				ls.PushBack(&Pairs{ai + 1, i + 1})
				ai++
				break
			} else {
				ai++
				if ai == n || a[ai]+y > b {
					break
				}
			}
		}
		if ai == n {
			break
		}
	}

	fmt.Println(ls.Len())
	e := ls.Front()
	for e != nil {
		p := e.Value.(*Pairs)
		fmt.Println(p.u, p.v)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

//http://codeforces.com/problemset/problem/161/A

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, x, y := reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
	}

	type Pairs struct {
		u, v int
	}

	ls := list.New()

	ai := 0
	for i := 0; i < m; i++ {
		b := reader.ReadInt()
		aiBack := ai
		for {
			if a[ai]-x <= b && b <= a[ai]+y {
				ls.PushBack(&Pairs{ai + 1, i + 1})
				ai++
				break
			} else {
				ai++
				if ai == n || a[ai]+y > b {
					ai = aiBack
					break
				}
			}
		}
		if ai == n {
			break
		}
	}

	fmt.Println(ls.Len())
	e := ls.Front()
	for e != nil {
		p := e.Value.(*Pairs)
		fmt.Println(p.u, p.v)
		e = e.Next()
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}


Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi ≤ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?

The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.

Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.

NoteIn the first sample the possible values of x are 3, 4 or 5.In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.

package main

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

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

	//var n int
	//var a int
	var b int
	var h []int

	inputLine1, _ := reader.ReadString('\n')
	value := strings.Split(strings.TrimSpace(inputLine1), " ")

	//n, _ = strconv.Atoi(value[0])
	//a, _ = strconv.Atoi(value[1])
	b, _ = strconv.Atoi(value[2])

	inputLine2, _ := reader.ReadString('\n')
	tmpChores := strings.Split(strings.TrimSpace(inputLine2), " ")

	h = convertStringToInt(tmpChores)

	sort.Slice(h, func(i, j int) bool {
		return h[i] < h[j]
	})

	vasya := h[b - 1]
	petya := h[b]

	fmt.Println(petya - vasya)
}

func convertStringToInt(arr []string) (result []int) {

	for _, string := range arr {
		if string == "" {
			continue
		}
		value, err := strconv.Atoi(string)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func solve(n int, p int, v int, arr []int) int {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] > arr[j] })

	for i := range arr {
		if p > 0 {
			p--
		} else {
			if arr[i] != arr[i-1] {
				return arr[i-1] - arr[i]
			}
			break
		}
	}
	return 0
}

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

	var n, p, v int
	fmt.Fscanf(r, "%d %d %d\n", &n, &p, &v)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, p, v, arr))
}

package main

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

func solve(n int, p int, v int, arr []int) int {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] > arr[j] })

	for i := range arr {
		if p > 0 {
			p--
			continue
		}
			if arr[i] != arr[i-1] {
				return arr[i-1] - arr[i]
			}
			break
	}

	return 0
}

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

	var n, p, v int
	fmt.Fscanf(r, "%d %d %d\n", &n, &p, &v)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, p, v, arr))
}

//http://codeforces.com/problemset/problem/169/A
package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, _, b := reader.ReadInt(), reader.ReadInt(), reader.ReadInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = reader.ReadInt()
	}

	sort.Ints(h)

	if h[b-1] == h[b] {
		fmt.Print(0)
		return
	}
	fmt.Print(h[b] - h[b-1])
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var n, a, b int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &a, &b)

	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &h[i])
	}

	h = sort(h)
	if h[b - 1] < h[b] {
		fmt.Fprintf(writer, "%d\n", h[b] - h[b - 1])
	} else {
		fmt.Fprintf(writer, "0\n")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

func solve(n int, p int, v int, arr []int) int {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] > arr[j] })

	for i := range arr {
		if p > 0 {
			p--
		} else {
			if arr[i] != arr[i-1] {
				return arr[i-1] - arr[i]
			}
		}
	}
	return 0
}

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

	var n, p, v int
	fmt.Fscanf(r, "%d %d %d\n", &n, &p, &v)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, p, v, arr))
}

//http://codeforces.com/problemset/problem/169/A
package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, _, b := reader.ReadInt(), reader.ReadInt(), reader.ReadInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = reader.ReadInt()
	}

	sort.Ints(h)

	if h[b-1] == h[b] || (b > 1 && h[b-1] == h[b-2]) {
		fmt.Print(0)
		return
	}
	fmt.Print(h[b] - h[b-1])
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}