← Home
package main

import (
	"io"
	"os"
)

func main() {
	in, _ := io.ReadAll(os.Stdin)
	pos := 0

	nextInt := func() int {
		for pos < len(in) && in[pos] <= 32 {
			pos++
		}
		if pos >= len(in) {
			return 0
		}
		res := 0
		for pos < len(in) && in[pos] > 32 {
			res = res*10 + int(in[pos]-'0')
			pos++
		}
		return res
	}

	t := nextInt()
	var out []byte
	for i := 0; i < t; i++ {
		n := nextInt()
		k := nextInt()

		first := make(map[int]int, n)
		last := make(map[int]int, n)

		for j := 0; j < n; j++ {
			u := nextInt()
			if _, ok := first[u]; !ok {
				first[u] = j
			}
			last[u] = j
		}

		for j := 0; j < k; j++ {
			a := nextInt()
			b := nextInt()

			f, okA := first[a]
			l, okB := last[b]

			if okA && okB && f < l {
				out = append(out, "YES\n"...)
			} else {
				out = append(out, "NO\n"...)
			}
		}
	}
	os.Stdout.Write(out)
}