Along the railroad there are stations indexed from $1$ to $10^9$. An express train always travels along a route consisting of $n$ stations with indices $u_1, u_2, \dots, u_n$, where ($1 \le u_i \le 10^9$). The train travels along the route from left to right. It starts at station $u_1$, then stops at station $u_2$, then at $u_3$, and so on. Station $u_n$ — the terminus.

It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values $u_1, u_2, \dots, u_n$.

You are given $k$ queries, each containing two different integers $a_j$ and $b_j$ ($1 \le a_j, b_j \le 10^9$). For each query, determine whether it is possible to travel by train from the station with index $a_j$ to the station with index $b_j$.

For example, let the train route consist of $6$ of stations with indices [$3, 7, 1, 5, 1, 4$] and give $3$ of the following queries:

$a_1 = 3$, $b_1 = 5$

It is possible to travel from station $3$ to station $5$ by taking a section of the route consisting of stations [$3, 7, 1, 5$]. Answer: YES.

$a_2 = 1$, $b_2 = 7$

You cannot travel from station $1$ to station $7$ because the train cannot travel in the opposite direction. Answer: NO.

$a_3 = 3$, $b_3 = 10$

It is not possible to travel from station $3$ to station $10$ because station $10$ is not part of the train's route. Answer: NO.


-----Input-----

The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) —the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case is empty.

The second line of each test case contains two integers: $n$ and $k$ ($1 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$) —the number of stations the train route consists of and the number of queries.

The third line of each test case contains exactly $n$ integers $u_1, u_2, \dots, u_n$ ($1 \le u_i \le 10^9$). The values $u_1, u_2, \dots, u_n$ are not necessarily different.

The following $k$ lines contain two different integers $a_j$ and $b_j$ ($1 \le a_j, b_j \le 10^9$) describing the query with index $j$.

It is guaranteed that the sum of $n$ values over all test cases in the test does not exceed $2 \cdot 10^5$. Similarly, it is guaranteed that the sum of $k$ values over all test cases in the test also does not exceed $2 \cdot 10^5$


-----Output-----

For each test case, output on a separate line:

YES, if you can travel by train from the station with index $a_j$ to the station with index $b_j$

NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).


-----Examples-----

Input
3
6 3
3 7 1 5 1 4
3 5
1 7
3 10
3 3
1 2 1
2 1
1 2
4 5
7 5
2 1 1 1 2 4 4
1 3
1 4
2 1
4 1
1 2
Output
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES


-----Note-----

The first test case is explained in the problem statement.

Source: codeforces | Difficulty: EASY
Tags: Data structures

Greedy algorithms


Solutions:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	_ = input()
	(n, k) = map(int, input().split())
	u = input().split()
	first = {item: n - i - 1 for (i, item) in enumerate(reversed(u))}
	last = {item: i for (i, item) in enumerate(u)}
	for _ in range(k):
		(a, b) = input().split()
		if a in first and b in last and (first[a] <= last[b]):
			sys.stdout.write('YES\n')
		else:
			sys.stdout.write('NO\n')


import sys

def get_int():
	return map(int, sys.stdin.readline().strip().split())

def get_lis():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_liss():
	return sys.stdin.readline().split()

def get_ints():
	return sys.stdin.readline().split()

def get_str():
	return sys.stdin.readline().strip()
from collections import defaultdict
t = int(input())
while t:
	input()
	(n, k) = get_int()
	l = get_liss()
	f = defaultdict(lambda : float('inf'))
	ld = defaultdict(lambda : -1)
	for i in range(n):
		if l[i] not in f:
			f[l[i]] = i
		ld[l[i]] = i
	for i in range(k):
		(a, b) = get_ints()
		if f[a] < ld[b]:
			sys.stdout.write('YES\n')
		else:
			sys.stdout.write('NO\n')
	t -= 1


for t in range(int(input())):
	s = input()
	(n, k) = map(int, input().split())
	stations = input().split()
	d = {}
	d_last = {}
	ans = []
	for x in range(0, n):
		if stations[x] not in d:
			d[stations[x]] = x
			d_last[stations[x]] = x
		else:
			d_last[stations[x]] = x
	for x in range(k):
		(a, b) = input().split()
		if a not in d or b not in d:
			ans.append('NO')
			continue
		if int(d[a]) < int(d_last[b]):
			ans.append('YES')
		else:
			ans.append('NO')
	print('\n'.join(ans))


