The robot is located on a checkered rectangular board of size $n \times m$ ($n$ rows, $m$ columns). The rows in the board are numbered from $1$ to $n$ from top to bottom, and the columns — from $1$ to $m$ from left to right.

The robot is able to move from the current cell to one of the four cells adjacent by side.

The sequence of commands $s$ executed by the robot is given. Each command is denoted by one of the symbols 'L', 'R', 'D' or 'U', and triggers the movement to left, right, down or up, respectively.

The robot can start its movement in any cell. The robot executes the commands starting from the first one, strictly in the order in which they are listed in $s$. If the robot moves beyond the edge of the board, it falls and breaks. A command that causes the robot to break is not considered successfully executed.

The robot's task is to execute as many commands as possible without falling off the board. For example, on board $3 \times 3$, if the robot starts a sequence of actions $s=$"RRDLUU" ("right", "right", "down", "left", "up", "up") from the central cell, the robot will perform one command, then the next command will force him to cross the edge. If the robot starts moving from the cell $(2, 1)$ (second row, first column) then all commands will be executed successfully and the robot will stop at the cell $(1, 2)$ (first row, second column).

The robot starts from cell $(2, 1)$ (second row, first column). It moves right, right, down, left, up, and up. In this case it ends in the cell $(1, 2)$ (first row, second column).

Determine the cell from which the robot should start its movement in order to execute as many commands as possible.


-----Input-----

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

The next $2t$ lines contain descriptions of the test cases.

In the description of each test case, the first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 10^6$) — the height and width of the field that the robot is located on. The second line of the description is a string $s$ consisting solely of characters 'L', 'R', 'D' and 'U' — the sequence of commands the robot executes. The string has a length from $1$ to $10^6$ commands.

It is guaranteed that the total length of $s$ over all test cases does not exceed $10^6$.


-----Output-----

Print $t$ lines, each of which contains the answer to the corresponding test case. The answer to the test case are two integers $r$ ($1 \leq r \leq n$) and $c$ ($1 \leq c \leq m$), separated by a space — the coordinates of the cell (row number and column number) from which the robot should start moving to perform as many commands as possible.

If there are several such cells, you may output any of them.


-----Examples-----

Input
4
1 1
L
1 2
L
3 3
RRDLUU
4 3
LUURRDDLLLUU
Output
1 1
1 2
2 1
3 2


-----Note-----

None

Difficulty: MEDIUM_HARD

