package main
import (
	"fmt"
)
func main() {
	var n int
	m:=make([]int,1005)
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&m[i])
	}
	cnt,x,y,p,q:=0,0,0,0,n-1
	for p<=q {
		if (cnt & 1)==1 {
			if m[p]>m[q] {
				y += m[p]
				p++
			} else {
				y += m[q]
				q--
			}
		} else {
			if m[p]>m[q] {
				x += m[p]
				p++
			} else {
				x += m[q]
				q--
			}
		}
		cnt++
	}
	fmt.Println(x,y)

}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	card := make([]int, n);

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

	sereja, dima := 0, 0

	for i, j:=0, n; i<j; {
		if card[i]>card[j-1] {
			sereja+=card[i]
			i++
		} else {
			sereja+=card[j-1]
			j--
		}

		if i<j {
			if card[i]>card[j-1] {
				dima+=card[i]
				i++
			} else {
				dima+=card[j-1]
				j--
			}
		}
	}

	fmt.Println(sereja, dima)
}

package main

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

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

	var n int64
	var i int64 = 0
	var j int64 = 0

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

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt64(cardsString)

	var turn int64 = 0
	var sereja int64 = 0
	var dima int64 = 0

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

		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}

		turn++
	}

	fmt.Println(sereja, dima)
}

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"
	"strconv"
	"strings"
)

func quicksort(nums []int, start int, end int) {
	var pivot, swapIndex int

	if end-start <= 1 {
		return
	}
	pivot = nums[start]
	swapIndex = start + 1
	for i := start + 1; i < end; i++ {
		if nums[i] < pivot {
			nums[i], nums[swapIndex] = nums[swapIndex], nums[i]
			swapIndex++
		}
	}
	swapIndex--
	nums[start], nums[swapIndex] = nums[swapIndex], nums[start]
	quicksort(nums, start, swapIndex)
	quicksort(nums, swapIndex+1, end)
}

func main() {
	var nums []int
	var n int
	var scanner *bufio.Scanner
	var e error
	var numsString []string
	var sereja, dima int
	var flag int

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, e = strconv.Atoi(strings.TrimSpace(scanner.Text()))
	if e != nil {
		panic(e)
	}
	scanner.Scan()
	numsString = strings.Split(scanner.Text(), " ")
	nums = make([]int, n)
	for i := 0; i < n; i++ {
		nums[i], e = strconv.Atoi(numsString[i])
		if e != nil {
			panic(e)
		}
	}
	// quicksort(nums, 0, n)
	flag = 1
	for i := n - 1; i > -1; i-- {
		if flag == 1 {
			if nums[0] >= nums[len(nums)-1] {
				sereja = sereja + nums[0]
				nums = nums[1:]
			} else {
				sereja = sereja + nums[len(nums)-1]
				nums = nums[:len(nums)-1]
			}
			flag = 2
		} else {
			if nums[0] >= nums[len(nums)-1] {
				dima = dima + nums[0]
				nums = nums[1:]
			} else {
				dima = dima + nums[len(nums)-1]
				nums = nums[:len(nums)-1]
			}
			flag = 1
		}
	}

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

// 42
// 15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	var sereja_dima [2]int
	var i int = 0 // Sereja first
	var head int = 0
	var tail int = n - 1
	for head <= tail {
		if array[head] > array[tail] {
			sereja_dima[i] += array[head]
			head++
		} else {
			sereja_dima[i] += array[tail]
			tail--
		}
		i = (i + 1) % 2
	}

	fmt.Printf("%d %d\n", sereja_dima[0], sereja_dima[1])
}

package main

import "fmt"

func main() {
    var n int
    var a [1005]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    l, r := 0, n-1
    score := [2]int{0,0}
    for i := 0; i < n; i++ {
        if a[l] > a[r] {
            score[i%2] += a[l]
            l++
        } else {
            score[i%2] += a[r]
            r--
        }
    }
    fmt.Println(score[0],score[1])
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	cards := make([]int, n)
	// fmt.Println(n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &cards[i])
	}
	// fmt.Println(cards)
	j := n - 1
	i := 0
	var count int
	var s int
	var d int
	for i <= j {
		// fmt.Println(count, i, j, cards[i], cards[j])
		if cards[i] > cards[j] {
			if count%2 == 0 {
				s += cards[i]
				i++
				count++
			} else {
				d += cards[i]
				i++
				count++
			}
		} else {
			if count%2 == 0 {
				s += cards[j]
				j--
				count++
			} else {
				d += cards[j]
				j--
				count++
			}

		}
	}
	fmt.Println(s, d)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var input = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&input[i])
	}

	var s, d int
	var start, end int = 0, n - 1
	var i int = 2
	for {
		if start > end {
			break
		}
		if i%2 == 0 {
			if input[start] > input[end] {
				s += input[start]
				start++
			} else {
				s += input[end]
				end--
			}
		} else {
			if input[start] > input[end] {
				d += input[start]
				start++
			} else {
				d += input[end]
				end--
			}
		}
		i++
	}
	fmt.Printf("%d %d\n", s, d)
}