import sys
EMPTY = 1
out = []
lines = [line.split() for line in sys.stdin.readlines()]
li = 1 + EMPTY
for _ in range(int(lines[0][0])):
	(n, k) = map(int, lines[li])
	u = lines[li + 1]
	first = dict()
	last = dict()
	for (i, ui) in enumerate(u):
		if ui not in first:
			first[ui] = i
		last[ui] = i
	for (a, b) in lines[li + 2:li + 2 + k]:
		out.append('YES' if a in first and b in first and (first[a] < last[b]) else 'NO')
	li += k + 2 + EMPTY
sys.stdout.write('\n'.join(out))


import sys
input = sys.stdin.readline
from collections import defaultdict as dd

def miis():
	return map(int, input().split())
for _ in range(int(input())):
	input()
	(n, k) = miis()
	a = input().split()
	l = dd(lambda : float('inf'))
	r = dd(lambda : -1)
	for i in range(n):
		if a[i] not in l:
			l[a[i]] = i
		r[a[i]] = i
	for i in range(k):
		(a, b) = input().split()
		if l[a] < r[b]:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
for i in range(int(input())):
	input()
	(n, k) = [int(i) for i in input().split()]
	a = {}
	q = input().split()
	for (i, j) in enumerate(q):
		if j in a:
			a[j][1] = i
		else:
			a[j] = [i, i]
	for i in range(k):
		(q, w) = input().split()
		if q in a and w in a:
			if a[q][0] < a[w][1]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	a = input().split()
	d = dict()
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = [i, i]
		else:
			d[a[i]][1] = i
	for i in range(k):
		(x, y) = input().split()
		if x not in d or y not in d:
			print('NO')
			continue
		if d[x][0] < d[y][1]:
			print('YES')
		else:
			print('NO')


from cmath import *
from decimal import *
import sys
input = sys.stdin.readline

def _input():
	return map(int, input().split())

def _list():
	return list(map(int, input().split()))

def solves():
	(n, m) = _input()
	a = _list()
	f = {}
	for i in range(n):
		x = a[i] ^ 69
		if x not in f:
			f[x] = i
	l = {}
	for i in range(n - 1, -1, -1):
		x = a[i] ^ 69
		if x not in l:
			l[x] = i
	for _ in range(m):
		(x, y) = map(lambda k: int(k) ^ 69, input().split())
		if x in f and y in l and (f[x] < l[y]):
			print('YES')
		else:
			print('NO')
t = 1
t = int(input())
for _ in range(0, t):
	input()
	solves()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	U = list(map(str, input().split()))
	v_to_i = dict()
	for i in range(n):
		u = U[i]
		if u in v_to_i:
			v_to_i[u][1] = i
		else:
			v_to_i[u] = [i, i]
	for _ in range(k):
		(a, b) = map(str, input().split())
		if a in v_to_i and b in v_to_i and (v_to_i[a][0] < v_to_i[b][1]):
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline

def solve():
	f = lambda x: x * 239017 + 17239
	input()
	(n, q) = map(int, input().split())
	left = {}
	right = {}
	a = list(enumerate(map(int, input().split())))
	for (i, x) in a:
		right[f(x)] = i
	for (i, x) in a[::-1]:
		left[f(x)] = i
	for iq in range(q):
		(a, b) = map(int, input().split())
		print('YES' if left.get(f(a), n) < right.get(f(b), -1) else 'NO')
tn = int(input())
for _ in range(tn):
	solve()


out = []
for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = input().split()
	g = dict()
	for i in range(n):
		idx = u[i]
		if idx in g:
			g[idx][1] = i
		else:
			g[idx] = [i, i]
	for i in range(k):
		(a, b) = input().split()
		if not a in g or not b in g:
			out.append('NO')
		elif g[a][0] < g[b][1]:
			out.append('YES')
		else:
			out.append('NO')
for i in out:
	print(i)