Solutions:
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	(negx, negy) = (0, 0)
	(posx, posy) = (0, 0)
	(prevx, prevy) = (0, 0)
	(ansx, ansy) = (1, 1)
	for i in range(len(s)):
		if s[i] == 'L':
			prevx -= 1
		elif s[i] == 'R':
			prevx += 1
		elif s[i] == 'U':
			prevy -= 1
		else:
			prevy += 1
		negx = min(negx, prevx)
		negy = min(negy, prevy)
		posx = max(posx, prevx)
		posy = max(posy, prevy)
		rx = posx - negx
		ry = posy - negy
		if rx >= m or ry >= n:
			break
		ansx = 1 - negx
		ansy = 1 - negy
	print(ansy, ansx)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	way = input()
	maxiUP = 0
	maxiDOWN = 0
	maxiRIGHT = 0
	maxiLEFT = 0
	now = [0, 0]
	last = None
	over = True
	for j in way:
		last = j
		if j == 'U':
			now[0] += 1
		elif j == 'D':
			now[0] -= 1
		elif j == 'R':
			now[1] += 1
		elif j == 'L':
			now[1] -= 1
		if now[0] > maxiUP:
			maxiUP = now[0]
		elif now[0] < -maxiDOWN:
			maxiDOWN = -now[0]
		elif now[1] > maxiRIGHT:
			maxiRIGHT = now[1]
		elif now[1] < -maxiLEFT:
			maxiLEFT = -now[1]
		if maxiDOWN + maxiUP > n - 1:
			over = False
			break
		elif maxiLEFT + maxiRIGHT > m - 1:
			over = False
			break
	print(maxiUP + 1 - 1 if last == 'U' and (not over) else maxiUP + 1, maxiLEFT + 1 - 1 if last == 'L' and (not over) else maxiLEFT + 1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	r = 0
	l = 0
	u = 0
	d = 0
	rl = 0
	ud = 0
	resX = 0
	resY = 0
	for i in range(len(s)):
		if s[i] == 'R':
			rl += 1
			r = max(r, rl)
			if 1 + r + abs(l) > m:
				r -= 1
				break
		elif s[i] == 'L':
			rl -= 1
			l = min(l, rl)
			if 1 + r + abs(l) > m:
				l += 1
				break
		elif s[i] == 'U':
			ud += 1
			u = max(u, ud)
			if 1 + u + abs(d) > n:
				u -= 1
				break
		else:
			ud -= 1
			d = min(d, ud)
			if 1 + u + abs(d) > n:
				d += 1
				break
	print(u + 1, m - r)


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	sys.stderr = open('error.txt', 'w')
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda : list(minp())
minp = lambda : map(int, input().split())
from math import inf, ceil, sqrt, log2, gcd
from collections import defaultdict, deque
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for _ in range(int(input())):
	((n, m), s) = (minp(), input())
	(x, y) = (0, 0)
	l = r = d = u = 0
	(X, Y) = (1, 1)
	for c in s:
		if c == 'L':
			x -= 1
		elif c == 'R':
			x += 1
		elif c == 'U':
			y += 1
		else:
			y -= 1
		l = max(l, -x)
		r = max(r, x)
		u = max(u, y)
		d = max(d, -y)
		if l + r < m and u + d < n:
			Y = l + 1
			X = u + 1
	print(X, Y)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	S = input().strip()
	A = [[0, 0]]
	for s in S:
		(x, y) = A[-1]
		if s == 'D':
			A.append([x + 1, y])
		elif s == 'U':
			A.append([x - 1, y])
		elif s == 'R':
			A.append([x, y + 1])
		else:
			A.append([x, y - 1])
	B = [[0, 0, 0, 0]]
	for (x, y) in A[1:]:
		(a, b, c, d) = B[-1]
		a = min(a, x)
		b = max(b, x)
		c = min(c, y)
		d = max(d, y)
		B.append([a, b, c, d])
	for i in range(len(B)):
		(a, b, c, d) = B[i]
		if b - a == n or d - c == m:
			(x, y, z, w) = B[i - 1]
			print(-x + 1, -z + 1)
			break
	else:
		(x, y, z, w) = B[-1]
		print(-x + 1, -z + 1)


import sys
input = sys.stdin.readline

def solution():
	(n, m) = [int(x) for x in input().strip().split()]
	s = input().strip()
	minx = 1
	maxx = n
	miny = 1
	maxy = m
	res = ['1', '1']
	updown = 0
	leftright = 0
	for command in s:
		if command == 'U':
			updown -= 1
		if command == 'D':
			updown += 1
		if command == 'L':
			leftright -= 1
		if command == 'R':
			leftright += 1
		minx = max(minx, 1 - updown)
		maxx = min(maxx, n - updown)
		miny = max(miny, 1 - leftright)
		maxy = min(maxy, m - leftright)
		if minx > maxx or miny > maxy:
			break
		res = [str(minx), str(miny)]
	print(' '.join(res))
for _ in range(int(input().strip())):
	solution()


solutions = []
t = int(input())
for i in range(t):
	str1 = input().strip().split()
	n = int(str1[0])
	m = int(str1[1])
	commands = input().strip()
	i1 = 1
	j1 = 1
	i2 = n
	j2 = m
	ok = 1
	for j in range(len(commands)):
		if commands[j] == 'R':
			if j2 < m:
				j2 += 1
			j1 += 1
			if j1 > j2:
				j1 -= 1
				ok = 0
				break
		elif commands[j] == 'L':
			if j1 > 1:
				j1 -= 1
			j2 -= 1
			if j1 > j2:
				j2 += 1
				ok = 0
				break
		elif commands[j] == 'D':
			if i2 < n:
				i2 += 1
			i1 += 1
			if i1 > i2:
				i1 -= 1
				ok = 0
				break
		elif commands[j] == 'U':
			if i1 > 1:
				i1 -= 1
			i2 -= 1
			if i1 > i2:
				i2 += 1
				ok = 0
				break
	curr_i = i1
	curr_j = j1
	if ok == 0:
		j -= 1
	for back in range(j, -1, -1):
		if commands[back] == 'L':
			curr_j += 1
		elif commands[back] == 'R':
			curr_j -= 1
		elif commands[back] == 'U':
			curr_i += 1
		elif commands[back] == 'D':
			curr_i -= 1
	solutions.append(str(curr_i) + ' ' + str(curr_j))
for i in solutions:
	print(i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	l = d = u = r = x = y = 0
	ans = ['0'] * 2
	di = {'L': (0, -1), 'R': (0, 1), 'U': (-1, 0), 'D': (1, 0)}
	for i in range(len(s)):
		(a, b) = di[s[i]]
		x += a
		y += b
		l = min(l, y)
		r = max(r, y)
		u = min(u, x)
		d = max(d, x)
		if r - l >= m or d - u >= n:
			break
		ans = (abs(u), abs(l))
	print(int(ans[0]) + 1, int(ans[1]) + 1)


for q in range(int(input())):
	(str, stb) = input().split()
	str = int(str)
	stb = int(stb)
	naprav = list(input())
	l = 0
	r = 0
	u = 0
	d = 0
	lr = 0
	ud = 0
	z = 0
	for i in range(len(naprav)):
		if naprav[i] == 'L':
			lr -= 1
		elif naprav[i] == 'R':
			lr += 1
		elif naprav[i] == 'D':
			ud -= 1
		elif naprav[i] == 'U':
			ud += 1
		if lr - l >= stb or r - lr >= stb or ud - d >= str or (u - ud >= str):
			print(1 + u, 1 - l)
			z = 1
			break
		elif lr < l:
			l = lr
		elif lr > r:
			r = lr
		elif ud < d:
			d = ud
		elif ud > u:
			u = ud
	if z == 0:
		print(1 + u, 1 - l)


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	(n, m) = M()
	s = S()
	l = d = u = r = x = y = 0
	ans = (0, 0)
	di = {'L': (0, -1), 'R': (0, 1), 'U': (-1, 0), 'D': (1, 0)}
	for i in range(len(s)):
		(a, b) = di[s[i]]
		x += a
		y += b
		l = min(l, y)
		r = max(r, y)
		u = min(u, x)
		d = max(d, x)
		if r - l >= m or d - u >= n:
			break
		ans = (abs(u), abs(l))
	print(ans[0] + 1, ans[1] + 1)


def can_do_it(n, m, s):
	dx = 0
	dy = 0
	min_dx = dx
	max_dx = dx
	min_dy = dy
	max_dy = dy
	coords = [1, 1]
	for c in s:
		if c == 'L':
			dx -= 1
		elif c == 'D':
			dy += 1
		elif c == 'R':
			dx += 1
		elif c == 'U':
			dy -= 1
		min_dx = min(dx, min_dx)
		max_dx = max(dx, max_dx)
		min_dy = min(dy, min_dy)
		max_dy = max(dy, max_dy)
		if max_dx - min_dx >= m or max_dy - min_dy >= n:
			return coords
		else:
			coords = [abs(min_dy) + 1, abs(min_dx) + 1]
	return coords
anss = []
t = int(input())
for _ in range(t):
	inp = list(map(int, input().split()))
	anss.append(can_do_it(inp[0], inp[1], input()))
for ans in anss:
	print(ans[0], ans[1])


def squareOK(r1, c1):
	if 0 < r1 <= r and 0 < c1 <= c:
		return True
	return False
t = int(input())
for test in range(t):
	(r, c) = map(int, input().split())
	s = input()
	ir = 1
	ic = 1
	cr = 1
	cc = 1
	left = 0
	right = c - 1
	up = 0
	down = r - 1
	for (ind, i) in enumerate(s):
		if i == 'L':
			if squareOK(cr, cc - 1):
				cc -= 1
				left = min(left, cc)
				continue
			elif squareOK(ir, ic + 1):
				if right > 0:
					ic += 1
					right -= 1
					continue
			break
		if i == 'R':
			if squareOK(cr, cc + 1):
				cc += 1
				right = min(right, c - cc)
				continue
			elif squareOK(ir, ic - 1):
				if left > 0:
					ic -= 1
					left -= 1
					continue
			break
		if i == 'U':
			if squareOK(cr - 1, cc):
				cr -= 1
				up = min(up, cr)
				continue
			elif squareOK(ir + 1, ic):
				if down > 0:
					ir += 1
					down -= 1
					continue
			break
		else:
			if squareOK(cr + 1, cc):
				cr += 1
				down = min(down, r - cr)
				continue
			elif squareOK(ir - 1, ic):
				if up > 0:
					ir -= 1
					up -= 1
					continue
			break
	print(ir, ic)


tc = int(input())
for t in range(tc):
	(yran, xran) = map(int, input().split())
	s = input()
	startx = 0
	starty = 0
	curx = 0
	cury = 0
	lowestx = 0
	lowesty = 0
	highestx = 0
	highesty = 0
	for i in range(len(s)):
		if s[i] == 'R':
			curx += 1
		elif s[i] == 'L':
			curx -= 1
		elif s[i] == 'U':
			cury -= 1
		elif s[i] == 'D':
			cury += 1
		prevlowx = lowestx
		prevhighx = highestx
		prevlowy = lowesty
		prevhighy = highesty
		if curx < lowestx:
			lowestx = curx
		if cury < lowesty:
			lowesty = cury
		if cury > highesty:
			highesty = cury
		if curx > highestx:
			highestx = curx
		if abs(highesty - lowesty) > yran - 1:
			lowestx = prevlowx
			highestx = prevhighx
			lowesty = prevlowy
			highesty = prevhighy
			break
		if abs(highestx - lowestx) > xran - 1:
			lowestx = prevlowx
			highestx = prevhighx
			lowesty = prevlowy
			highesty = prevhighy
			break
	startx = startx - lowestx
	starty = starty - lowesty
	startx += 1
	starty += 1
	print(starty, startx)


o = int(input())
for _ in range(0, o):
	(n, m) = map(int, input().split())
	s = input()
	sx = 0
	sy = 0
	x = sx
	y = sy
	maxr = 0
	maxl = 0
	maxu = 0
	maxd = 0
	for w in s:
		if w == 'R':
			y += 1
			if y >= m:
				if sy - 1 - maxl >= 0:
					sy -= 1
					y -= 1
				else:
					break
			maxr = max(maxr, y - sy)
		elif w == 'L':
			y -= 1
			if y < 0:
				if sy + 1 + maxr < m:
					sy += 1
					y += 1
				else:
					break
			maxl = max(maxl, sy - y)
		elif w == 'D':
			x += 1
			if x >= n:
				if sx - 1 - maxu >= 0:
					sx -= 1
					x -= 1
				else:
					break
			maxd = max(maxd, x - sx)
		elif w == 'U':
			x -= 1
			if x < 0:
				if sx + 1 + maxd < n:
					sx += 1
					x += 1
				else:
					break
			maxu = max(maxu, sx - x)
	print(sx + 1, sy + 1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	s = input().rstrip()
	(left, right, top, down) = (0, m - 1, 0, n - 1)
	path = []
	for t in s:
		if t == 'L':
			nl = max(0, left - 1)
			nr = right - 1
			left = nl
			if nr < 0:
				break
			right = nr
		elif t == 'R':
			nl = left + 1
			nr = min(m - 1, right + 1)
			right = nr
			if nl > m - 1:
				break
			left = nl
		elif t == 'U':
			nt = max(0, top - 1)
			nd = down - 1
			top = nt
			if nd < 0:
				break
			down = nd
		else:
			nt = top + 1
			nd = min(n - 1, down + 1)
			down = nd
			if nt > n - 1:
				break
			top = nt
		path.append(t)
	(r, c) = (top, left)
	while path:
		t = path.pop()
		if t == 'L':
			c += 1
		elif t == 'R':
			c -= 1
		elif t == 'U':
			r += 1
		else:
			r -= 1
	print(r + 1, c + 1)


def f():
	(n, m) = map(int, input().split())
	s = input()
	(xp, xn, yp, yn) = (0, 0, 0, 0)
	(x, y) = (0, 0)
	for i in s:
		if i == 'R':
			x += 1
			xp = max(xp, x)
		elif i == 'L':
			x -= 1
			xn = min(x, xn)
		elif i == 'D':
			y += 1
			yp = max(y, yp)
		else:
			y -= 1
			yn = min(y, yn)
		if xp - xn >= m or yp - yn >= n:
			if i == 'L':
				xn += 1
			elif i == 'U':
				yn += 1
			print(-yn + 1, -xn + 1)
			return
	print(-yn + 1, -xn + 1)
for _ in range(int(input())):
	f()


def solve():
	(h, w) = map(int, input().split())
	s = input()
	n = len(s)
	(max_x, min_x) = (0, 0)
	(max_y, min_y) = (0, 0)
	(x, y) = (0, 0)
	ans = [1, 1]
	for i in range(n):
		if s[i] == 'R':
			y += 1
			max_y = max(max_y, y)
		if s[i] == 'L':
			y -= 1
			min_y = min(min_y, y)
		if s[i] == 'U':
			x -= 1
			min_x = min(min_x, x)
		if s[i] == 'D':
			x += 1
			max_x = max(max_x, x)
		if 1 - min_x <= h - max_x and 1 - min_y <= w - max_y:
			ans[0] = 1 - min_x
			ans[1] = 1 - min_y
		else:
			break
	print(ans[0], ans[1])
	return
for _ in range(int(input())):
	solve()


t = int(input())
ans = []
for _ in range(t):
	[n, m] = [int(_) for _ in input().split()]
	cmds = input()
	(x0, y0) = (0, 0)
	(l, r, u, d) = (0, 0, 0, 0)
	for c in cmds:
		if c == 'L':
			y0 -= 1
			if y0 < l:
				if r - y0 == m:
					break
				l = y0
		elif c == 'R':
			y0 += 1
			if y0 > r:
				if y0 - l == m:
					break
				r = y0
		elif c == 'U':
			x0 -= 1
			if x0 < u:
				if d - x0 == n:
					break
				u = x0
		else:
			x0 += 1
			if x0 > d:
				if x0 - u == n:
					break
				d = x0
	ans.append(f'{-u + 1} {-l + 1}')
print('\n'.join(ans))


for _ in range(int(input())):
	(h, w) = map(int, input().split())
	s = input()
	n = len(s)
	(ci, cj) = (0, 0)
	(min_i, max_i) = (0, 0)
	(min_j, max_j) = (0, 0)
	last_idx = n
	for i in range(n):
		op = s[i]
		if op == 'R':
			cj += 1
			max_j = max(max_j, cj)
		elif op == 'L':
			cj -= 1
			min_j = min(min_j, cj)
		elif op == 'D':
			ci += 1
			max_i = max(max_i, ci)
		elif op == 'U':
			ci -= 1
			min_i = min(min_i, ci)
		if max_i - min_i == h or max_j - min_j == w:
			last_idx = i
			break
	if last_idx == -1:
		print(1, 1)
	elif last_idx == n:
		print(abs(min_i) + 1, abs(min_j) + 1)
	else:
		op = s[last_idx]
		if op == 'R':
			max_j -= 1
		elif op == 'L':
			min_j += 1
		elif op == 'D':
			max_i -= 1
		elif op == 'U':
			min_i += 1
		print(abs(min_i) + 1, abs(min_j) + 1)


def solve():
	(h, w) = map(int, input().split())
	coms = input().strip()
	(x, y) = (0, 0)
	(min_x, max_x, min_y, max_y) = (0, 0, 0, 0)
	for com in coms:
		if com == 'L':
			x -= 1
		elif com == 'R':
			x += 1
		elif com == 'U':
			y -= 1
		elif com == 'D':
			y += 1
		cached = str(-min_y + 1) + ' ' + str(-min_x + 1)
		min_x = min(min_x, x)
		max_x = max(max_x, x)
		min_y = min(min_y, y)
		max_y = max(max_y, y)
		if max_x - min_x >= w or max_y - min_y >= h:
			return cached
	return str(-min_y + 1) + ' ' + str(-min_x + 1)
n = int(input())
for i in range(n):
	print(solve())


import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		to = f(*args, **kwargs)
		if stack:
			return to
		else:
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						return to
					to = stack[-1].send(to)
	return wrappedfunc

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def dfs_utility(self, nodes, visited_nodes, colors, parity, level):
		global count
		if nodes == 1:
			colors[nodes] = -1
		elif len(self.graph[nodes]) == 1 and parity % 2 == 0:
			if q == 1:
				colors[nodes] = 1
			else:
				colors[nodes] = -1
				count += 1
		elif parity % 2 == 0:
			colors[nodes] = -1
		else:
			colors[nodes] = 1
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			new_level = level + 1
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)

	def dfs(self, node):
		Visited = set()
		color = collections.defaultdict()
		self.dfs_utility(node, Visited, color, 0, 0)
		return color

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1
		return False

class Tree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UF:

	def __init__(self, N):
		self._id = list(range(N))
		self._count = N
		self._rank = [0] * N

	def find(self, p):
		id = self._id
		while p != id[p]:
			p = id[p]
		return p

	def count(self):
		return self._count

	def connected(self, p, q):
		return self.find(p) == self.find(q)

	def union(self, p, q):
		id = self._id
		rank = self._rank
		i = self.find(p)
		j = self.find(q)
		if i == j:
			return
		self._count -= 1
		if rank[i] < rank[j]:
			id[i] = j
		elif rank[i] > rank[j]:
			id[j] = i
		else:
			id[j] = i
			rank[i] += 1

	def add_roads(self):
		return set(self._id)

	def __str__(self):
		return ' '.join([str(x) for x in self._id])

	def __repr__(self):
		return 'UF(' + str(self) + ')'

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def p_sum(array):
	return list(itertools.accumulate(array))

def base_change(nn, bb):
	if nn == 0:
		return [0]
	digits = []
	while nn:
		digits.append(int(nn % bb))
		nn //= bb
	return digits[::-1]

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, **kwargs):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	(n, m) = map_inp(int)
	s = inp()
	(x, y) = (0, 0)
	ans_x = 1
	ans_y = 1
	(m_x, mi_x, m_y, mi_y) = (0, 0, 0, 0)
	arr = []
	for item in s:
		if item == 'D':
			y += 1
		elif item == 'U':
			y -= 1
		elif item == 'L':
			x -= 1
		else:
			x += 1
		mi_x = min(mi_x, x)
		m_x = max(m_x, x)
		mi_y = min(mi_y, y)
		m_y = max(m_y, y)
		if abs(mi_x) + abs(m_x) < m:
			ans_x = abs(mi_x) + 1
		if abs(mi_y) + abs(m_y) < n:
			ans_y = abs(mi_y) + 1
	print(ans_y, ans_x)


answers = []
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	(sx, sy, x, y, max_x, max_y) = (1, 1, 1, 1, 1, 1)
	for j in range(len(s)):
		i = s[j]
		if i == 'U':
			y -= 1
		if i == 'D':
			y += 1
		if i == 'L':
			x -= 1
		if i == 'R':
			x += 1
		if x < 1:
			if max_x < m:
				x += 1
				sx += 1
				max_x += 1
			else:
				break
		if y < 1:
			if max_y < n:
				y += 1
				sy += 1
				max_y += 1
			else:
				break
		if x > m or y > n:
			break
		max_x = max(max_x, x)
		max_y = max(max_y, y)
	answers.append((sy, sx))
for i in answers:
	print(*i)


def main():
	T = int(input())
	for t in range(T):
		run()

def run():
	(h, w) = map(int, input().rstrip().split(' '))
	s = input().rstrip()
	(pos_x, pos_y, min_x, max_x, min_y, max_y) = (0, 0, 0, 0, 0, 0)
	grid = [(0, 0, 0, 0)]
	for move in s:
		if move == 'R':
			pos_x += 1
			max_x = max(pos_x, max_x)
		elif move == 'L':
			pos_x -= 1
			min_x = min(pos_x, min_x)
		elif move == 'U':
			pos_y += 1
			max_y = max(pos_y, max_y)
		else:
			pos_y -= 1
			min_y = min(pos_y, min_y)
		grid.append((min_x, max_x, min_y, max_y))
	for (min_x, max_x, min_y, max_y) in grid[::-1]:
		if w >= max_x - min_x + 1 and h >= max_y - min_y + 1:
			print(max_y + 1, abs(min_x) + 1)
			break
main()


import sys
input = sys.stdin.readline
t = int(input())
d = {'U': (-1, 0), 'D': (1, 0), 'L': (0, -1), 'R': (0, 1)}
for _ in range(t):
	(n, m) = map(int, input().split())
	s = list(input().rstrip())
	(u, v) = (0, 0)
	(miu, mau, miv, mav) = (0, 0, 0, 0)
	(miu0, mau0, miv0, mav0) = (0, 0, 0, 0)
	for i in s:
		(du, dv) = d[i]
		u += du
		v += dv
		miu = min(u, miu)
		mau = max(u, mau)
		miv = min(v, miv)
		mav = max(v, mav)
		if mau - miu == n or mav - miv == m:
			(miu, mau, miv, mav) = (miu0, mau0, miv0, mav0)
			break
		(miu0, mau0, miv0, mav0) = (miu, mau, miv, mav)
	ans = [1 - miu, 1 - miv]
	print(*ans)


import sys
import math
import random
import heapq
input = sys.stdin.readline

def pow(a, n):
	if n == 0:
		return 1
	x = pow(a, n // 2)
	if n % 2 == 0:
		return x * x
	else:
		return x * x * a

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def bs(arr, le, ri):
	l = 0
	arr.sort()
	r = len(arr) - 1
	ans = 10000000
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= le and arr[m] <= ri:
			ans = arr[m]
			r = m - 1
		elif arr[m] < le:
			l = m + 1
		else:
			r = m - 1
	return ans
t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	s = input().strip()
	(l, r, u, d) = (0, 0, 0, 0)
	h = 0
	v = 0
	for i in s:
		if i == 'L':
			h -= 1
			if h < 0:
				l = max(l, abs(h))
			if l + r == m:
				l -= 1
				break
		elif i == 'R':
			h += 1
			if h > 0:
				r = max(r, h)
			if l + r == m:
				r -= 1
				break
		elif i == 'U':
			v -= 1
			if v < 0:
				u = max(u, abs(v))
			if u + d == n:
				u -= 1
				break
		else:
			v += 1
			if v > 0:
				d = max(d, v)
			if u + d == n:
				d -= 1
				break
	print(u + 1, l + 1)
	t -= 1


def get(a, k):
	n = len(a)
	x = 0
	mini = 0
	maxi = 0
	for i in a:
		mini = min(mini, i)
		maxi = max(maxi, i)
		if maxi - mini + 1 > k:
			return x
		if i < 0:
			x = max(x, abs(i))
	return x
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = input()
	pre_x = []
	pre_y = []
	for i in a:
		if i == 'R':
			pre_x.append(1)
		elif i == 'L':
			pre_x.append(-1)
		elif i == 'U':
			pre_y.append(-1)
		else:
			pre_y.append(1)
	for i in range(1, len(pre_x)):
		pre_x[i] += pre_x[i - 1]
	for i in range(1, len(pre_y)):
		pre_y[i] += pre_y[i - 1]
	print(get(pre_y, n) + 1, get(pre_x, m) + 1)


for i in range(int(input())):
	(size_y, size_x) = list(map(int, input().split()))
	instructions = input()
	(min_x, max_x, min_y, max_y, x, y) = (0, 0, 0, 0, 0, 0)
	(prev_min_x, prev_max_x) = (0, 0)
	(prev_min_y, prev_max_y) = (0, 0)
	for d in instructions:
		if d == 'U':
			y -= 1
			if y < min_y:
				min_y = y
		elif d == 'D':
			y += 1
			if y > max_y:
				max_y = y
		elif d == 'L':
			x -= 1
			if x < min_x:
				min_x = x
		elif d == 'R':
			x += 1
			if x > max_x:
				max_x = x
		if max_x - min_x > size_x - 1 or max_y - min_y > size_y - 1:
			(min_x, max_x) = (prev_min_x, prev_max_x)
			(min_y, max_y) = (prev_min_y, prev_max_y)
			break
		(prev_min_x, prev_max_x) = (min_x, max_x)
		(prev_min_y, prev_max_y) = (min_y, max_y)
	print(-min_y + 1, -min_x + 1)


import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import *
from collections import defaultdict, deque, Counter
import math, string
from heapq import *
from operator import add
from itertools import accumulate
BUFSIZE = 8192
sys.setrecursionlimit(10 ** 5)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inf = float('inf')
en = lambda x: list(enumerate(x))
ceil_ = lambda a, b: (a + b - 1) // b
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def go(x, y, s, n, col):
	c = 0
	for i in s:
		if i == 'L':
			if x != 1:
				x -= 1
				c += 1
		if i == 'R':
			if x != col:
				x += 1
				c += 1
		if i == 'U':
			if y != 1:
				y -= 1
				c += 1
		if i == 'D':
			if y != n:
				y += 1
				c += 1
	return c

def solve():
	(n, m) = r()
	s = input()
	a = b = 0
	left = up = 0
	right = down = 0
	for i in s:
		if i == 'L':
			a -= 1
			if a < 0:
				left = max(left, abs(a))
		if i == 'R':
			a += 1
			if a >= 0:
				right = max(right, abs(a))
		if i == 'U':
			b -= 1
			if b < 0:
				up = max(up, abs(b))
		if i == 'D':
			b += 1
			if b >= 0:
				down = max(down, abs(b))
	left += 1
	up += 1
	down = n - down
	right = m - right
	left = min(left, m)
	left = max(left, 1)
	right = min(right, m)
	right = max(right, 1)
	up = min(up, n)
	up = max(up, 1)
	down = min(down, n)
	down = max(down, 1)
	ans = -inf
	for i in [left, right, max(1, left - 1), min(m, right + 1)]:
		for j in [up, down, max(1, up - 1), min(right + 1, n)]:
			pop = go(i, j, s, n, m)
			if pop > ans:
				ans = pop
				ax = i
				ay = j
	print(ay, ax)
for _ in ' ' * ii():
	solve()


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

def hnbhai(tc):
	(n, m) = sd()
	s = sa()
	lr = []
	td = []
	for i in s:
		if i == 'L' or i == 'R':
			lr.append(i)
		else:
			td.append(i)
	low = 1
	high = len(lr)
	ans = 0
	while low <= high:
		l = [0]
		mid = (low + high) // 2
		x = 0
		for i in range(mid):
			if lr[i] == 'L':
				x -= 1
			else:
				x += 1
			l.append(x)
		(mn, mx) = (min(l), max(l))
		if mx - mn + 1 > m:
			high = mid - 1
			continue
		else:
			low = mid + 1
			ans = abs(mn)
	low = 1
	high = len(td)
	ans2 = 0
	while low <= high:
		l = [0]
		mid = (low + high) // 2
		x = 0
		for i in range(mid):
			if td[i] == 'U':
				x -= 1
			else:
				x += 1
			l.append(x)
		(mn, mx) = (min(l), max(l))
		if mx - mn + 1 > n:
			high = mid - 1
			continue
		else:
			low = mid + 1
			ans2 = abs(mn)
	print(ans2 + 1, ans + 1)
for _ in range(sb()):
	hnbhai(_ + 1)


from itertools import product, combinations
from math import sqrt, gcd, ceil
INF = int(1000000000.0 + 1)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	x = 0
	y = 0
	(xmin, xmax, ymin, ymax) = (0, 0, 0, 0)
	breaked = False
	for i in range(len(s)):
		el = s[i]
		if el == 'L':
			x -= 1
		elif el == 'R':
			x += 1
		elif el == 'U':
			y += 1
		elif el == 'D':
			y -= 1
		if x < xmin:
			xmin = x
			t = 1
		elif x > xmax:
			xmax = x
			t = 2
		elif y < ymin:
			ymin = y
			t = 3
		elif y > ymax:
			ymax = y
			t = 4
		if ymax - ymin >= n or xmax - xmin >= m:
			breaked = True
			break
	if breaked:
		if t == 1:
			xmin += 1
		elif t == 2:
			xmax -= 1
		elif t == 3:
			ymin += 1
		else:
			ymax -= 1
	print(1 + ymax, m - xmax)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	(x, y) = (0, 0)
	(mxx, mnx, mxy, mny) = (0, 0, 0, 0)
	for l in s:
		if l == 'R':
			x += 1
			mxx = max(mxx, x)
		elif l == 'L':
			x -= 1
			mnx = min(mnx, x)
		elif l == 'U':
			y += 1
			mxy = max(mxy, y)
		elif l == 'D':
			y -= 1
			mny = min(mny, y)
		if mxx - mnx + 1 > m or mxy - mny + 1 > n:
			if l == 'R':
				x -= 1
				mxx -= 1
			elif l == 'L':
				x += 1
				mnx += 1
			elif l == 'U':
				y -= 1
				mxy -= 1
			elif l == 'D':
				y += 1
				mny += 1
			break
	print(1 + mxy, 1 - mnx)


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

def Ii():
	return int(input())

def infi():
	return float('Inf')

def mino():
	return -1
for ____ in range(Ii()):
	(n, m) = II()
	cs = 0
	ml = 0
	mr = 0
	mu = 0
	md = 0
	cd = 0
	s = input()
	for i in s:
		if i == 'L':
			cs -= 1
			if cs < ml:
				if mr - ml >= m - 1:
					break
				ml = cs
		if i == 'R':
			cs += 1
			if cs > mr:
				if mr - ml >= m - 1:
					break
				mr = cs
		if i == 'U':
			cd -= 1
			if cd < mu:
				if md - mu >= n - 1:
					break
				mu = cd
		if i == 'D':
			cd += 1
			if cd > md:
				if md - mu >= n - 1:
					break
				md = cd
	print(1 - mu, 1 - ml)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	(r, c) = (1, 1)
	(x, y, lx, rx, uy, dy) = (0, 0, 0, 0, 0, 0)
	for ch in s:
		if ch == 'L':
			x -= 1
		elif ch == 'R':
			x += 1
		elif ch == 'U':
			y -= 1
		else:
			y += 1
		(lx, rx) = (min(lx, x), max(rx, x))
		(uy, dy) = (min(uy, y), max(dy, y))
		if rx - lx + 1 > m or dy - uy + 1 > n:
			break
		(r, c) = (1 - uy, 1 - lx)
	print(r, c)


for _ in range(int(input())):
	(n, M) = map(int, input().split())
	s = input()
	cnt_hor = 0
	cnt_ver = 0
	mu = 0
	md = 0
	ml = 0
	mr = 0
	m = [[], [], [], []]
	for i in s:
		if i == 'U':
			cnt_ver += 1
			mu = max(mu, cnt_ver)
		elif i == 'D':
			cnt_ver -= 1
			md = min(md, cnt_ver)
		elif i == 'L':
			cnt_hor -= 1
			ml = min(ml, cnt_hor)
		else:
			cnt_hor += 1
			mr = max(mr, cnt_hor)
		m[3].append(mr)
		m[0].append(mu)
		m[2].append(ml)
		m[1].append(md)
	ans = len(s) - 1
	for i in range(len(s)):
		if m[0][i] - m[1][i] > n - 1 or m[3][i] - m[2][i] > M - 1:
			ans = i - 1
			break
	if ans == -1:
		print(1, 1)
	else:
		print(1 + m[0][ans], abs(m[2][ans]) + 1)


import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)
(n, m) = (int(), int())
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

def charming():
	global n, m
	(n, m) = map(int, input().split())
	opt = input()
	d = {'U': 0, 'R': 1, 'D': 2, 'L': 3}
	(res1, res2) = (1, 1)
	(cntx, cnty) = (0, 0)
	(mnx, mxx) = (0, 0)
	(mny, mxy) = (0, 0)
	(flag1, flag2) = (True, True)
	for i in opt:
		id = d[i]
		cntx += dx[id]
		cnty += dy[id]
		mnx = min(mnx, cntx)
		mxx = max(mxx, cntx)
		mny = min(mny, cnty)
		mxy = max(mxy, cnty)
		lx = 1 - mnx
		rx = n - mxx
		ly = 1 - mny
		ry = m - mxy
		if id == 0 or id == 2:
			if lx <= rx:
				res1 = lx
			else:
				break
		if id == 1 or id == 3:
			if ly <= ry:
				res2 = ly
			else:
				break
	print(res1, res2)
for t in range(int(input())):
	charming()


import bisect
mod = 10 ** 9 + 7
eps = 10 ** (-9)

def __gcd(a, b):
	return a if b == 0 else __gcd(b, a % b)

def __lcm(a, b):
	return a * b / __gcd(a, b)

def __fact(n):
	return 1 if n == 1 else n * __fact(n - 1)

def __mex(a):
	mex = 0
	a.sort()
	for x in a:
		if x <= mex:
			mex += 1
		else:
			break
	return mex

def __dist(x1, y1, x2, y2):
	return (x1 - x2) ** 2 + (y1 - y2) ** 2

def __getprimes(n):
	isprime = [True for i in range(n + 1)]
	primes = []
	for i in range(2, n + 1):
		if isprime[i]:
			for j in range(i * i, n + 1, i):
				isprime[j] = False
	for i in range(2, n + 1):
		if isprime[i]:
			primes.append(i)
	return primes

def __cntprimediv(n):
	ret = 0
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			n //= i
			ret += 1
		i += 1
	if n > 1:
		ret += 1
	return ret

def __primefactors(n):
	ret = []
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			ret.append(i)
			n //= i
		i += 1
	if n > 1:
		ret.append(n)
	return ret

def __sumdigit(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret

def __zfunc(s):
	n = len(s)
	z = [0 for i in range(n)]
	l = 0
	r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z

def __to(n, x):
	ret = ''
	while n > 0:
		q = n % x
		if q < 10:
			ret += str(q)
		else:
			ret += chr(q - 10 + ord('a'))
		n //= x
	return ret[::-1]

def solve(t):
	(n, m) = map(int, input().split())
	s = input()
	x = 0
	y = 0
	mnx = 0
	mxx = 0
	mny = 0
	mxy = 0
	ansx = 1
	ansy = 1
	for c in s:
		if c == 'U':
			x -= 1
		elif c == 'D':
			x += 1
		elif c == 'R':
			y += 1
		else:
			y -= 1
		if max(mxx, x) - min(mnx, x) + 1 <= n and max(mxy, y) - min(mny, y) + 1 <= m:
			mxx = max(mxx, x)
			mnx = min(mnx, x)
			mxy = max(mxy, y)
			mny = min(mny, y)
			ansx = -mnx + 1
			ansy = -mny + 1
		else:
			break
	print(ansx, ansy)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, m) = ma()
	s = st()
	left = 0
	right = 0
	up = 0
	down = 0
	(h, v) = (0, 0)
	pos = 0
	xco = 0
	yco = 0
	hmin = 0
	vmin = 0
	for i in s:
		if i == 'L':
			left += 1
			if right:
				right -= 1
			h -= 1
		elif i == 'R':
			right += 1
			if left:
				left -= 1
			h += 1
		elif i == 'U':
			up += 1
			if down:
				down -= 1
			v -= 1
		else:
			down += 1
			if up:
				up -= 1
			v += 1
		if left >= m or right >= m or up >= n or (down >= n):
			break
		hmin = min(hmin, h)
		vmin = min(vmin, v)
		yco = -hmin
		xco = -vmin
	print(xco + 1, yco + 1)


import heapq

def solve():
	(n, m) = list(map(int, input().split()))
	moves = input()
	(max_up, max_down) = (0, 0)
	(max_left, max_right) = (0, 0)
	(x, y) = (0, 0)
	(ans_x, ans_y) = (1, 1)
	for char in moves:
		if char == 'U':
			y += 1
		elif char == 'D':
			y -= 1
		elif char == 'L':
			x -= 1
		elif char == 'R':
			x += 1
		max_left = min(x, max_left)
		max_right = max(x, max_right)
		max_up = max(y, max_up)
		max_down = min(y, max_down)
		if max_right - max_left + 1 > m or max_up - max_down + 1 > n:
			break
		else:
			ans_y = abs(max_left) + 1
			ans_x = abs(max_up) + 1
	print(*[ans_x, ans_y])
for i in range(int(input())):
	solve()


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input().strip()
	vals1 = []
	vals2 = []
	a = b = -1
	x = y = -1
	ans1 = ans2 = 0
	for i in s:
		if i == 'D' or i == 'U':
			if x == -1:
				if i == 'D':
					x = 1
				else:
					x = 0
			if i != a:
				a = i
				vals1.append(1)
			else:
				vals1[-1] += 1
		else:
			if y == -1:
				if i == 'R':
					y = 1
				else:
					y = 0
			if i != b:
				b = i
				vals2.append(1)
			else:
				vals2[-1] += 1
	xcor = [0, n - 1]
	ycor = [0, m - 1]
	if x != -1:
		delta = 0
		for i in vals1:
			if x:
				xcor[1] = min(n - 1 - i - delta, xcor[1])
				if xcor[1] <= xcor[0]:
					ans1 = xcor[0]
					break
				delta += i
			else:
				xcor[0] = max(i - delta, xcor[0])
				if xcor[1] <= xcor[0]:
					ans1 = xcor[1]
					break
				delta -= i
			x ^= 1
		else:
			ans1 = xcor[0]
	if y != -1:
		delta = 0
		for i in vals2:
			if y:
				ycor[1] = min(m - 1 - i - delta, ycor[1])
				if ycor[1] <= ycor[0]:
					ans2 = ycor[0]
					break
				delta += i
			else:
				ycor[0] = max(i - delta, ycor[0])
				if ycor[1] <= ycor[0]:
					ans2 = ycor[1]
					break
				delta -= i
			y ^= 1
		else:
			ans2 = ycor[0]
	print(ans1 + 1, ans2 + 1)


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	s = input()
	(x, y, rt, dw, cr, cd) = (1, 1, 1, 1, 1, 1)
	for c in s:
		if c == 'R':
			cr += 1
			rt = max(rt, cr)
			if rt > m:
				break
		elif c == 'D':
			cd += 1
			dw = max(dw, cd)
			if dw > n:
				break
		elif c == 'L':
			cr -= 1
			if cr < 1:
				rt += 1
				cr += 1
				if rt > m:
					break
				y += 1
		else:
			cd -= 1
			if cd < 1:
				dw += 1
				cd += 1
				if dw > n:
					break
				x += 1
	print(x, y)


import sys
import re
if len(sys.argv) > 1 and re.match(re.compile('^t[0-9]$'), sys.argv[1]):
	import os
	sys.stdin = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), sys.argv[1]), 'r')
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	x0 = y0 = 0
	x = y = 0
	mr = mb = 0
	for i in s:
		if i == 'U':
			if x - 1 >= 0:
				x -= 1
			elif mb + 1 <= n - 1:
				x0 += 1
				mb += 1
			else:
				break
		elif i == 'D':
			if x + 1 <= n - 1:
				x += 1
				mb = max(x, mb)
			else:
				break
		elif i == 'L':
			if y - 1 >= 0:
				y -= 1
			elif mr + 1 <= m - 1:
				y0 += 1
				mr += 1
			else:
				break
		elif i == 'R':
			if y + 1 <= m - 1:
				y += 1
				mr = max(y, mr)
			else:
				break
	print(x0 + 1, y0 + 1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp_vars_int = lambda : map(int, input().split())
inp_list_int = lambda : list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(n, m) = inp_vars_int()
	s = input()
	(rx, ry) = (0, 0)
	(x_max, x_min, y_max, y_min) = (0, 0, 0, 0)
	(maxdu, maxdd, maxdl, maxdr) = (0, 0, 0, 0)
	coms = {'R': (1, 0), 'L': (-1, 0), 'U': (0, -1), 'D': (0, 1)}
	for (i, c) in enumerate(s):
		(dx, dy) = coms[c]
		(nx, ny) = (rx + dx, ry + dy)
		x_max = max(nx, x_max)
		y_max = max(ny, y_max)
		x_min = min(nx, x_min)
		y_min = min(ny, y_min)
		maxdl = max(maxdl, x_max - nx)
		maxdr = max(maxdr, nx - x_min)
		maxdu = max(maxdd, y_max - ny)
		maxdd = max(maxdu, ny - y_min)
		if max(maxdl, maxdr) > m - 1 or max(maxdu, maxdd) > n - 1:
			x_min -= min(0, dx)
			y_min -= min(0, dy)
			break
		(rx, ry) = (nx, ny)
	print(1 - y_min, 1 - x_min)


t = int(input())
for _ in range(t):
	ans = [-1] * 2
	(n, m) = map(int, input().split())
	s = list(input())
	nmin = nmax = mmin = mmax = 0
	nnow = mnow = 0
	for i in range(len(s)):
		if s[i] == 'U':
			nnow += 1
			nmax = max(nmax, nnow)
		elif s[i] == 'D':
			nnow -= 1
			nmin = min(nmin, nnow)
		if nmax - nmin == n:
			if nnow == nmax:
				nmax -= 1
			break
		if s[i] == 'L':
			mnow -= 1
			mmin = min(mmin, mnow)
		elif s[i] == 'R':
			mnow += 1
			mmax = max(mmax, mnow)
		if mmax - mmin == m:
			if mnow == mmin:
				mmin += 1
			break
	ans[0] = nmax + 1
	ans[1] = -mmin + 1
	print(*ans)


t = int(input())

def solve():
	(n, m) = map(int, input().split())
	commands = input()
	(leftE, rightE, upE, downE) = (0, 0, 0, 0)
	(x, y) = (0, 0)
	(ansI, ansJ) = (1, 1)
	for (i, c) in enumerate(commands):
		if c == 'L':
			x -= 1
			leftE = max(-x, leftE)
		elif c == 'R':
			x += 1
			rightE = max(rightE, x)
		elif c == 'U':
			y += 1
			upE = max(upE, y)
		else:
			y -= 1
			downE = max(downE, -y)
		r = leftE + rightE + 1
		u = upE + downE + 1
		if r > m or u > n:
			break
		ansI = upE + 1
		ansJ = leftE + 1
	print(ansI, ansJ)
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	(u, r, d, l) = (0, 0, 0, 0)
	(cx, cy) = (0, 0)
	for move in s:
		if move == 'U':
			cy += 1
			u = max(u, cy)
			if u - d >= n:
				u -= 1
				break
		elif move == 'D':
			cy -= 1
			d = min(d, cy)
			if u - d >= n:
				d += 1
				break
		elif move == 'L':
			cx -= 1
			l = min(l, cx)
			if r - l >= m:
				l += 1
				break
		else:
			cx += 1
			r = max(r, cx)
			if r - l >= m:
				r -= 1
				break
	print(u + 1, 1 - l)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	(posx, posy) = (0, 0)
	s = input()
	minx = 0
	maxx = 0
	miny = 0
	maxy = 0
	for c in s:
		if c == 'L':
			posy -= 1
		if c == 'R':
			posy += 1
		if c == 'U':
			posx -= 1
		if c == 'D':
			posx += 1
		newmaxx = max(maxx, posx)
		newminx = min(minx, posx)
		newmaxy = max(maxy, posy)
		newminy = min(miny, posy)
		if newmaxx - newminx + 1 > n or newmaxy - newminy + 1 > m:
			break
		(maxx, minx, maxy, miny) = (newmaxx, newminx, newmaxy, newminy)
	print(1 - minx, 1 - miny)


import sys
import math
from bisect import bisect_left as bl
from bisect import bisect_right as br
from math import inf
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(input().rstrip())
	(l, u, d, r) = (0, 0, 0, 0)
	(nowx, nowy) = (0, 0)
	flag = True
	for i in range(len(arr)):
		if not flag:
			break
		if arr[i] == 'L':
			nowx -= 1
			l = min(l, nowx)
			if r - l == m:
				l += 1
				flag = False
		elif arr[i] == 'R':
			nowx += 1
			r = max(r, nowx)
			if r - l == m:
				r -= 1
				flag = False
		elif arr[i] == 'D':
			nowy += 1
			d = max(d, nowy)
			if d - u == n:
				d -= 1
				flag = False
		elif arr[i] == 'U':
			nowy -= 1
			u = min(u, nowy)
			if d - u == n:
				u += 1
				flag = False
	print(1 - u, 1 - l)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(curx, cury) = (1, 1)
	(minx, miny) = (1, 1)
	(maxx, maxy) = (1, 1)
	(ansx, ansy) = (1, 1)
	for c in input():
		if c == 'U':
			curx -= 1
		elif c == 'D':
			curx += 1
		elif c == 'L':
			cury -= 1
		else:
			cury += 1
		minx = min(minx, curx)
		miny = min(miny, cury)
		maxx = max(maxx, curx)
		maxy = max(maxy, cury)
		if maxx - minx + 1 > n:
			break
		if maxy - miny + 1 > m:
			break
		ansx = 2 - minx
		ansy = 2 - miny
	print(ansx, ansy)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	(currx, curry) = (0, 0)
	bigx = 0
	smlx = 0
	bigy = 0
	smly = 0
	done = False
	for char in s:
		if char == 'U':
			currx -= 1
			if bigx - currx == n:
				done = True
				print(-currx, -smly + 1)
				break
			else:
				smlx = min(smlx, currx)
		elif char == 'D':
			currx += 1
			if currx - smlx == n:
				done = True
				print(-smlx + 1, -smly + 1)
				break
			else:
				bigx = max(bigx, currx)
		elif char == 'L':
			curry -= 1
			if bigy - curry == m:
				done = True
				print(-smlx + 1, -smly + 1)
				break
			else:
				smly = min(smly, curry)
		elif char == 'R':
			curry += 1
			if curry - smly == m:
				done = True
				print(-smlx + 1, -smly + 1)
				break
			else:
				bigy = max(bigy, curry)
	if not done:
		print(-smlx + 1, -smly + 1)


t = int(input())
for k in range(t):
	inp = input().split()
	row = int(inp[0])
	column = int(inp[1])
	s = input()
	L = []
	D = []
	left = 0
	down = 0
	start = 0
	maximum = 0
	for i in s:
		if i == 'R':
			if left + 1 < column:
				left = left + 1
				if maximum < left:
					maximum = left
			else:
				break
		elif i == 'L':
			if left - 1 >= 0:
				left = left - 1
			elif start + 1 < column and maximum + 1 < column:
				start = start + 1
				maximum = maximum + 1
			else:
				break
	start1 = 0
	maximum = 0
	down = 0
	for i in s:
		if i == 'D':
			if down + 1 < row:
				down = down + 1
				if maximum < down:
					maximum = down
			else:
				break
		elif i == 'U':
			if down - 1 >= 0:
				down = down - 1
			elif start1 + 1 < row and maximum + 1 < row:
				start1 = start1 + 1
				maximum = maximum + 1
			else:
				break
	print(start1 + 1, start + 1)


from sys import stdin

def main():
	moves = {'L': (0, -1), 'R': (0, 1), 'D': (1, 0), 'U': (-1, 0)}
	input = stdin.readline
	t = int(input())
	for _ in range(t):
		(n, m) = [int(i) for i in input().split()]
		commands = input().strip()
		cur = [1, 1]
		ma = [(1, 1), (1, 1), (1, 1), (1, 1)]
		for move in commands:
			cur[0] += moves[move][0]
			cur[1] += moves[move][1]
			tc = tuple(cur)
			h = max(ma[1][0], tc[0]) - min(ma[0][0], tc[0])
			w = max(ma[3][1], tc[1]) - min(ma[2][1], tc[1])
			if n <= h or m <= w:
				break
			if cur[0] < ma[0][0]:
				ma[0] = tc
			if cur[0] > ma[1][0]:
				ma[1] = tc
			if cur[1] < ma[2][1]:
				ma[2] = tc
			if cur[1] > ma[3][1]:
				ma[3] = tc
		print(1 + max(0, 1 - ma[0][0]), 1 + max(0, 1 - ma[2][1]))
main()


import bisect
import random
import sys

def input():
	return sys.stdin.readline().strip('\n')

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

def cin_int():
	return int(input())
from collections import defaultdict

def mock(n, m, cmd):
	d = defaultdict(list)
	for x in range(1, n + 1):
		for y in range(1, m + 1):
			point = (x, y)
			ans = 0
			for c in cmd:
				if c == 'L':
					y -= 1
				elif c == 'R':
					y += 1
				elif c == 'U':
					x -= 1
				elif c == 'D':
					x += 1
				if not (1 <= x <= n and 1 <= y <= m):
					break
				ans += 1
			d[ans].append(point)
	return d[max(d.keys())]

def sv(n, m, cmd):
	(x, y) = (0, 0)
	points = []
	for c in cmd:
		if c == 'L':
			y -= 1
		elif c == 'R':
			y += 1
		elif c == 'U':
			x -= 1
		elif c == 'D':
			x += 1
		points.append((x, y))
	pre = [(min(points[0][0], 0), max(points[0][0], 0), min(0, points[0][1]), max(0, points[0][1]))]
	for p in points[1:]:
		(min_x, max_x, min_y, max_y) = pre[-1]
		(x2, y2) = p
		pre.append((min(min_x, x2, 0), max(max_x, x2, 0), min(min_y, y2, 0), max(max_y, y2, 0)))
	ans = (1, 1)
	for (a, b, c, d) in pre:
		if a <= 0 and b < n and (b - a <= n - 1) and (c <= 0) and (d < m) and (d - c <= m - 1):
			ans = (-a + 1, -c + 1)
	return ans
for _ in range(cin_int()):
	(n, m) = cin_int_ls()
	cmd = input()
	(x, y) = sv(n, m, cmd)
	print(x, y)


import math
import os
import sys
from io import BytesIO, IOBase
M = 1000000007
import random
import heapq
import threading
import bisect
import time
from functools import *
from collections import *
from itertools import *
BUFSIZE = 8192
import array

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def build(arr, a, b, st, node):
	if a == b:
		st[node] = arr[a]
		return st[node]
	mid = (a + b) // 2
	st[node] = min(build(arr, a, mid, st, 2 * node + 1), build(arr, mid + 1, b, st, 2 * node + 2))
	return st[node]

def getmin(arr, a, b, l, r, st, node):
	if l > b or r < a:
		return float('inf')
	if l <= a and r >= b:
		return st[node]
	mid = (a + b) // 2
	return min(getmin(arr, a, mid, l, r, st, 2 * node + 1), getmin(arr, mid + 1, b, l, r, st, 2 * node + 2))

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		(n, m) = sep()
		s = inp()
		(x, y) = (1, 1)
		(a, b) = (1, 1)
		maxx = 1
		maxy = 1
		minx = 1
		miny = 1
		for i in range(len(s)):
			if s[i] == 'L':
				b -= 1
			if s[i] == 'R':
				b += 1
			if s[i] == 'U':
				a -= 1
			if s[i] == 'D':
				a += 1
			if a < 1:
				if maxx >= n:
					break
				x += 1
				a = 1
				maxx += 1
			elif a > n:
				if minx <= 1:
					break
				x -= 1
				a = n
				maxx -= 1
			elif b > m:
				if miny == 1:
					break
				y -= 1
				b = m
				maxy -= 1
			elif b < 1:
				if maxy == m:
					break
				y += 1
				b = 1
				maxy += 1
			maxx = max(maxx, a)
			minx = min(minx, a)
			maxy = max(maxy, b)
			miny = min(miny, b)
			if x < 1 or x > n or y < 1 or (y > m):
				break
		print(max(1, min(x, n)), max(1, min(y, m)))
main()


import os
import sys
from math import *
from bisect import *
from io import BytesIO, IOBase
from typing import overload

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = int(1000000000.0 + 7)
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, m) = value()
	s = input()
	right = 0
	left = 0
	up = 0
	down = 0
	(x, y) = (0, 0)
	ans = (1, 1)
	for i in s:
		if i == 'R':
			x += 1
		elif i == 'L':
			x -= 1
		elif i == 'U':
			y += 1
		else:
			y -= 1
		right = max(right, x)
		left = min(left, x)
		up = max(up, y)
		down = min(down, y)
		row = 1 + abs(left)
		col = 1 + abs(up)
		if row - abs(left) >= 1 and row + right <= m and (col - up >= 1) and (col + abs(down) <= n):
			ans = (row, col)
	print(ans[1], ans[0])


