Jonas asked Martha to stand at point $(x_{1},y_{1})$ on an infinite cartesian plane. He gave her a string $S$ which consists of operations in the form of characters 'R', 'L', 'U', and 
'D'.

Each character of the string corresponds to the following movements: 

'R' means moving right by $1$ unit i.e, $(x,y)$ to $(x+1,y)$.
'L' means moving left by $1$ unit i.e, $(x,y)$ to $(x-1,y)$.
'U' means moving up by $1$ unit i.e, $(x,y)$ to $(x,y+1)$.
'D' means moving down by $1$ unit i.e, $(x,y)$ to $(x,y-1)$.

Now, Jonas asks Martha $Q$ queries. In each query, coordinates are given of form $(x_{2},y_{2})$. Martha needs to tell if it is possible to move from $(x_{1},y_{1})$ to $(x_{2},y_{2})$ by choosing a subsequence of given string $S$ and performing the operations in sequential order.Starting point $(x_{1},y_{1})$ remains same for all queries.

If it is possible, print "YES" and the length of the smallest possible subsequence of string, else print "NO".

Recall that string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly zero or all) characters. For example, for the string $a$="codechef", the following strings are subsequences: "code", "ee", "odchef", "df", "", and others, but the following are not subsequences: "ced", "eehc", "cofe".

Note: Use of Fast IO is recommended.

------ Input: ------

First line will contain $T$, number of test cases. Then test cases follow.
For each test case, first line will contain string $S$, string of operations.
Second line will contain coordinates $x_{1}$ and $y_{1}$.
Third line will contain $Q$, number of queries.
$Q$ lines follow. Each line will contain coordinates $x_{2}$ and $y_{2}$.

------ Output: ------
For each query if subsequence exists then print "YES" (without quotes) and length of smallest possible subsequence separated by a space in new line, else print "NO" (without quotes) in new line.

------ Constraints  ------
$1 ≤ T ≤ 10$
$1 ≤ |S| ≤ 10^{6}$
$-10^{8} ≤ x_{1},x_{2},y_{1},y_{2} ≤ 10^{8}$
$1 ≤ Q ≤ 10^{5}$

----- Sample Input 1 ------ 
1
RLUDRLUD
1 2
2
2 3
1 -2
----- Sample Output 1 ------ 
YES 2
NO
----- explanation 1 ------ 
Given String is "RLUDRLUD", $(x_{1},y_{1})$ is $(1,2)$. We can move from $(1,2)$ to $(2,3)$ in just two operations if we choose subsequence as "RU" or "UR".

Suppose we choose "RU" as a subsequence. 'R' means moving from $(1,2)$ to $(2,2)$. 'U' means moving from $(2,2)$ to $(2,3)$.

In the second query, we can't move from (1,2) to (1,-2) using operations of the given string.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Geometry

String algorithms

Combinatorics

Mathematics

Data structures


Solutions:
from collections import defaultdict
import sys
for q in range(int(sys.stdin.readline())):
	s = sys.stdin.readline()
	(x1, y1) = map(int, sys.stdin.readline().split())
	Q = int(sys.stdin.readline())
	dict = defaultdict(int)
	for i in s:
		dict[i] += 1
	for _ in range(Q):
		(x2, y2) = map(int, sys.stdin.readline().split())
		c = 0
		f = 0
		if x2 - x1 >= 0:
			if dict['R'] >= x2 - x1:
				c += x2 - x1
			else:
				f = 1
		elif dict['L'] >= x1 - x2:
			c += x1 - x2
		else:
			f = 1
		if y2 - y1 > 0:
			if dict['U'] >= y2 - y1:
				c += y2 - y1
			else:
				f = 1
		elif dict['D'] >= y1 - y2:
			c += y1 - y2
		else:
			f = 1
		if f == 1:
			sys.stdout.write('NO')
		else:
			sys.stdout.write('YES' + ' ' + str(c))
		sys.stdout.write('\n')