def sol(arr, queries):
	first = dict()
	last = dict()
	for i in range(len(arr)):
		if arr[i] not in first:
			first[arr[i]] = i
		last[arr[i]] = i
	for (a, b) in queries:
		if a not in first or b not in first:
			print('NO')
		elif first[a] <= last[b]:
			print('YES')
		else:
			print('NO')
x = int(input())
for _ in range(x):
	input()
	(n, k) = list(map(int, input().split()))
	arr = input().split()
	queries = []
	for _ in range(k):
		queries.append(input().split())
	sol(arr, queries)


import sys

def rall():
	return [x.strip() for x in sys.stdin.readlines()]

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something=''):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')
NT = int(rl())
for ti in range(NT):
	_ = rl()
	(n, k) = map(int, rl().split(' '))
	route = list(map(int, rl().split(' ')))
	S = set(route)
	rloc = {p: [] for p in S}
	for (i, p) in enumerate(route):
		rloc[p].append(i)
	for _ in range(k):
		(s, e) = map(int, rl().split(' '))
		if s in S:
			if e in S:
				pr('YES' if rloc[s][0] < rloc[e][-1] else 'NO')
			else:
				pr('NO')
		else:
			pr('NO')


cases = int(input())
for _ in range(cases):
	input()
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	stations = input().split(' ')
	queries = []
	for _ in range(k):
		queries.append(input().split(' '))
	station_index = {}
	for i in range(len(stations)):
		current_station = stations[i]
		if current_station not in station_index:
			station_index[current_station] = [i, i]
		else:
			current_value = station_index[current_station]
			station_index[current_station] = [current_value[0], i]
	for i in range(len(queries)):
		(aj, bj) = queries[i]
		if aj not in station_index or bj not in station_index:
			print('NO')
		elif station_index[aj][0] < station_index[bj][1]:
			print('YES')
		else:
			print('NO')


t = int(input())
while t:
	empty = input()
	(n, k) = [int(x) for x in input().split()]
	routes = list(input().split())
	routesDic = {}
	for i in range(len(routes)):
		if routes[i] in routesDic:
			routesDic[routes[i]][1] = i
		else:
			routesDic[routes[i]] = [i, i]
	queries = []
	while k:
		query = [int(x) for x in input().split()]
		queries += query
		k -= 1
	for i in range(0, len(queries), 2):
		left = str(queries[i])
		right = str(queries[i + 1])
		if left in routesDic and right in routesDic and (routesDic[left][0] <= routesDic[right][1]):
			print('YES')
		else:
			print('NO')
	t -= 1


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import defaultdict
for _ in range(int(input())):
	input()
	(N, K) = map(int, input().split())
	U = [i for i in input().split()]
	rnk = defaultdict(lambda : [float('inf'), -1], {})
	for (i, u) in enumerate(U):
		rnk[u][0] = min(rnk[u][0], i)
		rnk[u][1] = max(rnk[u][1], i)
	for i in range(K):
		(a, b) = input().split()
		if rnk[a][0] < rnk[b][1]:
			print('YES')
		else:
			print('NO')


import sys
from bisect import bisect_left, bisect_right
T = int(sys.stdin.readline())
for t in range(T):
	empty = sys.stdin.readline()
	(n, k) = map(int, sys.stdin.readline().split())
	u = list(map(int, sys.stdin.readline().split()))
	stations = [(station, idx) for (idx, station) in enumerate(u)]
	stations.sort(key=lambda x: (x[0], x[1]))
	(stations, idxes) = ([station for (station, idx) in stations], [idx for (station, idx) in stations])
	check = set(u)
	for _ in range(k):
		(a, b) = map(int, sys.stdin.readline().split())
		if a not in check or b not in check:
			print('NO')
			continue
		left_a = bisect_left(stations, a)
		right_b = bisect_right(stations, b) - 1
		if idxes[left_a] < idxes[right_b]:
			print('YES')
		else:
			print('NO')


def res():
	for x in range(int(input())):
		input()
		(n, k) = map(int, input().split())
		a = input().split()
		m1 = {}
		m2 = {}
		for (i, j) in enumerate(a):
			if j not in m1:
				m1[j] = i
			m2[j] = i
		for i in range(k):
			(a, b) = input().split()
			if a in m1 and b in m2 and (m1[a] < m2[b]):
				print('YES')
			else:
				print('NO')
res()