import sys
input = sys.stdin.readline
dir = {'L': (0, -1), 'R': (0, 1), 'U': (-1, 0), 'D': (1, 0)}
t = int(input())
for __ in range(t):
	(n, m) = map(int, input().split())
	s = input().rstrip()
	(x, y) = (0, 0)
	(l, r, u, d) = [0] * 4
	answer = (0, 0)
	for i in s:
		(dx, dy) = dir[i]
		(x, y) = (x + dx, y + dy)
		l = min(l, y)
		r = max(r, y)
		u = min(u, x)
		d = max(d, x)
		if r - l < m and d - u < n:
			answer = (abs(u), abs(l))
		else:
			break
	print(1 + answer[0], 1 + answer[1])


def fun(m, n, s):
	stack_hor = 0
	stack_ver = 0
	(min_hor, max_hor) = (0, 0)
	(min_ver, max_ver) = (0, 0)
	i = 0
	while i < len(s) and (max_hor - min_hor < n and max_ver - min_ver < m):
		direction = s[i]
		if direction == 'U':
			stack_ver += 1
			max_ver = max(max_ver, stack_ver)
			if not max_ver - min_ver < m:
				max_ver -= 1
				break
		elif direction == 'D':
			stack_ver -= 1
			min_ver = min(min_ver, stack_ver)
			if not max_ver - min_ver < m:
				min_ver += 1
				break
		elif direction == 'R':
			stack_hor += 1
			max_hor = max(max_hor, stack_hor)
			if not max_hor - min_hor < n:
				max_hor -= 1
				break
		else:
			stack_hor -= 1
			min_hor = min(min_hor, stack_hor)
			if not max_hor - min_hor < n:
				min_hor += 1
				break
		i += 1
	print(str(abs(max_ver) + 1) + ' ' + str(abs(min_hor) + 1))