package main

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

func solve(n int, arr []int) {
	seraja, dima, left, right, turn := 0, 0, 0, n-1, 0

	for left <= right {
		if turn%2 == 0 {
			if arr[left] > arr[right] {
				seraja += arr[left]
				left++
			} else {
				seraja += arr[right]
				right--
			}
		} else {
			if arr[left] > arr[right] {
				dima += arr[left]
				left++
			} else {
				dima += arr[right]
				right--
			}
		}
		turn++
	}

	fmt.Println(seraja, dima)
}

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

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

	arr := make([]int, n)

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

	solve(n, arr)
}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    card := make([]int, n + 5)
    for i := 0; i < n; i++ {
        fmt.Scan(&card[i])
    }

    sum := make([]int, 2)
    head, tail := 0, n - 1
    for i := 0; i < n; i++ {
        var bigger int
        if card[head] > card[tail] {
            bigger = card[head]
            head++
        } else {
            bigger = card[tail]
            tail --
        }
        sum[i % 2] += bigger
    }
    fmt.Println(sum[0], sum[1])
}

package main

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

func main() {
	var n, inp uint32
	var s, d uint32
	var h []uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint32(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	if n == 1 {
		fmt.Println(inp, 0)
		return
	}
	l := uint32(n - 1)
	i := uint32(0)

	for i <= l && l >= 0 && l < 1001 {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
			break
		}
	}
	fmt.Println(s, d)
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")
	list := make([]int, n)

	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	sereja := 0
	dima := 0
	i := 0
	j := len(list) - 1
	for {
		if list[i] >= list[j] {
			sereja += list[i]
			i++
		} else {
			sereja += list[j]
			j--
		}

		if i > j {
			break
		}

		if list[i] >= list[j] {
			dima += list[i]
			i++
		} else {
			dima += list[j]
			j--
		}

		if i > j {
			break
		}
	}

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

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var cards []int = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	i := 0
	j := len(cards) - 1
	turn := true //sereja
	var serejaScore, dimaScore int = 0, 0
	for j >= i {
		if cards[j] > cards[i] {
			if turn {
				serejaScore += cards[j]
			} else {
				dimaScore += cards[j]
			}
			j--
		} else {
			if turn {
				serejaScore += cards[i]
			} else {
				dimaScore += cards[i]
			}
			i++
		}
		turn = !turn
	}
	fmt.Println(serejaScore, dimaScore)
}

package main

import (
	"fmt"
)

func solve(n int, numbers []int) (a, b int) {
	left := 0
	right := n - 1
	a = 0
	b = 0
	for left <= right {
		if numbers[left] > numbers[right] {
			a += numbers[left]
			left++
		} else {
			a += numbers[right]
			right--
		}

		if left > right {
			break
		}

		if numbers[left] > numbers[right] {
			b += numbers[left]
			left++
		} else {
			b += numbers[right]
			right--
		}
	}

	return a, b
}

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

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

	fmt.Println(solve(n, numbers))
}

package main

import (
	"fmt"
)

func main() {
	var numberOfCards int
	var serejaPoints, dimaPoints int
	fmt.Scan(&numberOfCards)
	cardsInt := make([]int, numberOfCards)
	var myInt int
	for index := 0; index < numberOfCards; index++ {
		fmt.Scan(&myInt)
		cardsInt[index] = myInt
	}
	i := 0
	j := numberOfCards - 1
	turns := 1
	for numberOfCards != turns-1 {
		toAdd := 0
		if int(cardsInt[i]) > int(cardsInt[j]) {
			toAdd = cardsInt[i]
			i++
		} else {
			toAdd = cardsInt[j]
			j--
		}
		if turns%2 == 0 {
			dimaPoints += toAdd
		} else {
			serejaPoints += toAdd
		}
		turns++
	}
	fmt.Println(serejaPoints, " ", dimaPoints)
}

package main

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

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

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

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

	var a, b, d, r int
	c := []int{}
	scanf("%d %d\n", &a, &b)
	for i := 0; i < a; i++ {
		scanf("%d", &b)
		c = append(c, b)
	}
	isA := false

	for len(c) > 0 {
		greatest := 0
		if len(c) < 2 {
			greatest = c[0]
			c = []int{}
		} else {
			if c[0] > c[len(c)-1] {
				greatest = c[0]
				c = c[1:len(c)]
			} else {
				greatest = c[len(c)-1]
				c = c[:len(c)-1]
			}
		}

		if !isA {
			d += greatest
			isA = true
		} else {
			r += greatest
			isA = false
		}
	}
	//CODE HERE
	printf("%d %d\n", d, r)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	card := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &card[i])
	}
	var l, r int = 0, n - 1
	var a, b int = 0, 0
	for i := 0; i < n; i++ {
		var temp int = 0
		if card[l] > card[r] {
			temp = card[l]
			l++
		} else {
			temp = card[r]
			r--
		}
		if i&1 == 1 {
			b += temp
		} else {
			a += temp
		}
	}
	fmt.Println(a, b)
}