def solve(q, nodes):
	first_index = {}
	last_index = {}
	for (i, n) in enumerate(nodes):
		if n not in first_index:
			first_index[n] = i
		last_index[n] = i
	for _ in range(q):
		(start, end) = input().split()
		if start not in first_index or end not in last_index:
			print('NO')
		elif first_index[start] <= last_index[end]:
			print('YES')
		else:
			print('NO')
t = int(input())
for _ in range(t):
	input()
	(n, q) = map(int, input().split())
	nodes = input().split()
	solve(q, nodes)


for t in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	a = input().split()
	(d1, d2) = ({}, {})
	for (i, j) in enumerate(a):
		if not j in d1:
			d1[j] = i
		d2[j] = i
	for i in range(k):
		(x, y) = input().split()
		if x in d1 and y in d2 and (d1[x] < d2[y]):
			print('YES')
		else:
			print('NO')


def main():
	t = int(input())
	ans = []
	for _ in range(t):
		input()
		(n, k) = map(int, input().split())
		nums = list(input().split())
		d = {}
		for i in range(n):
			x = nums[i]
			if x in d.keys():
				d[x] = (d[x][0], i)
			else:
				d[x] = (i, i)
		for _ in range(k):
			(a, b) = input().split()
			if a in d.keys() and b in d.keys():
				if d[a][0] < d[b][1]:
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
main()


for _ in range(int(input())):
	__ = input()
	(n, k) = map(int, input().split())
	u = input().split()
	f = {}
	b = {}
	for (i, x) in enumerate(u):
		if x not in f:
			f[x] = i
		b[x] = i
	for __ in range(k):
		(x, y) = input().split()
		if x in f and y in b and (b[y] > f[x]):
			print('YES')
		else:
			print('NO')


for x in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	ar = input().split()
	m1 = {}
	m2 = {}
	y = 'YES'
	no = 'NO'
	for (i, j) in enumerate(ar):
		if j not in m1:
			m1[j] = i
		m2[j] = i
	for i in range(k):
		(a, b) = input().split()
		if a in m1 and b in m2 and (m1[a] < m2[b]):
			print(y)
		else:
			print(no)


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = input().split()
	first = {}
	second = {}
	for i in range(len(u)):
		if u[i] not in first:
			first[u[i]] = i
		second[u[i]] = i
	for i in range(k):
		(a, b) = input().split()
		if a in first and b in second and (second[b] > first[a]):
			print('YES')
		else:
			print('NO')


nt = int(input())
for _ in range(nt):
	input()
	(n, k) = map(int, input().split())
	(idx_first, idx_last) = ({}, {})
	for (i, e) in enumerate(input().split()):
		if e not in idx_first:
			idx_first[e] = i
		idx_last[e] = i
	for _ in range(k):
		(a, b) = input().split()
		print('YES' if idx_first.get(a, n) <= idx_last.get(b, -1) else 'NO')


tc = int(input())
for _ in range(tc):
	empty = input()
	(n, k) = map(int, input().split())
	lis = input().split()
	prev = {}
	after = {}
	for (i, j) in enumerate(lis):
		if j not in prev:
			prev[j] = i
		after[j] = i
	for _ in range(k):
		(aj, bj) = input().split()
		if aj in prev and bj in after and (prev[aj] < after[bj]):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = input().split()
	front = {}
	back = {}
	for (i, x) in enumerate(u):
		if x not in front:
			front[x] = i
		back[x] = i
	for i in range(k):
		(a, b) = input().split()
		if a in front and b in back and (front[a] < back[b]):
			print('YES')
		else:
			print('NO')


def read_int() -> int:
	return int(input().strip())

def read_ints_map() -> map:
	return map(int, input().strip().split())

def read_ints_list() -> [int]:
	return [*read_ints_map()]
try:
	fin = open('./input.txt')
	import sys
	sys.stdin = fin
except:
	pass
t = read_int()
for _ in range(t):
	input()
	(n, k) = read_ints_list()
	first = dict()
	last = dict()
	for (i, u) in enumerate(input().split()):
		if u not in first:
			first[u] = i
		last[u] = i
	for _ in range(k):
		(a, b) = input().split()
		if a in first and b in last and (first[a] < last[b]):
			print('YES')
		else:
			print('NO')