t = int(input())
for _ in range(t):
	m_n = input().split()
	m = int(m_n[0])
	n = int(m_n[1])
	s = input()
	fun(m, n, s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	x = 1
	y = 1
	s = s[::-1]
	for i in s:
		if i == 'L' and x < m:
			x += 1
		elif i == 'R' and x > 1:
			x -= 1
		elif i == 'U' and y < n:
			y += 1
		elif i == 'D' and y > 1:
			y -= 1
	print(y, x)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	L = 0
	R = 0
	T = 0
	D = 0
	(n, m) = list(map(int, input().strip().split()))[:2]
	commands = input()
	ans = [1, 1]
	val = len(commands)
	posX = 0
	posY = 0
	for i in range(val):
		if commands[i] == 'U':
			posY += 1
		elif commands[i] == 'D':
			posY -= 1
		elif commands[i] == 'L':
			posX -= 1
		else:
			posX += 1
		L = max(L, posX)
		R = min(R, posX)
		T = max(T, posY)
		D = min(D, posY)
		ax = abs(L) + abs(R) + 1
		ay = abs(T) + abs(D) + 1
		if ax <= m and ay <= n:
			ans = [abs(T) + 1, abs(R) + 1]
		else:
			break
	print(f'{ans[0]} {ans[1]}')
T = 1
T = int(input())
for _ in range(T):
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip()

def solve():
	(N, M) = map(int, input().split())
	c = r = c1 = c2 = r1 = r2 = 0
	for s in input():
		if s == 'L':
			c -= 1
			if c2 - c >= M:
				break
			c1 = min(c, c1)
		elif s == 'R':
			c += 1
			if c - c1 >= M:
				break
			c2 = max(c, c2)
		elif s == 'U':
			r -= 1
			if r2 - r >= N:
				break
			r1 = min(r, r1)
		else:
			r += 1
			if r - r2 >= N:
				break
			r2 = max(r, r2)
	print(1 - r1, 1 - c1)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	s = input()
	(r, c, tr, tc) = (1, 1, 1, 1)
	(cnth, cntv) = (0, 0)
	(N, M) = (n, m)
	for i in range(len(s)):
		if s[i] == 'R':
			cnth += 1
			while cnth > 0 and m + cnth > M:
				m -= 1
		if s[i] == 'L':
			cnth -= 1
			while cnth < 0 and c + cnth < 1:
				c += 1
		if s[i] == 'U':
			cntv -= 1
			while cntv < 0 and r + cntv < 1:
				r += 1
		if s[i] == 'D':
			cntv += 1
			while cntv > 0 and n + cntv > N:
				n -= 1
		if r > n or c > m:
			break
		tr = r
		tc = c
	print(tr, tc)


from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	arr = list(input().rstrip())
	row = 0
	col = 0
	max_r = 0
	min_r = 0
	max_c = 0
	min_c = 0
	x = False
	y = False
	if a == 1:
		x = 1
	if b == 1:
		y = 1
	for i in range(len(arr)):
		if arr[i] == 'L':
			row -= 1
			min_r = min(min_r, row)
		elif arr[i] == 'R':
			row += 1
			max_r = max(max_r, row)
		elif arr[i] == 'D':
			col += 1
			max_c = max(max_c, col)
		else:
			col -= 1
			min_c = min(min_c, col)
		if max_r - min_r == b - 1 and y == False:
			y = 1 - min_r
		if max_c - min_c == a - 1 and x == False:
			x = 1 - min_c
	if x == False:
		x = 1 - min_c
	if y == False:
		y = 1 - min_r
	print(x, y)


from sys import *
input = stdin.readline
import threading
from bisect import *
import math
from collections import *
import operator
from heapq import *
from itertools import *
inf = 10 ** 19
mod = 10 ** 9 + 7
MOD = 998244353
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
dx = [-1, 0]
dy = [0, -1]
setrecursionlimit(200005)

def asc(c):
	return ord(c) - 97 + 1
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()[:-1]
	sx = 0
	sy = 0
	x = 0
	y = 0
	ans = 0
	mxx = 0
	mxy = 0
	for i in s:
		if i == 'R':
			x += 1
		elif i == 'L':
			x -= 1
		elif i == 'U':
			y -= 1
		else:
			y += 1
		mxx = max(mxx, x)
		mxy = max(mxy, y)
		if x >= m or y >= n:
			break
		if x < 0 and mxx < m - 1:
			x += 1
			sx += 1
			mxx += 1
		if y < 0 and mxy < n - 1:
			y += 1
			sy += 1
			mxy += 1
	print(sy + 1, sx + 1)


number = int(input())

def f(n, m, steps):
	n = n - 1
	m = m - 1
	max_x = 0
	max_y = 0
	min_x = 0
	min_y = 0
	y = 0
	x = 0
	pos = [0, 0]
	for step in steps:
		if step == 'U':
			y += 1
		elif step == 'D':
			y -= 1
		elif step == 'L':
			x += 1
		elif step == 'R':
			x -= 1
		min_x = min(min_x, x)
		min_y = min(min_y, y)
		max_x = max(max_x, x)
		max_y = max(max_y, y)
		if max_y - min_y <= n and max_x - min_x <= m:
			pos = [max_y, max_x]
		else:
			return pos
	return pos
for _ in range(number):
	board = input().split(' ')
	steps = input()
	(n, m) = (int(board[0]), int(board[1]))
	pos = f(n, m, steps)
	print(pos[0] + 1, pos[1] + 1)


import sys
import math
import collections
import heapq
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
r = lambda : sys.stdin.readline().rstrip()
MIS = lambda : map(int, r().split())
for _ in range(int(r())):
	(N, M) = MIS()
	L = list(r())
	lM = 0
	rM = 0
	uM = 0
	dM = 0
	nowy = 0
	nowx = 0
	for i in L:
		if i == 'R':
			nowx += 1
			if rM < nowx:
				rM = nowx
			if abs(rM - lM) + 1 > M:
				break
		if i == 'L':
			nowx -= 1
			if lM > nowx:
				lM = nowx
			if abs(rM - lM) + 1 > M:
				lM += 1
				break
		if i == 'U':
			nowy -= 1
			if dM > nowy:
				dM = nowy
			if abs(uM - dM) + 1 > N:
				dM += 1
				break
		if i == 'D':
			nowy += 1
			if uM < nowy:
				uM = nowy
			if abs(uM - dM) + 1 > N:
				break
	print(-dM + 1, -lM + 1)


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	(n, m) = il()
	s = list(ip())
	x = 0
	y = 0
	cox = -1
	coy = -1
	t = 0
	t1 = 0
	t2 = 0
	t3 = 0
	ind = len(s)
	for i in range(len(s)):
		if s[i] == 'R':
			x += 1
		elif s[i] == 'L':
			x -= 1
		elif s[i] == 'U':
			y -= 1
		else:
			y += 1
		if x <= -m + t1:
			ind = i
			break
		elif x >= m - t:
			ind = i
			break
		elif y <= -n + t3:
			ind = i
			break
		elif y >= n - t2:
			ind = i
			break
		if x > 0:
			t1 = max(t1, x)
		if x < 0:
			t = max(t, -x)
		if y > 0:
			t3 = max(t3, y)
		if y < 0:
			t2 = max(t2, -y)
	x = 0
	y = 0
	t = 0
	t1 = 0
	cox = 0
	coy = 0
	for i in range(ind):
		if s[i] == 'R':
			x += 1
		elif s[i] == 'L':
			x -= 1
		elif s[i] == 'U':
			y -= 1
		else:
			y += 1
		if x < t:
			cox += 1
			t -= 1
		if y < t1:
			coy += 1
			t1 -= 1
	print(coy + 1, cox + 1)


t = int(input())
for i in range(t):
	(n, m) = [int(k) for k in input().split()]
	s = input()
	(x, y) = (0, 0)
	ml = 0
	mr = 0
	mu = 0
	md = 0
	for z in s:
		if z == 'L':
			x -= 1
			if x < ml:
				ml = x
			if mr - ml + 1 > m:
				ml += 1
				break
		if z == 'R':
			x += 1
			if x > mr:
				mr = x
			if mr - ml + 1 > m:
				mr -= 1
				break
		if z == 'D':
			y += 1
			if y > md:
				md = y
			if md - mu + 1 > n:
				md -= 1
				break
		if z == 'U':
			y -= 1
			if y < mu:
				mu = y
			if md - mu + 1 > n:
				mu += 1
				break
	print(1 - mu, 1 - ml)


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	s = input()
	(r, c, x, y, m1, m2, m3, m4) = (0, 0, 0, 0, 0, 0, 0, 0)
	for i in s:
		if i == 'L':
			y -= 1
			if y == -1:
				if m2 == m - 1:
					break
				c += 1
				y += 1
				m1 += 1
				m2 += 1
			m1 = min(m1, y)
		elif i == 'R':
			y += 1
			if y == m:
				if m1 == 0:
					break
				c -= 1
				y -= 1
				m1 -= 1
				m2 -= 1
			m2 = max(m2, y)
		elif i == 'U':
			x -= 1
			if x == -1:
				if m4 == n - 1:
					break
				r += 1
				x += 1
				m3 += 1
				m4 += 1
			m3 = min(m3, x)
		elif i == 'D':
			x += 1
			if x == n:
				if m3 == 0:
					break
				r -= 1
				x -= 1
				m3 -= 1
				m4 -= 1
			m4 = max(m4, x)
	print(r + 1, c + 1)


move = {'L': -1, 'R': 1, 'U': 1, 'D': -1}
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	move_order = input()
	(bx, by, maxbx, maxby, minbx, minby) = (0, 0, 0, 0, 0, 0)
	for c in move_order:
		if c == 'L':
			bx -= 1
			minbx = min(minbx, bx)
		elif c == 'R':
			bx += 1
			maxbx = max(maxbx, bx)
		elif c == 'U':
			by -= 1
			minby = min(minby, by)
		else:
			by += 1
			maxby = max(maxby, by)
		if maxbx - minbx >= m:
			if bx == minbx:
				minbx += 1
			break
		if maxby - minby >= n:
			if by == minby:
				minby += 1
			break
	str1 = str(1 - minby)
	str2 = str(1 - minbx)
	print(str1 + ' ' + str2)


import sys

def rall():
	return 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')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	(n, m) = map(int, rl().split(' '))
	commands = rl()
	start = [1, 1]
	if n > 1 or m > 1:
		(x, y) = (0, 0)
		(maxX, minX, maxY, minY) = (0, 0, 0, 0)
		last_command = None
		for c in commands:
			if c == 'R':
				x += 1
				maxX = max(x, maxX)
			if c == 'L':
				x -= 1
				minX = min(x, minX)
			if c == 'U':
				y -= 1
				minY = min(y, minY)
			if c == 'D':
				y += 1
				maxY = max(y, maxY)
			if maxX - minX == m:
				if c == 'R':
					maxX -= 1
					x -= 1
				if c == 'L':
					minX += 1
					x += 1
				break
			if maxY - minY == n:
				if c == 'U':
					minY += 1
					y += 1
				if c == 'D':
					maxY -= 1
					y -= 1
				break
		start = [1 - minY, 1 - minX]
	pra(start)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split(' '))
	S = input()
	(left, right, top, bottom) = (0, 0, 0, 0)
	(xbest, ybest) = (1, 1)
	(x, y) = (0, 0)
	for s in S:
		if s == 'U':
			y -= 1
			top = min(top, y)
		elif s == 'D':
			y += 1
			bottom = max(bottom, y)
		elif s == 'L':
			x -= 1
			left = min(left, x)
		else:
			x += 1
			right = max(right, x)
		if right - left + 1 > m or bottom - top + 1 > n:
			break
		if left <= 0:
			xbest = 1 - left
		if top <= 0:
			ybest = 1 - top
	print('{} {}'.format(ybest, xbest))