package main

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

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

	var n int16
	var i int16 = 0
	var j int16 = 0

	inputLine1, _, _ := reader.ReadLine()
	tmp, err := strconv.ParseInt(string(inputLine1[0]), 10, 64)
	if err != nil {
		panic(err)
	}

	n = int16(tmp)

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt16(cardsString)

	var turn int16 = 0
	var sereja int16 = 0
	var dima int16 = 0

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

		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}
		turn++
	}

	fmt.Println(sereja, dima)
}

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

package main

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

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

	var n int16
	var i int16 = 0
	var j int16 = 0

	inputLine1, _, _ := reader.ReadLine()
	tmp, err := strconv.ParseInt(string(inputLine1[0]), 10, 64)
	if err != nil {
		panic(err)
	}

	n = int16(tmp)

	j = n - 1

	cardsString := make([]string, n)
	inputLine2, _ := reader.ReadString('\n')
	cardsString = strings.Split(strings.TrimSpace(inputLine2), " ")
	cards := convertStringToInt16(cardsString)

	var turn int16 = 0
	var sereja int16 = 0
	var dima int16 = 0

	fmt.Println(i, j, n)
	for i = 0; i <= j; i++ {

		fmt.Println(cards[j], cards[i])
		for cards[j] > cards[i] {
			if turn % 2 == 0 {
				sereja += cards[j]
			} else {
				dima += cards[j]
			}
			j--
			turn++
		}

		if turn % 2 == 0 {
			sereja += cards[i]
		} else {
			dima += cards[i]
		}
		turn++
	}

	fmt.Println(sereja, dima)
}

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

package main

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

func quicksort(nums []int, start int, end int) {
	var pivot, swapIndex int

	if end-start <= 1 {
		return
	}
	pivot = nums[start]
	swapIndex = start + 1
	for i := start + 1; i < end; i++ {
		if nums[i] < pivot {
			nums[i], nums[swapIndex] = nums[swapIndex], nums[i]
			swapIndex++
		}
	}
	swapIndex--
	nums[start], nums[swapIndex] = nums[swapIndex], nums[start]
	quicksort(nums, start, swapIndex)
	quicksort(nums, swapIndex+1, end)
}

func main() {
	var nums []int
	var n int
	var scanner *bufio.Scanner
	var e error
	var numsString []string
	var sereja, dima int
	var flag int

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, e = strconv.Atoi(strings.TrimSpace(scanner.Text()))
	if e != nil {
		panic(e)
	}
	scanner.Scan()
	numsString = strings.Split(scanner.Text(), " ")
	nums = make([]int, n)
	for i := 0; i < n; i++ {
		nums[i], e = strconv.Atoi(numsString[i])
		if e != nil {
			panic(e)
		}
	}
	quicksort(nums, 0, n)
	// fmt.Println(nums)
	flag = 1
	for i := n - 1; i > -1; i-- {
		if flag == 1 {
			sereja = sereja + nums[i]
			flag = 2
		} else {
			dima = dima + nums[i]
			flag = 1
		}
	}

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

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := n - 1
	i := uint16(0)
	for i <= l {
		if h[i] > h[l] {
			s += uint32(h[i])
			fmt.Println("seroja ", h[i])
			i++
		} else {
			s += uint32(h[l])
			fmt.Println("seroja ", h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			fmt.Println("dima ", h[i])
			i++
		} else {
			d += uint32(h[l])
			fmt.Println("dima ", h[l])
			l--
		}
		if i == l {
			fmt.Println("tentsesen seroja ", h[i])
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	if n == 1 {
		return
	}
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := n - 1
	i := uint16(0)
	for i <= l {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

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

func main() {
	var n, inp uint16
	var s, d uint32
	var h []uint16
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d", &inp)
		h = append(h, inp)
	}
	l := int16(n - 1)
	i := int16(0)
	for i < int16(n) && l > 0 {
		if h[i] > h[l] {
			s += uint32(h[i])
			i++
		} else {
			s += uint32(h[l])
			l--
		}
		if h[i] > h[l] {
			d += uint32(h[i])
			i++
		} else {
			d += uint32(h[l])
			l--
		}
		if i == l {
			s += uint32(h[i])
			i++
		}
	}
	fmt.Println(s, d)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	card := make([]int, n + 5)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &card[i])
	}

	sum := make([]int, 2)
	head, tail := 0, n - 1
	for i := 0; i < n; i++ {
		var bigger int
		if card[head] > card[tail] {
			bigger = card[head]
			head++
		} else {
			bigger = card[tail]
			tail --
		}
		sum[i % 2] += bigger
	}
	fmt.Println(sum[0], sum[1])
}


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

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"
	"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はとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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


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

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


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

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
}