def main():
	q = int(input())
	while q > 0:
		_ = input()
		(n, t) = map(int, input().split())
		a = input().split()
		d = {}
		for i in range(n):
			if a[i] not in d:
				d[a[i]] = [i, i]
			else:
				d[a[i]][-1] = i
		while t > 0:
			(u, v) = input().split()
			if u in d and v in d:
				x = d[u][0]
				y = d[v][-1]
				if x < y:
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
			t -= 1
		q -= 1
main()


for t in range(int(input())):
	s = input()
	(n, k) = map(int, input().split())
	arr = input().split()
	dic = {}
	for (i, j) in enumerate(arr):
		if j in dic:
			dic[j][1] = i
		else:
			dic[j] = [i, i]
	for i in range(k):
		(a, b) = input().split()
		if a in dic and b in dic and (dic[a][0] <= dic[b][1]):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = list(map(int, input().split()))
	arr = list(input().split())[:n]
	aIndex = {}
	bIndex = {}
	for (i, x) in enumerate(arr[:]):
		if x not in aIndex:
			aIndex[x] = i
		bIndex[x] = i
	for j in range(k):
		(p, q) = list(input().split())
		if p in aIndex and q in bIndex and (aIndex[p] < bIndex[q]):
			print('YES')
		else:
			print('NO')


from collections import defaultdict
for _ in range(int(input())):
	p = input()
	(n, k) = map(int, input().split())
	lis = input().split()
	(one, two) = (dict(), dict())
	for (i, j) in enumerate(lis):
		if j not in one:
			one[j] = i
		two[j] = i
	for i in range(k):
		(a, b) = input().split()
		if a in one and b in two:
			if one[a] < two[b]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	data = input().split()
	first = {}
	second = {}
	for (i, j) in enumerate(data):
		if j not in first:
			first[j] = i
		second[j] = i
	for _ in range(m):
		(a, b) = input().split()
		if a in first and b in second and (first[a] < second[b]):
			print('YES')
		else:
			print('NO')