for _ in range(int(input())):
	s = input()
	(x1, y1) = map(int, input().split())
	q = int(input())
	n = len(s)
	cords = [list(map(int, input().split())) for i in range(q)]
	(posx, negx) = (0, 0)
	(posy, negy) = (0, 0)
	for e in s:
		posx = posx + 1 if e == 'R' else posx + 0
		negx = negx + 1 if e == 'L' else negx + 0
		posy = posy + 1 if e == 'U' else posy + 0
		negy = negy + 1 if e == 'D' else negy + 0
	for ele in cords:
		(x2, y2) = ele
		(diffx, diffy) = (x2 - x1, y2 - y1)
		if -negx <= diffx <= posx and -negy <= diffy <= posy:
			print('YES', abs(diffx) + abs(diffy))
		else:
			print('NO')


import sys
from collections import defaultdict
for _ in range(int(input())):
	s = sys.stdin.readline()
	(x, y) = map(int, sys.stdin.readline().strip().split())
	q = int(sys.stdin.readline())
	dict = defaultdict(int)
	for i in s:
		dict[i] += 1
	for i in range(q):
		(a, b) = map(int, sys.stdin.readline().strip().split())
		f = 0
		c = 0
		if a - x >= 0:
			if dict['R'] >= a - x:
				c += a - x
			else:
				f = 1
		elif dict['L'] >= x - a:
			c += x - a
		else:
			f = 1
		if b - y >= 0:
			if dict['U'] >= b - y:
				c += b - y
			else:
				f = 1
		elif dict['D'] >= y - b:
			c += y - b
		else:
			f = 1
		if f == 0:
			sys.stdout.write('YES' + ' ' + str(c))
		else:
			sys.stdout.write('NO')
		sys.stdout.write('\n')


t = int(input())
ans = []
while t != 0:
	s = input()
	(X, Y) = input().split()
	l = s.count('L')
	r = s.count('R')
	d = s.count('D')
	u = s.count('U')
	x = int(X)
	y = int(Y)
	q = int(input())
	while q != 0:
		(A, B) = input().split()
		a = int(A)
		b = int(B)
		if x > a:
			d1 = x - a
		else:
			d1 = a - x
		if y > b:
			d2 = y - b
		else:
			d2 = b - y
		if a > x:
			if b > y:
				if d1 <= r and d2 <= u:
					ans.append('YES ' + str(d1 + d2))
				else:
					ans.append('NO')
			elif d1 <= r and d2 <= d:
				ans.append('YES ' + str(d1 + d2))
			else:
				ans.append('NO')
		elif b > y:
			if d1 <= l and d2 <= u:
				ans.append('YES ' + str(d1 + d2))
			else:
				ans.append('NO')
		elif d1 <= l and d2 <= d:
			ans.append('YES ' + str(d1 + d2))
		else:
			ans.append('NO')
		q = q - 1
	t = t - 1
for i in ans:
	print(i)


import sys
for _ in range(int(sys.stdin.readline().strip())):
	s = input()
	r_count = 0
	l_count = 0
	u_count = 0
	d_count = 0
	for i in range(len(s)):
		if s[i] == 'R':
			r_count += 1
		if s[i] == 'L':
			l_count += 1
		if s[i] == 'U':
			u_count += 1
		if s[i] == 'D':
			d_count += 1
	(x1, y1) = map(int, sys.stdin.readline().strip().split())
	for j in range(int(sys.stdin.readline().strip())):
		(x2, y2) = map(int, sys.stdin.readline().strip().split())
		first = x2 - x1
		second = y2 - y1
		flag = False
		if first > 0 and r_count < first:
			flag = True
		if first < 0 and l_count < abs(first):
			flag = True
		if second > 0 and u_count < second:
			flag = True
		if second < 0 and d_count < abs(second):
			flag = True
		if flag:
			print('NO')
		else:
			print('YES', ' ', abs(first) + abs(second))


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

def string_list():
	return list(map(str, input().split()))

def hetro_list():
	return list(input().split())