import sys

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

def get_string():
	return sys.stdin.readline().strip()
FILE = False
if FILE:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = get_int()
answer = []
for i in range(0, t):
	dim = get_string()
	(n, m) = dim.split()
	n = int(n)
	m = int(m)
	message = get_string()
	dx = 0
	dy = 0
	min_dx = 0
	max_dx = 0
	min_dy = 0
	max_dy = 0
	for letter in message:
		if letter == 'L':
			dy -= 1
			min_dy = min(min_dy, dy)
		elif letter == 'R':
			dy += 1
			max_dy = max(max_dy, dy)
		elif letter == 'U':
			dx -= 1
			min_dx = min(min_dx, dx)
		else:
			dx += 1
			max_dx = max(max_dx, dx)
		if max_dx - min_dx >= n:
			if dx == min_dx:
				min_dx += 1
			break
		if max_dy - min_dy >= m:
			if dy == min_dy:
				min_dy += 1
			break
	v1 = 1 - min_dx
	v2 = 1 - min_dy
	answer.append(str(v1) + ' ' + str(v2))
for item in answer:
	sys.stdout.write(item)
	sys.stdout.write('\n')


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))

def fn(x):
	pos_mx = neg_mx = 0
	for i in range(x + 1):
		if right[i] < 0:
			neg_mx = max(neg_mx, abs(right[i]))
		else:
			pos_mx = max(pos_mx, right[i])
	start_col = 1 + neg_mx
	end_col = col - pos_mx
	if start_col > col or end_col < 1 or end_col < start_col:
		return False
	pos_mx = neg_mx = 0
	for i in range(x + 1):
		if up[i] < 0:
			neg_mx = max(neg_mx, abs(up[i]))
		else:
			pos_mx = max(pos_mx, up[i])
	start_row = 1 + pos_mx
	end_row = row - neg_mx
	if start_row > row or end_row < 1 or end_row < start_row:
		return False
	return True
for _ in range(nmbr()):
	(row, col) = lst()
	s = input()
	n = len(s)
	right = [0] * n
	up = [0] * n
	for i in range(n):
		if s[i] == 'R':
			right[i] += 1
		elif s[i] == 'U':
			up[i] += 1
		elif s[i] == 'L':
			right[i] -= 1
		else:
			up[i] -= 1
	for i in range(1, n):
		up[i] += up[i - 1]
		right[i] += right[i - 1]
	(l, r) = (0, n - 1)
	while l <= r:
		mid = l + r >> 1
		if fn(mid):
			l = mid + 1
		else:
			r = mid - 1
	pos_mx = neg_mx = 0
	for i in range(r + 1):
		if right[i] < 0:
			neg_mx = max(neg_mx, abs(right[i]))
		else:
			pos_mx = max(pos_mx, right[i])
	start_col = 1 + neg_mx
	end_col = col - pos_mx
	pos_mx = neg_mx = 0
	for i in range(r + 1):
		if up[i] < 0:
			neg_mx = max(neg_mx, abs(up[i]))
		else:
			pos_mx = max(pos_mx, up[i])
	start_row = 1 + pos_mx
	end_row = row - neg_mx
	print(start_row, start_col)