for t in range(int(input())):
	input()
	(m, q) = map(int, input().split())
	s = [*input().split()]
	k = {}
	l = {}
	for (i, j) in enumerate(s):
		if j not in k:
			k[j] = i
		l[j] = i
	for i in range(q):
		(x, y) = input().split()
		print('YES' if x in k and y in l and (k[x] < l[y]) else 'NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = input().split()
	first_d = {}
	second_d = {}
	for i in range(n):
		if u[i] not in first_d:
			first_d[u[i]] = i
		second_d[u[i]] = i
	for i in range(k):
		(a, b) = input().split()
		if a in first_d and b in second_d and (first_d[a] < second_d[b]):
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = input().split()
	d = {}
	a = {}
	for i in range(n):
		if u[i] not in d:
			d[u[i]] = i
		a[u[i]] = i
	for i in range(k):
		(x, y) = input().split()
		if x in d and y in a and (a[y] > d[x]):
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	e = input()
	(n, k) = map(int, input().split())
	a = input().split()
	d = dict()
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = [i, i]
		else:
			d[a[i]][1] = i
	for _ in range(k):
		(ai, bi) = input().split()
		if ai not in d or bi not in d:
			print('NO')
			continue
		if d[ai][0] < d[bi][1]:
			print('YES')
		else:
			print('NO')


T = int(input())
for test in range(T):
	input()
	(n, k) = [int(a) for a in input().split()]
	u = input().split()
	dict_first = {}
	dict_last = {}
	for (i, x) in enumerate(u):
		if x not in dict_first:
			dict_first[x] = i
		dict_last[x] = i
	for i in range(k):
		(x, y) = input().split()
		if x in dict_first and y in dict_last and (dict_first[x] < dict_last[y]):
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	s = input()
	(n, m) = list(map(int, input().split()))
	ar = list(input().split())
	ans1 = {}
	ans2 = {}
	for (i, j) in enumerate(ar[:]):
		if j not in ans1:
			ans1[j] = i
		ans2[j] = i
	for i in range(m):
		(a, b) = list(input().split())
		if a in ans1 and b in ans2 and (ans1[a] < ans2[b]):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	u = dict()
	for (i, j) in enumerate(input().split()):
		if j not in u:
			u[j] = (i, i)
		else:
			u[j] = (u[j][0], i)
	for i in range(k):
		(a, b) = input().split()
		u1 = u.get(a, -1)
		u2 = u.get(b, -1)
		if u1 == -1 or u2 == -1 or u1[0] > u2[1]:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	ig = input()
	(n, k) = map(int, input().split())
	arr = list(input().split())
	mi = {}
	ma = {}
	for (i, l) in enumerate(arr):
		if l not in mi:
			mi[l] = i
		ma[l] = i
	for o in range(k):
		(a, b) = input().split()
		if a in mi and b in ma and (mi[a] < ma[b]):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	a = input().split()
	b = {}
	for i in range(n):
		if a[i] in b:
			b[a[i]][1] = i
		else:
			b[a[i]] = [i, i]
	for _ in range(k):
		(x, y) = input().split()
		if y in b and x in b and (b[x][0] < b[y][1]):
			print('YES')
		else:
			print('NO')


import os
import sys
if os.path.exists('tests'):
	sys.stdin = open('tests', 'r')
T = int(input())
for _ in range(T):
	input()
	(n_stations, n_queries) = [int(c) for c in input().split()]
	stations = input().split()
	station_to_first_i = {stations[i]: i for i in range(n_stations - 1, -1, -1)}
	station_to_last_i = {stations[i]: i for i in range(n_stations)}
	for _ in range(n_queries):
		(a, b) = input().split()
		if a not in station_to_first_i or b not in station_to_last_i:
			print('NO')
		elif station_to_first_i[a] < station_to_last_i[b]:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	umin = dict()
	umax = dict()
	for (i, j) in enumerate(input().split()):
		try:
			umin[j]
			umax[j] = i
		except Exception:
			umin[j] = i
			umax[j] = i
	for i in range(k):
		(a, b) = input().split()
		try:
			u1 = umin[a]
			u2 = umax[b]
			if u1 < u2:
				print('YES')
			else:
				print('NO')
		except Exception:
			print('NO')


for _ in range(int(input())):
	e = input()
	(station_no, queries) = list(map(int, input().split()))
	ar = list(input().split())[:station_no]
	ans1 = {}
	ans2 = {}
	for (i, j) in enumerate(ar[:]):
		if j not in ans1:
			ans1[j] = i
		ans2[j] = i
	for i in range(queries):
		(a, b) = list(input().split())
		if a in ans1 and b in ans2 and (ans1[a] < ans2[b]):
			print('YES')
		else:
			print('NO')


from collections import defaultdict
x = int(input())
for _ in range(x):
	input()
	(n, k) = map(int, input().split())
	arr = input().split()
	first = defaultdict(lambda : float('inf'))
	last = defaultdict(lambda : -1)
	for i in range(len(arr)):
		if arr[i] not in first:
			first[arr[i]] = i
		last[arr[i]] = i
	queries = []
	for _ in range(k):
		(a, b) = input().split()
		if first[a] <= last[b]:
			print('YES')
		else:
			print('NO')


from collections import defaultdict

def test(t1, t2, map):
	if t1 not in map or t2 not in map:
		return 'NO'
	arr1 = map[t1]
	arr2 = map[t2]
	if arr1[0] > arr2[-1]:
		return 'NO'
	else:
		return 'YES'
for _ in range(int(input())):
	input()
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	map = defaultdict(list)
	terminals = input().split(' ')
	for i in range(len(terminals)):
		map[terminals[i]].append(i)
	for _ in range(k):
		(s1, s2) = input().split(' ')
		print(test(s1, s2, map))


for i in range(int(input())):
	input()
	(n, k) = input().split()
	u = list(input().split())
	d = {}
	for j in range(int(n)):
		if u[j] in d:
			d[u[j]].append(j)
		else:
			d[u[j]] = [j]
	for l in range(int(k)):
		(a, b) = input().split()
		if a in d and b in d and (d[a][0] < d[b][-1]):
			print('YES')
		else:
			print('NO')


t = int(input())
while t > 0:
	_ = input()
	(n, k) = map(int, input().split())
	Dicta = {}
	Dictb = {}
	for (i, u) in enumerate(input().split()):
		if u not in Dicta:
			Dicta[u] = i
		Dictb[u] = i
	for i in range(k):
		(a, b) = input().split()
		if a not in Dicta or b not in Dictb or Dicta[a] > Dictb[b]:
			print('NO')
		else:
			print('YES')
	t -= 1


from collections import defaultdict
t = int(input())
while t:
	input()
	(n, k) = map(int, input().split())
	lst = input().split()
	first = defaultdict(lambda : float('inf'))
	last = defaultdict(lambda : -1)
	for i in range(len(lst)):
		if lst[i] not in first:
			first[lst[i]] = i
		last[lst[i]] = i
	for _ in range(k):
		(a, b) = input().split()
		if first[a] <= last[b]:
			print('YES')
		else:
			print('NO')
	t -= 1


from collections import defaultdict
t = int(input())
while t:
	input()
	(n, k) = map(int, input().split())
	l = input().split()
	f = defaultdict(lambda : float('inf'))
	ld = defaultdict(lambda : -1)
	for i in range(n):
		if l[i] not in f:
			f[l[i]] = i
		ld[l[i]] = i
	for i in range(k):
		(a, b) = input().split()
		if f[a] < ld[b]:
			print('YES')
		else:
			print('NO')
	t -= 1


import sys, math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_ls():
	return list(map(int, sys.stdin.readline().strip().split()))

def main():
	for _ in range(int(input())):
		input()
		(n, k) = map(int, input().split())
		ls = input().split()
		mp1 = {}
		mp2 = {}
		for (i, v) in enumerate(ls):
			if v not in mp1:
				mp1[v] = i
			mp2[v] = i
		for i in range(k):
			(a, b) = input().split()
			if a in mp1 and b in mp2 and (mp1[a] < mp2[b]):
				print('YES')
			else:
				print('NO')
main()


for trials in range(int(input())):
	whatever = input()
	(n, k) = input().split()
	nbr = list(input().split())
	d = {}
	for i in range(len(nbr)):
		if nbr[i] in d:
			d[nbr[i]].append(i)
		else:
			d[nbr[i]] = [i]
	for queries in range(int(k)):
		(a, b) = input().split()
		try:
			if d[a][0] < d[b][-1]:
				print('YES')
			else:
				print('NO')
		except:
			print('NO')


for _ in range(int(input())):
	input()
	(n, k) = map(int, input().split())
	lst = list(input().split())
	stations_dictionary = {}
	counter = 0
	for s in lst:
		if s not in stations_dictionary:
			stations_dictionary[s] = [counter]
		else:
			stations_dictionary[s].append(counter)
		counter += 1
	for i in range(k):
		(a, b) = input().split()
		if stations_dictionary.get(a) is None or stations_dictionary.get(b) is None:
			print('NO')
		elif stations_dictionary[a][0] < stations_dictionary[b][-1]:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	empty = input()
	data = input().split(' ')
	data[0] = int(data[0])
	data[1] = int(data[1])
	arr = input().split(' ')
	record = {}
	for j in range(data[0]):
		if arr[j] not in record:
			record[arr[j]] = [j]
		else:
			record[arr[j]].append(j)
	for k in range(data[1]):
		route = input().split()
		if route[0] not in record or route[1] not in record:
			print('NO')
		elif record[route[0]][0] < record[route[1]][-1]:
			print('YES')
		else:
			print('NO')


t = int(input())
for i1 in range(t):
	empty_stroke = input()
	while empty_stroke == '':
		empty_stroke = input()
	(n, k) = map(int, empty_stroke.split())
	v = input().split()
	d = {}
	for i in range(len(v)):
		if v[i] not in d:
			d[v[i]] = []
		d[v[i]].append(i)
	for i in range(k):
		(a, b) = input().split()
		if a in d and b in d:
			if d[a][0] < d[b][-1]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


from collections import defaultdict
x = int(input())
for jj in range(x):
	emp = input()
	(n, k) = [int(i) for i in input().split(' ')]
	dic = defaultdict(list)
	for (i, v) in enumerate(input().split(' ')):
		dic[v].append(i)
	for i in range(k):
		(a, b) = input().split(' ')
		if a not in dic or b not in dic:
			print('NO')
		elif dic[a][0] < dic[b][-1]:
			print('YES')
		else:
			print('NO')