t = int(input())
for _ in range(t):
	s = input()
	(x, y) = integer_list()
	q = int(input())
	n = len(s)
	lst = [integer_list() for i in range(q)]
	(pos_x, neg_x) = (0, 0)
	(pos_y, neg_y) = (0, 0)
	for ele in s:
		pos_x = pos_x + 1 if ele == 'R' else pos_x + 0
		neg_x = neg_x + 1 if ele == 'L' else neg_x + 0
		pos_y = pos_y + 1 if ele == 'U' else pos_y + 0
		neg_y = neg_y + 1 if ele == 'D' else neg_y + 0
	for ele in lst:
		(x1, y1) = ele
		(diff_x, diff_y) = (x1 - x, y1 - y)
		if -neg_x <= diff_x <= pos_x and -neg_y <= diff_y <= pos_y:
			print('YES', abs(diff_x) + abs(diff_y))
		else:
			print('NO')


def call(up, right, down, left, start, dest):
	ans = 0
	x = dest[0] - start[0]
	y = dest[1] - start[1]
	if x == 0 and y == 0:
		return ['YES', 0]
	if x > 0:
		if x > right:
			return ['NO']
		else:
			ans += x
	if x < 0:
		if abs(x) > left:
			return ['NO']
		else:
			ans += abs(x)
	if y > 0:
		if y > up:
			return ['NO']
		else:
			ans += y
	if y < 0:
		if abs(y) > down:
			return ['NO']
		else:
			ans += abs(y)
	return ['YES', ans]
t = int(input())
while t > 0:
	string = input()
	start = list(map(int, input().split()))
	q = int(input())
	destinations = []
	for _ in range(q):
		destinations.append(list(map(int, input().split())))
	(up, left, right, down) = (0, 0, 0, 0)
	for s in string:
		if s == 'L':
			left += 1
		elif s == 'R':
			right += 1
		elif s == 'U':
			up += 1
		else:
			down += 1
	for dest in destinations:
		sol = call(up, right, down, left, start, dest)
		if len(sol) == 1:
			print(sol[0])
		else:
			print(sol[0], sol[1])
	t -= 1


import os.path
import sys
from math import *
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	s = inp()
	(totl, totr, totu, totd) = [0] * 4
	for i in s:
		if i == 'L':
			totl += 1
		elif i == 'R':
			totr += 1
		elif i == 'U':
			totu += 1
		else:
			totd += 1
	(x1, y1) = map(int, inp().split())
	q = int(inp())
	for j in range(0, q):
		flag = 0
		(x2, y2) = map(int, inp().split())
		dx = x2 - x1
		dy = y2 - y1
		if x2 > x1 and totr < abs(dx):
			flag = 1
		if y2 > y1 and totu < abs(dy):
			flag = 1
		if y1 > y2 and totd < abs(dy):
			flag = 1
		if x1 > x2 and totl < abs(dx):
			flag = 1
		if flag == 1:
			print('NO')
		else:
			print('YES', end=' ')
			print(abs(dx) + abs(dy))


for _ in range(int(input())):
	s = input()
	(x1, y1) = map(int, input().split())
	n = int(input())
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in s:
		d[i] += 1
	l = list()
	for i in range(n):
		l.append(list(map(int, input().split())))
	for i in l:
		x_diff = i[0] - x1
		y_diff = i[1] - y1
		if x_diff <= 0 and y_diff <= 0:
			if abs(x_diff) <= d['L'] and abs(y_diff) <= d['D']:
				print('YES', abs(x_diff) + abs(y_diff))
			else:
				print('NO')
		elif x_diff <= 0 and y_diff >= 0:
			if abs(x_diff) <= d['L'] and abs(y_diff) <= d['U']:
				print('YES', abs(x_diff) + abs(y_diff))
			else:
				print('NO')
		elif x_diff >= 0 and y_diff <= 0:
			if abs(x_diff) <= d['R'] and abs(y_diff) <= d['D']:
				print('YES', abs(x_diff) + abs(y_diff))
			else:
				print('NO')
		elif abs(x_diff) <= d['R'] and abs(y_diff) <= d['U']:
			print('YES', abs(x_diff) + abs(y_diff))
		else:
			print('NO')


T = int(input())
ans = []
for _ in range(T):
	S = input()
	(x1, y1) = [int(i) for i in input().split()]
	Q = int(input())
	D = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for i in S:
		D[i] = D.get(i, 0) + 1
	for i in range(Q):
		(x2, y2) = [int(i) for i in input().split()]
		x = x2 - x1
		y = y2 - y1
		r = 0
		l = 0
		u = 0
		d = 0
		if x > 0:
			r = x
		else:
			l = abs(x)
		if y > 0:
			u = y
		else:
			d = abs(y)
		if D['R'] >= r and D['L'] >= l and (D['U'] >= u) and (D['D'] >= d):
			ans.append('YES {}'.format(r + l + u + d))
		else:
			ans.append('NO')
for i in ans:
	print(i)


import collections
test = int(input())
for _ in range(test):
	s = input()
	(a, b) = map(int, input().split())
	n = int(input())
	queries = []
	for i in range(n):
		(x, y) = map(int, input().split())
		queries.append((x - a, y - b))
	C = collections.Counter(s)
	for q in queries:
		flag = True
		if q[0] < 0:
			xx = -q[0]
			if xx > C['L']:
				flag = False
		else:
			xx = q[0]
			if xx > C['R']:
				flag = False
		if q[1] < 0:
			yy = -q[1]
			if yy > C['D']:
				flag = False
		else:
			yy = q[1]
			if yy > C['U']:
				flag = False
		if flag == True:
			print('YES', abs(q[0]) + abs(q[1]))
		else:
			print('NO')


import collections
t = int(input())
for i in range(t):
	s = str(input())
	(x1, y1) = map(int, input().split())
	q = int(input())
	queries = []
	for i in range(q):
		(x2, y2) = map(int, input().split())
		queries.append((x2 - x1, y2 - y1))
	C = collections.Counter(s)
	for q in queries:
		(x, y) = (q[0], q[1])
		flag = True
		if x < 0:
			xx = -x
			if xx > C['L']:
				flag = False
		else:
			xx = x
			if xx > C['R']:
				flag = False
		if y < 0:
			yy = -y
			if yy > C['D']:
				flag = False
		else:
			yy = y
			if yy > C['U']:
				flag = False
		if flag == True:
			print('YES', abs(x) + abs(y))
		else:
			print('NO')


import sys
from collections import defaultdict
for _ in range(int(input())):
	S = sys.stdin.readline()
	h = defaultdict(int)
	for i in S:
		h[i] += 1
	(x1, y1) = map(int, sys.stdin.readline().strip().split())
	for _ in range(int(input())):
		(x2, y2) = map(int, sys.stdin.readline().strip().split())
		dx = x2 - x1
		dy = y2 - y1
		flag_x = False
		flag_y = False
		if dy > 0:
			if h['U'] >= dy:
				flag_y = True
		elif dy < 0:
			if h['D'] >= abs(dy):
				flag_y = True
		else:
			flag_y = True
		if dx > 0:
			if h['R'] >= dx:
				flag_x = True
		elif dx < 0:
			if h['L'] >= abs(dx):
				flag_x = True
		else:
			flag_x = True
		if flag_x and flag_y:
			print(f'YES {abs(dx) + abs(dy)}')
		else:
			print('NO')


import sys
for _ in range(int(sys.stdin.readline().strip())):
	s = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	(x, y) = map(int, sys.stdin.readline().strip().split())
	for t in range(int(sys.stdin.readline().strip())):
		(xx, yy) = map(int, sys.stdin.readline().strip().split())
		dx = xx - x
		dy = yy - y
		ans = True
		if dx < 0 and l < abs(dx):
			ans = False
		if dx > 0 and r < dx:
			ans = False
		if dy < 0 and d < abs(dy):
			ans = False
		if dy > 0 and u < dy:
			ans = False
		if ans:
			print('YES', str(abs(dx) + abs(dy)))
		else:
			print('NO')


T = int(input())
import sys
while T != 0:
	S = sys.stdin.readline().strip()
	p = list(map(int, sys.stdin.readline().strip().split()))[:2]
	(x1, y1) = (p[0], p[1])
	SHash = [0] * 4
	for i in S:
		if i == 'L':
			SHash[0] += 1
		elif i == 'R':
			SHash[1] += 1
		elif i == 'U':
			SHash[2] += 1
		else:
			SHash[3] += 1
	Q = int(input())
	while Q != 0:
		(hor, ver, ans) = (False, False, 0)
		p = list(map(int, sys.stdin.readline().strip().split()))[:2]
		(x2, y2) = (p[0], p[1])
		LR = x2 - x1
		if LR < 0:
			if SHash[0] >= x1 - x2:
				hor = True
				ans += x1 - x2
		elif SHash[1] >= LR:
			hor = True
			ans += LR
		UD = y2 - y1
		if UD < 0:
			if SHash[3] >= y1 - y2:
				ver = True
				ans += y1 - y2
		elif SHash[2] >= UD:
			ver = True
			ans += UD
		if LR == 0:
			hor = True
		if UD == 0:
			ver = True
		if ver and hor:
			print('YES ' + str(ans))
		else:
			print('NO')
		Q -= 1
	T -= 1


from functools import lru_cache
import sys
try:
	from cp import input
except:

	def input():
		return sys.stdin.readline()
try:
	import numpy as np
except:
	pass
import math
import copy
import random
from copy import deepcopy

def itarr(arr):
	return range(len(arr))

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

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

def inp():
	return int(input())
MOD = 1000000007
sys.setrecursionlimit(100000)
sys.settrace
inf_p = float('inf')
inf_n = float('-inf')

def dist(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def main():
	s = input().strip()
	(ox, oy) = mp()
	XP = s.count('R') + ox
	XN = ox - s.count('L')
	YP = s.count('U') + oy
	YN = oy - s.count('D')
	q = inp()
	for _ in range(q):
		(x, y) = mp()
		if x <= XP and x >= XN and (y >= YN) and (y <= YP):
			print(f'YES {dist(ox, oy, x, y)}')
		else:
			print('NO')
for i in range(inp()):
	main()


from collections import Counter
t = int(input())
ans = []
for _ in range(t):
	s = input()
	(x1, y1) = tuple(map(int, input().split()))
	q = int(input())
	s = Counter(s)
	for _ in range(q):
		temp = tuple(map(int, input().split()))
		dist = [x1 - temp[0], y1 - temp[1]]
		flag = 1
		if x1 < temp[0] and abs(dist[0]) > s['R']:
			flag = 0
		if x1 > temp[0] and abs(dist[0]) > s['L']:
			flag = 0
		if y1 < temp[1] and abs(dist[1]) > s['U']:
			flag = 0
		if y1 > temp[1] and abs(dist[1]) > s['D']:
			flag = 0
		tdist = abs(dist[1]) + abs(dist[0])
		if flag:
			ans.append('YES ' + str(tdist))
		else:
			ans.append('NO')
print(*ans, sep='\n')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	s = stdin.readline()
	(r, l, u, d) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'R':
			r = r + 1
		elif s[i] == 'L':
			l = l + 1
		elif s[i] == 'U':
			u = u + 1
		elif s[i] == 'D':
			d = d + 1
		else:
			pass
	(x, y) = [int(p) for p in stdin.readline().split()]
	q = int(stdin.readline())
	for i in range(q):
		(j, k) = [int(p) for p in stdin.readline().split()]
		j = j - x
		k = k - y
		if j >= 0:
			if r >= j:
				if k >= 0:
					if u >= k:
						print('YES %d' % (j + k))
					else:
						print('NO')
				elif d >= -k:
					print('YES %d' % (j - k))
				else:
					print('NO')
			else:
				print('NO')
		elif l >= -j:
			if k >= 0:
				if u >= k:
					print('YES %d' % (-j + k))
				else:
					print('NO')
			elif d >= -k:
				print('YES %d' % (-j - k))
			else:
				print('NO')
		else:
			print('NO')


import sys
import bisect
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	s = input()
	(x1, y1) = map(int, input().split())
	q = int(input())
	(l, r, u, d) = (s.count('L'), s.count('R'), s.count('U'), s.count('D'))
	(xmp, ymp) = (x1 + r, y1 + u)
	(xmn, ymn) = (x1 - l, y1 - d)
	for _ in range(q):
		(x, y) = map(int, input().split())
		if x >= xmn and y >= ymn and (x <= xmp) and (y <= ymp):
			print('YES {}'.format(abs(x - x1) + abs(y - y1)))
		else:
			print('NO')


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	s = input()
	ans = []
	(totl, totr, totu, totd) = (0, 0, 0, 0)
	for x in s:
		if x == 'L':
			totl += 1
		elif x == 'R':
			totr += 1
		elif x == 'U':
			totu += 1
		else:
			totd += 1
	(x, y) = map(int, sys.stdin.readline().strip().split())
	q = int(sys.stdin.readline().strip())
	for __ in range(q):
		flag = 0
		(l, r) = map(int, sys.stdin.readline().strip().split())
		dx = l - x
		dy = r - y
		if l < x and totl < abs(dx):
			flag = 1
		if l > x and totr < abs(dx):
			flag = 1
		if r < y and totd < abs(dy):
			flag = 1
		if r > y and totu < abs(dy):
			flag = 1
		if flag == 1:
			ans += ['NO']
		else:
			ans += ['YES ' + str(abs(dx) + abs(dy))]
	print(*ans, sep='\n')


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	s = rs()
	(x, y) = ria()
	d = defaultdict(int)
	for i in s:
		d[i] += 1
	for _ in range(ri()):
		(a, b) = ria()
		p = a - x
		q = b - y
		R = L = U = D = 0
		if p < 0:
			L = abs(p)
		else:
			R = p
		if q < 0:
			D = abs(q)
		else:
			U = q
		flag = 1
		if d['R'] < R:
			flag = 0
		if d['L'] < L:
			flag = 0
		if d['U'] < U:
			flag = 0
		if d['D'] < D:
			flag = 0
		if flag:
			print('YES', R + L + U + D)
		else:
			print('NO')


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	s = stdin.readline()
	r = l = d = u = 0
	(x1, y1) = [int(x) for x in stdin.readline().split()]
	for i in s:
		if i == 'R':
			r = r + 1
		if i == 'L':
			l = l + 1
		if i == 'D':
			d = d + 1
		if i == 'U':
			u = u + 1
	for i in range(int(stdin.readline())):
		(x2, y2) = [int(x) for x in stdin.readline().split()]
		if x2 > x1 and y2 > y1:
			a = abs(x2 - x1)
			b = abs(y2 - y1)
			if r >= a and u >= b:
				print('YES', a + b)
			else:
				print('NO')
		if x2 < x1 and y2 < y1:
			a = abs(x2 - x1)
			b = abs(y2 - y1)
			if l >= a and d >= b:
				print('YES', a + b)
			else:
				print('NO')
		if x2 > x1 and y2 < y1:
			a = x2 - x1
			b = abs(y1 - y2)
			if r >= a and d >= b:
				print('YES', a + b)
			else:
				print('NO')
		if x2 < x1 and y2 > y1:
			a = abs(x2 - x1)
			b = abs(y2 - y1)
			if l >= a and u >= b:
				print('YES', a + b)
			else:
				print('NO')
		if x1 == x2 and y1 == y2:
			print('YES', 0)
		if x1 == x2:
			if y1 > y2:
				a = abs(y1 - y2)
				if d >= a:
					print('YES', a)
				else:
					print('NO')
			if y1 < y2:
				a = abs(y2 - y1)
				if u >= a:
					print('YES', a)
				else:
					print('NO')
		if y1 == y2:
			if x1 > x2:
				a = abs(x1 - x2)
				if l >= a:
					print('YES', a)
				else:
					print('NO')
			if x1 < x2:
				a = abs(x2 - x1)
				if r >= a:
					print('YES', a)
				else:
					print('NO')


import sys
import bisect
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	s = input()
	d = {}
	for i in s:
		d[i] = d.get(i, 0) + 1
	(x1, y1) = map(int, input().split())
	q = int(input())
	for __ in range(q):
		(x2, y2) = map(int, input().split())
		dx = x2 - x1
		dy = y2 - y1
		ans = 0
		ch = 1
		if dx >= 0:
			if d.get('R', 0) >= dx:
				ans += dx
		elif d.get('L', 0) >= abs(dx):
			ans += abs(dx)
		if dy >= 0:
			if d.get('U', 0) >= dy:
				ans += dy
		elif d.get('D', 0) >= abs(dy):
			ans += abs(dy)
		if ans == abs(dx) + abs(dy):
			print('YES', ans)
		else:
			print('NO')


from sys import stdin
input = stdin.readline
from collections import Counter
for _ in range(int(input())):
	s = input()
	k = Counter(s)
	(x, y) = map(int, input().split())
	q = int(input())
	for i in range(q):
		(a, b) = map(int, input().split())
		v1 = a - x
		v2 = b - y
		if v1 >= 0:
			d = 'R'
		else:
			d = 'L'
			v1 = v1 * -1
		if v2 <= 0:
			d1 = 'D'
			v2 = v2 * -1
		else:
			d1 = 'U'
		c1 = k[d]
		c2 = k[d1]
		if c1 >= v1 and c2 >= v2:
			print('YES', v1 + v2)
		else:
			print('NO')


from sys import stdin, stdout

def martha(arr, a, b):
	i = 'R' if a < 0 else 'L'
	j = 'U' if b < 0 else 'D'
	(a, b) = (abs(a), abs(b))
	return a + b if arr[i] >= a and arr[j] >= b else -1
for t in range(int(stdin.readline())):
	d = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	strs = stdin.readline()
	for i in range(len(strs) - 1):
		d[strs[i]] += 1
	(x, y) = map(int, stdin.readline().split())
	for q in range(int(stdin.readline())):
		(a, b) = map(int, stdin.readline().split())
		ans = martha(d, x - a, y - b)
		if ans >= 0:
			print('YES ' + str(ans))
		else:
			print('NO')


from sys import stdin, stdout
I = stdin.readline
for _ in range(int(I())):
	s = list(I())
	(x1, y1) = map(int, I().split())
	dic = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for i in s:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	for i in range(int(I())):
		(x, y) = map(int, I().split())
		varx = x1 - x
		vary = y1 - y
		fl = 0
		if varx < 0:
			if dic['R'] < varx * -1:
				print('NO')
				fl = 1
		elif varx > 0:
			if dic['L'] < varx:
				print('NO')
				fl = 1
		if fl == 0:
			if vary > 0:
				if dic['D'] < vary:
					print('NO')
					fl = 1
			elif vary < 0:
				if dic['U'] < -1 * vary:
					print('NO')
					fl = 1
		if fl == 0:
			print('YES', abs(varx) + abs(vary))


import copy
from collections import Counter
from sys import stdin, stdout
t = int(stdin.readline())
while t:
	s = stdin.readline()
	(r, d, l, u) = (0, 0, 0, 0)
	for i in s:
		if i == 'R':
			r += 1
		elif i == 'L':
			l += 1
		elif i == 'D':
			d += 1
		elif i == 'U':
			u += 1
	(x1, y1) = map(int, stdin.readline().split())
	q = int(stdin.readline())
	while q:
		(rr, dd, uu, ll) = (r, d, u, l)
		(pos, pos_y) = (0, 0)
		le = 0
		k = 1
		(x2, y2) = map(int, stdin.readline().split())
		x_shift = x2 - x1
		y_shift = y2 - y1
		if x_shift == 0 and y_shift == 0:
			print('YES', 0)
		else:
			if x_shift < 0:
				pos = 1
				x_shift *= -1
			if y_shift < 0:
				pos_y = 1
				y_shift *= -1
			if x_shift and (not pos):
				if rr >= x_shift:
					le += x_shift
					rr -= x_shift
				else:
					print('NO')
					k = 0
			if x_shift and pos and k:
				if ll >= x_shift:
					le += x_shift
					ll -= x_shift
				else:
					print('NO')
					k = 0
			if y_shift and (not pos_y) and k:
				if uu >= y_shift:
					le += y_shift
					uu -= y_shift
				else:
					print('NO')
					k = 0
			if y_shift and pos_y and k:
				if dd >= y_shift:
					le += y_shift
					dd -= y_shift
				else:
					print('NO')
					k = 0
			if k:
				if rr < 0 or ll < 0 or dd < 0 or (uu < 0):
					print('NO')
					k = 0
			if k:
				print('YES', le)
		q -= 1
	t -= 1


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	s = stdin.readline().strip()
	(x, y) = list(map(int, stdin.readline().split()))
	d = {'R': 0, 'L': 0, 'D': 0, 'U': 0}
	for i in s:
		d[i] += 1
	for i in range(int(stdin.readline())):
		(a, b) = list(map(int, stdin.readline().split()))
		(p, q) = (a - x, b - y)
		(count, s) = (0, 0)
		if p > 0:
			if p <= d['R']:
				count += p
			else:
				s += 1
		elif abs(p) <= d['L']:
			count += abs(p)
		else:
			s += 1
		if q > 0:
			if q <= d['U']:
				count += q
			else:
				s += 1
		elif abs(q) <= d['D']:
			count += abs(q)
		else:
			s += 1
		if s > 0:
			print('NO')
		else:
			print('YES', count)


from sys import stdin, stdout
I = stdin.readline
for _ in range(int(I())):
	s = I()
	l = ['L', 'R', 'U', 'D']
	c = {}
	for i in l:
		c[i] = s.count(i)
	(x1, y1) = map(int, I().split())
	q = int(I())
	for i in range(q):
		(x2, y2) = map(int, I().split())
		d = {}
		if x1 - x2 >= 0:
			d['L'] = x1 - x2
		elif x1 - x2 < 0:
			d['R'] = abs(x1 - x2)
		if y1 - y2 >= 0:
			d['D'] = y1 - y2
		elif y1 - y2 < 0:
			d['U'] = abs(y1 - y2)
		test = 0
		for i in d:
			if c[i] - d[i] < 0:
				test = 1
				break
		if test == 0:
			s = 0
			for i in d:
				s = s + d[i]
			print('YES', s)
		else:
			print('NO')


for _ in range(int(input())):
	s = input()
	(x, y) = map(int, input().split())
	q = int(input())
	Q = [0] * q
	for __ in range(q):
		Q[__] = map(int, input().split())
	r = 0
	u = 0
	l = 0
	d = 0
	for i in s:
		if i == 'R':
			r += 1
		elif i == 'L':
			l += 1
		elif i == 'U':
			u += 1
		elif i == 'D':
			d += 1
	for i in range(q):
		(ex, ey) = Q[i]
		hori = ex - x
		verti = ey - y
		steps = 0
		flag = 1
		if hori > 0:
			if r >= hori:
				steps += hori
			else:
				flag = 0
		else:
			hori *= -1
			if l >= hori:
				steps += hori
			else:
				flag = 0
		if verti > 0:
			if u >= verti:
				steps += verti
			else:
				flag = 0
		else:
			verti *= -1
			if d >= verti:
				steps += verti
			else:
				flag = 0
		if flag == 0:
			print('NO')
		else:
			print('YES', steps)


from sys import stdin
for _ in range(int(stdin.readline())):
	s = stdin.readline()
	(x1, y1) = map(int, stdin.readline().split())
	q = int(stdin.readline())
	rco = s.count('R')
	uco = s.count('U')
	lco = s.count('L')
	dco = s.count('D')
	for i in range(q):
		flag = 0
		(x2, y2) = map(int, stdin.readline().split())
		x_diff = x2 - x1
		y_diff = y2 - y1
		if x_diff > 0 and rco < abs(x_diff):
			flag = 1
		if x_diff < 0 and lco < abs(x_diff):
			flag = 1
		if y_diff > 0 and uco < abs(y_diff):
			flag = 1
		if y_diff < 0 and dco < abs(y_diff):
			flag = 1
		if flag == 1:
			print('NO')
		else:
			print('YES ', abs(x_diff) + abs(y_diff))


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	s = input()
	(x1, y1) = map(int, sys.stdin.readline().strip().split())
	q = int(sys.stdin.readline().strip())
	cr = s.count('R')
	cu = s.count('U')
	cl = s.count('L')
	cd = s.count('D')
	for i in range(q):
		flag = 0
		(x2, y2) = map(int, sys.stdin.readline().strip().split())
		nx = x2 - x1
		ny = y2 - y1
		if nx > 0 and cr < abs(nx):
			flag = 1
		if nx < 0 and cl < abs(nx):
			flag = 1
		if ny > 0 and cu < abs(ny):
			flag = 1
		if ny < 0 and cd < abs(ny):
			flag = 1
		if flag == 1:
			print('NO')
		else:
			print('YES ', abs(nx) + abs(ny))