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

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
from collections import deque, defaultdict
import time
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import copy
from itertools import combinations
import sys
import heapq

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

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

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

def tot(a, n, d):
	return n * (2 * a + (n - 1) * d) // 2
for _ in range(int(input())):
	(n, m) = get_ints()
	s = input()
	x = [0 for i in range(len(s))]
	y = [0 for i in range(len(s))]
	for i in range(len(s)):
		if s[i] == 'R':
			x[i] += 1
		if s[i] == 'L':
			x[i] -= 1
		if s[i] == 'U':
			y[i] -= 1
		if s[i] == 'D':
			y[i] += 1
		if i != 0:
			x[i] += x[i - 1]
			y[i] += y[i - 1]
	x_max = [x[0]]
	x_min = [x[0]]
	y_max = [y[0]]
	y_min = [y[0]]
	ans_x = -inf
	ans_y = -inf
	for i in range(1, len(s)):
		x_max.append(max(x_max[i - 1], x[i]))
		x_min.append(min(x_min[i - 1], x[i]))
		y_max.append(max(y_max[i - 1], y[i]))
		y_min.append(min(y_min[i - 1], y[i]))
	for i in range(len(s)):
		x_cor = -inf
		y_cor = -inf
		if x_max[i] >= 0 and x_min[i] >= 0:
			x_cor = m - x_max[i]
		if x_max[i] <= 0 and x_min[i] <= 0:
			if -x_min[i] + 1 <= m:
				x_cor = -x_min[i] + 1
		if x_max[i] >= 0 and x_min[i] <= 0:
			if m - x_max[i] >= -x_min[i] + 1:
				x_cor = m - x_max[i]
		if x_cor != -inf:
			if y_max[i] >= 0 and y_min[i] >= 0:
				y_cor = n - y_max[i]
			if y_max[i] <= 0 and y_min[i] <= 0:
				if -y_min[i] + 1 <= n:
					y_cor = -y_min[i] + 1
			if y_max[i] >= 0 and y_min[i] <= 0:
				if n - y_max[i] >= -y_min[i] + 1:
					y_cor = n - y_max[i]
		if x_cor != -inf and y_cor != -inf and (x_cor >= 1) and (x_cor <= m) and (y_cor >= 1) and (y_cor <= n):
			ans_x = x_cor
			ans_y = y_cor
		else:
			break
	if ans_x != -inf and ans_y != -inf:
		print(ans_y, ans_x)
	else:
		print(1, 1)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
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')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

class LazySegUpdate:

	def __init__(self, N):
		self.N = N
		n = 4 * N
		self.tree = [0] * n
		self.lazy = [0] * n

	def queryHelper(self, index, s, e, l, r):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return 0
		if s >= l and e <= r:
			return self.tree[index]
		mid = (s + e) // 2
		return max(self.queryHelper(2 * index, s, mid, l, r), self.queryHelper(2 * index + 1, mid + 1, e, l, r))

	def updateHelper(self, index, s, e, l, r, h):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return
		if s >= l and e <= r:
			self.tree[index] = max(self.tree[index], h)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], h)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], h)
			return
		mid = (s + e) // 2
		self.updateHelper(2 * index, s, mid, l, r, h)
		self.updateHelper(2 * index + 1, mid + 1, e, l, r, h)
		self.tree[index] = max(self.tree[2 * index], self.tree[2 * index + 1])

	def query(self, l, r):
		return self.queryHelper(1, 0, self.N - 1, l, r - 1)

	def update(self, l, r, h):
		self.updateHelper(1, 0, self.N - 1, l, r - 1, h)

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
tt = 1
tt = int(input())
for _ in range(tt):
	(n, m) = map(int, input().split())
	s = input()
	side = 0
	top = 0
	ans = [n, m]
	(lm, rm, tm, bm) = [0] * 4
	for i in s:
		if i == 'L':
			side -= 1
		elif i == 'R':
			side += 1
		elif i == 'U':
			top -= 1
		else:
			top += 1
		lm = min(lm, side)
		rm = max(rm, side)
		tm = max(tm, top)
		bm = min(bm, top)
		if rm - lm >= m or tm - bm >= n:
			break
		ans = [1 - bm, 1 - lm]
	print(*ans)


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 _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	dx = 0
	dy = 0
	maxleft = 0
	maxright = 0
	maxup = 0
	maxdown = 0
	for sym in s:
		if sym == 'L':
			dx -= 1
			maxleft = min(dx, maxleft)
			if maxright - maxleft >= m:
				maxleft += 1
				break
		elif sym == 'R':
			dx += 1
			maxright = max(dx, maxright)
			if maxright - maxleft >= m:
				break
		elif sym == 'D':
			dy += 1
			maxdown = max(dy, maxdown)
			if maxdown - maxup >= n:
				break
		else:
			dy -= 1
			maxup = min(dy, maxup)
			if maxdown - maxup >= n:
				maxup += 1
				break
	correcty = -maxup + 1
	correctx = -maxleft + 1
	print(correcty, correctx)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input().strip()
	(min_y, max_y) = (0, 0)
	(min_x, max_x) = (0, 0)
	(x, y) = (0, 0)
	for i in range(len(s)):
		if s[i] == 'L':
			x -= 1
			min_x = min(min_x, x)
		if s[i] == 'R':
			x += 1
			max_x = max(max_x, x)
		if s[i] == 'U':
			y -= 1
			min_y = min(min_y, y)
		if s[i] == 'D':
			y += 1
			max_y = max(max_y, y)
		have_solution = False
		if max_y - min_y >= n:
			have_solution = True
			if s[i] == 'D':
				max_y -= 1
			else:
				min_y += 1
		if max_x - min_x >= m:
			have_solution = True
			if s[i] == 'R':
				max_x -= 1
			else:
				min_x += 1
		if have_solution:
			break
	print(-min_y + 1, -min_x + 1)


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)


import sys
import io, os
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = str(input().rstrip())
	(y, x) = (0, 0)
	(my, My) = (0, 0)
	(mx, Mx) = (0, 0)
	flag = True
	for c in s:
		if c == 'L':
			x -= 1
		elif c == 'R':
			x += 1
		elif c == 'D':
			y += 1
		else:
			y -= 1
		my = min(my, y)
		My = max(My, y)
		mx = min(mx, x)
		Mx = max(Mx, x)
		if Mx - mx + 1 > m:
			if c == 'L':
				sx = m - Mx
				sy = n - My
			else:
				sx = 1 - mx
				sy = n - My
			flag = False
			break
		if My - my + 1 > n:
			if c == 'U':
				sy = n - My
				sx = m - Mx
			else:
				sy = 1 - my
				sx = m - Mx
			flag = False
			break
	if flag:
		sy = n - My
		sx = m - Mx
		print(sy, sx)
	else:
		print(sy, sx)


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
sys.setrecursionlimit(100000)

def _r():
	return sys.stdin.buffer.readline()

def rs():
	return _r().decode('ascii').strip()

def rn():
	return int(_r())

def rnt():
	return tuple(map(int, _r().split()))

def rnl():
	return list(rnt())

def solve(n, m, s):
	dirs = {'L': (0, -1), 'R': (0, 1), 'U': (-1, 0), 'D': (1, 0)}
	r = c = 0
	sr = sc = 0
	mr = mc = 1
	for d in s:
		(dr, dc) = dirs[d]
		r += dr
		c += dc
		if r < 0:
			if mr + 1 <= n:
				mr += 1
				r += 1
				sr += 1
			else:
				break
		elif r == mr:
			if mr + 1 <= n:
				mr += 1
			else:
				break
		elif c < 0:
			if mc + 1 <= m:
				mc += 1
				c += 1
				sc += 1
			else:
				break
		elif c == mc:
			if mc + 1 <= m:
				mc += 1
	return (sr + 1, sc + 1)
for _ in range(rn()):
	(n, m) = rnt()
	s = rs()
	print(' '.join(map(str, solve(n, m, s))))


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)


from collections import defaultdict, deque, Counter
from heapq import heapify, heappop, heappush
import math
from copy import deepcopy
from itertools import combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
import sys

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

def getN():
	return int(input())

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

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

def getListGraph():
	return list(map(lambda x: int(x) - 1, input().split()))

def getArray(intn):
	return [int(input()) for i in range(intn)]
mod = 10 ** 9 + 7
MOD = 998244353
inf = float('inf')
eps = 10 ** (-15)
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
T = getN()
for _ in range(T):
	(N, M) = getNM()
	C = input()
	(y, x) = (0, 0)
	ans = [1, 1]
	rang = [[0, 0], [0, 0]]
	for c in C:
		if c == 'L':
			x -= 1
			rang[1][0] = min(rang[1][0], x)
		elif c == 'R':
			x += 1
			rang[1][1] = max(rang[1][1], x)
		elif c == 'U':
			y -= 1
			rang[0][0] = min(rang[0][0], y)
		else:
			y += 1
			rang[0][1] = max(rang[0][1], y)
		if rang[0][1] - rang[0][0] + 1 > N or rang[1][1] - rang[1][0] + 1 > M:
			break
		ans = [1 - rang[0][0], 1 - rang[1][0]]
	print(*ans)


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


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	n -= 1
	m -= 1
	s = input()
	lh = 0
	uh = 0
	lw = 0
	rw = 0
	h = 0
	w = 0
	for i in s:
		if i == 'L':
			if rw - w == m:
				break
			w -= 1
			lw = min(w, lw)
		elif i == 'R':
			if w - lw == m:
				break
			w += 1
			rw = max(w, rw)
		elif i == 'U':
			if lh - h == n:
				break
			h -= 1
			uh = min(h, uh)
		elif i == 'D':
			if h - uh == n:
				break
			h += 1
			lh = max(lh, h)
	print(-uh + 1, -lw + 1)


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)


for _ in range(int(input())):
	(y, x) = list(map(int, input().split()))
	s = str(input())
	dif = [0, 0]
	maxy = 0
	maxx = 0
	miny = 0
	minx = 0
	y_taken = 1
	x_taken = 1
	for i in range(len(s)):
		if s[i] == 'U':
			dif[0] -= 1
		elif s[i] == 'D':
			dif[0] += 1
		elif s[i] == 'R':
			dif[1] += 1
		else:
			dif[1] -= 1
		if dif[0] > maxy:
			maxy = dif[0]
		elif dif[0] < miny:
			miny = dif[0]
		elif dif[1] > maxx:
			maxx = dif[1]
		elif dif[1] < minx:
			minx = dif[1]
		y_taken = 1 + abs(miny) + maxy
		x_taken = 1 + abs(minx) + maxx
		if y_taken > y or x_taken > x:
			if s[i] == 'U':
				y_taken -= 1
				miny += 1
			elif s[i] == 'D':
				y_taken -= 1
				maxy -= 1
			elif s[i] == 'R':
				x_taken -= 1
				maxx -= 1
			else:
				x_taken -= 1
				minx += 1
			break
	diapos = [1 - miny, y - maxy, 1 - minx, x - maxx]
	ans = [0, 0]
	if dif[0] > 0:
		ans[0] = min(diapos[0], diapos[1])
	else:
		ans[0] = max(diapos[0], diapos[1])
	if dif[1] > 0:
		ans[1] = min(diapos[2], diapos[3])
	else:
		ans[1] = min(diapos[2], diapos[3])
	print(*ans)


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
from os import path
if path.exists('input.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def main():
	inp = [x for x in sys.stdin.buffer.read().split()]
	ii = 0
	out = []
	t = int(inp[ii])
	ii += 1
	for _ in range(t):
		(n, m) = map(int, inp[ii:ii + 2])
		ii += 2
		s = str(inp[ii])[2:-1]
		ii += 1
		l = m
		r = 1
		u = n
		d = 1
		hor = 0
		ver = 0
		(x, y) = ('', '')
		for i in range(len(s)):
			if s[i] == 'L':
				hor -= 1
			if s[i] == 'R':
				hor += 1
			if s[i] == 'U':
				ver -= 1
			if s[i] == 'D':
				ver += 1
			l = min(l, m - hor)
			r = max(r, 1 - hor)
			u = min(u, n - ver)
			d = max(d, 1 - ver)
			y = r if s[i] == 'R' else l
			x = d if s[i] == 'D' else u
			if l < r or u < d:
				break
		out.append(str(x) + ' ' + str(y))
		pass
	out_str = '\n'.join((str(x) for x in out))
	sys.stdout.write(out_str)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	dirn = [0, 0, 0, 0]
	x = 0
	y = 0
	for i in s:
		if i == 'R':
			x += 1
		elif i == 'L':
			x -= 1
		elif i == 'U':
			y += 1
		else:
			y -= 1
		U = max(dirn[0], y)
		R = max(dirn[1], x)
		D = min(dirn[2], y)
		L = min(dirn[3], x)
		(col, row) = (abs(R - L) + 1, abs(U - D) + 1)
		if row <= n and col <= m:
			dirn = [U, R, D, L]
			continue
		else:
			break
	print(dirn[0] + 1, -dirn[3] + 1)


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)


import collections
import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left
from math import gcd, log, ceil
from collections import Counter
from pprint import pprint
import heapq
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')

def main2():
	(r, c) = list(map(int, input().split()))
	s = input()
	n = len(s)
	frq = collections.Counter(s)
	(ml, mr, mt, md) = (0, 0, 0, 0)
	(cr, cc) = (1, 1)
	move = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
	adjust = {'U': (-1, 0), 'D': (1, 0), 'L': (0, 1), 'R': (0, -1)}
	(mr, mc) = (1, 1)
	(ar, ac) = (1, 1)
	frq = collections.defaultdict(lambda : 0)
	for i in s:
		if i == 'L':
			frq['L'] += 1
		if i == 'R':
			frq['L'] -= 1
		if i == 'U':
			frq['D'] -= 1
		if i == 'D':
			frq['D'] += 1
		if abs(frq['D']) >= r:
			break
		if abs(frq['L']) >= c:
			break
		if frq['L'] > 0:
			ac = min(c, frq['L'])
		else:
			ac = min(c, c + frq['L'])
		if frq['D'] > 0:
			ar = min(r, frq['D'])
		else:
			ar = min(r, frq['D'] + r)
		print(ac, ar, frq)
	print(ar, ac)

def move(c, s, move_type='L', not_allowed=['U', 'D']):
	ans_col = 1
	x_move = 0
	(left, right) = (0, 0)
	for i in s:
		if i in not_allowed:
			continue
		x_move += -1 if i == move_type else 1
		if x_move < 0:
			left = max(left, abs(x_move))
		elif x_move > 0:
			right = max(right, abs(x_move))
		loc_gap_size = c - left - right
		if loc_gap_size <= 0:
			break
		ans_col = left + 1
	return ans_col

def main():
	(r, c) = list(map(int, input().split()))
	s = input()
	n = len(s)
	ans_c = move(c, s, 'L', ['U', 'D'])
	ans_r = move(r, s, 'U', ['L', 'R'])
	print(ans_r, ans_c)
t = int(input())
for _ in range(t):
	ans = main()


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)


for _ in range(int(input())):
	(rows, cols) = [int(x) for x in input().split()]
	seq = input()
	size_r = 0
	size_l = 0
	size_u = 0
	size_d = 0
	size_hz = size_r - size_l + 1
	size_vt = size_u - size_d + 1
	curr_pos_hz = 0
	curr_pos_vt = 0
	for char in seq:
		if char == 'R':
			curr_pos_hz += 1
		elif char == 'L':
			curr_pos_hz -= 1
		elif char == 'U':
			curr_pos_vt += 1
		elif char == 'D':
			curr_pos_vt -= 1
		new_size_r = max(size_r, curr_pos_hz)
		new_size_l = min(size_l, curr_pos_hz)
		new_size_u = max(size_u, curr_pos_vt)
		new_size_d = min(size_d, curr_pos_vt)
		new_size_hz = new_size_r - new_size_l + 1
		new_size_vt = new_size_u - new_size_d + 1
		if new_size_hz > cols or new_size_vt > rows:
			print(1 + size_u, cols - size_r)
			break
		size_r = new_size_r
		size_l = new_size_l
		size_u = new_size_u
		size_d = new_size_d
		size_hz = new_size_hz
		size_vt = new_size_vt
	else:
		print(1 + size_u, cols - size_r)


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


from sys import stdin

def read_input():
	(n, m) = map(int, stdin.readline().split())
	s = stdin.readline().rstrip()
	return (n, m, s)

def solve(n, m, s):
	(r, c) = (0, 0)
	(left, right, bottom, top) = (0, 0, 0, 0)
	for si in s:
		if si == 'L':
			if right - (c - 1) >= m:
				break
			c -= 1
			left = min(left, c)
		elif si == 'R':
			if c + 1 - left >= m:
				break
			c += 1
			right = max(right, c)
		elif si == 'D':
			if r + 1 - top >= n:
				break
			r += 1
			bottom = max(bottom, r)
		else:
			if bottom - (r - 1) >= n:
				break
			r -= 1
			top = min(top, r)
	return str(1 - top) + ' ' + str(1 - left)

def main():
	t = int(stdin.readline())
	for _ in range(t):
		input = read_input()
		answer = solve(*input)
		print(answer)
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])


import sys
import os.path
from collections import *
import math
import bisect
import heapq as hq
from fractions import Fraction
from random import randint
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline

def solve():
	(n, m) = [int(x) for x in input().split()]
	s = list(input().rstrip('\n'))
	left = 1
	right = 1
	up = 1
	down = 1
	x = 1
	y = 1
	X = 1
	Y = 1
	for i in range(len(s)):
		if s[i] == 'L':
			if x == 1:
				right += 1
				if right > m:
					break
				X += 1
			else:
				x -= 1
		if s[i] == 'R':
			if x == m:
				break
			else:
				x += 1
		if s[i] == 'U':
			if y == 1:
				down += 1
				if down > n:
					break
				Y += 1
			else:
				y -= 1
		if s[i] == 'D':
			if y == n:
				break
			else:
				y += 1
		right = max(right, x)
		down = max(down, y)
		if right > m or down > n:
			break
	print(Y, X)
t = int(input())
while t:
	t -= 1
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = input()
	(x, y) = (0, 0)
	c = 0
	d = 0
	(n1, m1, n2, m2) = (0, 0, 0, 0)
	for i in range(len(a)):
		if a[i] == 'L':
			c -= 1
		if a[i] == 'R':
			c += 1
		if a[i] == 'U':
			d -= 1
		if a[i] == 'D':
			d += 1
		n1 = min(d, n1)
		n2 = max(d, n2)
		m1 = min(c, m1)
		m2 = max(c, m2)
		if -n1 + n2 >= n or -m1 + m2 >= m:
			break
		x = -n1
		y = -m1
	print(x + 1, y + 1)


def fun(n, m, s):
	import sys
	yo = sys.maxsize
	l = len(s)
	(ver, hor) = (0, 0)
	lmax = 0
	rmax = 0
	umax = 0
	dmax = 0
	for ch in s:
		if ch == 'L':
			hor -= 1
		if ch == 'R':
			hor += 1
		if ch == 'U':
			ver -= 1
		if ch == 'D':
			ver += 1
		lmax = min(lmax, hor)
		umax = min(umax, ver)
		rmax = max(rmax, hor)
		dmax = max(dmax, ver)
		if rmax - lmax >= m or dmax - umax >= n:
			if ch == 'U':
				umax += 1
			if ch == 'D':
				dmax -= 1
			if ch == 'L':
				lmax += 1
			if ch == 'R':
				rmax -= 1
			break
	ansy = (0 - lmax + (m - rmax)) // 2
	ansx = (0 - umax + (n - dmax)) // 2
	return [ansx + 1, ansy + 1]
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s = input()
	ans = fun(n, m, s)
	print(*ans)


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


from __future__ import division, print_function
import math
import sys
import os
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')

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 int(input())

def inps():
	return input().strip()

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m) = invr()
	s = insr()
	ls = len(s)
	(x, y) = (0, 0)
	(mxx, mnx) = (0, 0)
	(mxy, mny) = (0, 0)
	ans = [1, 1]
	for i in range(ls):
		if s[i] == 'L':
			x -= 1
		elif s[i] == 'R':
			x += 1
		elif s[i] == 'U':
			y -= 1
		elif s[i] == 'D':
			y += 1
		mxx = max(x, mxx)
		mnx = min(x, mnx)
		mxy = max(y, mxy)
		mny = min(y, mny)
		if abs(mxx - mnx) < m:
			if abs(mxy - mny) < n:
				ans = [1 - mny, 1 - mnx]
			else:
				break
		else:
			break
	print(*ans)


def solve():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	moves = input()
	(grid_x, grid_y) = (0, 0)
	(x, y) = (0, 0)
	(max_x, max_y) = (0, 0)
	for command in moves:
		if command == 'R':
			if x + 1 <= grid_x + m - 1:
				x += 1
				max_x = max(max_x, x)
			else:
				return (-grid_y + 1, -grid_x + 1)
		elif command == 'D':
			if y + 1 <= grid_y + n - 1:
				y += 1
				max_y = max(max_y, y)
			else:
				return (-grid_y + 1, -grid_x + 1)
		elif command == 'L':
			if max_x == grid_x + m - 1:
				if x == grid_x:
					return (-grid_y + 1, -grid_x + 1)
				else:
					x -= 1
			elif x == grid_x:
				x -= 1
				grid_x -= 1
			else:
				x -= 1
		elif max_y == grid_y + n - 1:
			if y == grid_y:
				return (-grid_y + 1, -grid_x + 1)
			else:
				y -= 1
		elif y == grid_y:
			y -= 1
			grid_y -= 1
		else:
			y -= 1
	return (-grid_y + 1, -grid_x + 1)
t = int(input())
for _ in range(t):
	result = solve()
	print(result[0], result[1])


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
inf = 4294967295
md = 998244353

def solve():
	(h, w) = LI()
	s = SI()
	i = j = 0
	mni = mxi = mnj = mxj = 0
	for c in s:
		(di, dj) = dij['RDLU'.find(c)]
		(i, j) = (i + di, j + dj)
		if i - mni == h or mxi - i == h or j - mnj == w or (mxj - j == w):
			break
		if i < mni:
			mni = i
		if i > mxi:
			mxi = i
		if j < mnj:
			mnj = j
		if j > mxj:
			mxj = j
	print(1 - mni, 1 - mnj)
for testcase in range(II()):
	solve()


for __ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	(a, b, c, d) = (0, 0, 0, 0)
	(x, y) = (0, 0)
	(ans1, ans2) = (0, 0)
	ar = list(input())
	for i in range(len(ar)):
		if ar[i] == 'L':
			x -= 1
			a = min(a, x)
		elif ar[i] == 'R':
			x += 1
			b = max(b, x)
		elif ar[i] == 'U':
			y += 1
			c = max(c, y)
		elif ar[i] == 'D':
			y -= 1
			d = min(d, y)
		if b - a < m and c - d < n:
			(ans1, ans2) = (c + 1, -a + 1)
		else:
			break
	if ans1 == ans2 == 0:
		print(1, 1)
	else:
		print(ans1, ans2)


import sys
import os
import math
import bisect
from collections import *
import heapq
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from itertools import *
from functools import *
import random
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
INF = float('inf')
MOD = 1000000007
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')

def solve():
	(m, n) = mul()
	s = input()
	x = 0
	y = 0
	hi_x = 0
	lo_x = 0
	hi_y = 0
	lo_y = 0
	ans = [1, 1]
	for c in s:
		if c == 'U':
			y -= 1
		elif c == 'D':
			y += 1
		elif c == 'R':
			x += 1
		else:
			x -= 1
		hi_x = max(hi_x, x)
		lo_x = min(lo_x, x)
		hi_y = max(hi_y, y)
		lo_y = min(lo_y, y)
		if hi_x - lo_x + 1 <= n and hi_y - lo_y + 1 <= m:
			ans[0] = 1 - lo_y
			ans[1] = 1 - lo_x
		else:
			break
	print(ans[0], ans[1])
t = 1
t = inp()
for _ in range(t):
	solve()


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

def main():
	t = int(input())
	while t:
		(n, m) = map(int, input().split())
		s = str(input())
		(dx, dy) = (0, 0)
		(mdx, mdy, mndx, mndy) = (0, 0, 0, 0)
		(ansx, ansy) = (1, 1)
		for i in range(len(s)):
			if s[i] == 'L':
				dy -= 1
			if s[i] == 'R':
				dy += 1
			if s[i] == 'U':
				dx -= 1
			if s[i] == 'D':
				dx += 1
			mdy = max(mdy, dy)
			mndy = min(mndy, dy)
			mdx = max(mdx, dx)
			mndx = min(mndx, dx)
			x = n - mdx
			y = m - mdy
			if x >= 1 and x <= n and (x + mndx >= 1) and (x + mdx <= n) and (y >= 1) and (y <= m) and (y + mdy <= m) and (y + mndy >= 1):
				(ansx, ansy) = (x, y)
			else:
				break
		print(ansx, ansy)
		t -= 1
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')
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	i = j = 0
	left = right = up = down = 0
	for x in input():
		if x == 'L':
			j -= 1
			if right - (left := min(left, j)) == m:
				left += 1
				break
		elif x == 'R':
			j += 1
			if (right := max(right, j)) - left == m:
				right -= 1
				break
		elif x == 'U':
			i -= 1
			if down - (up := min(up, i)) == n:
				up += 1
				break
		elif x == 'D':
			i += 1
			if (down := max(down, i)) - up == n:
				down -= 1
				break
	print(1 - up, 1 - left)


t = int(input())
nth = []
mth = []
arr = []
for i in range(t):
	inp = input().split(' ')
	nth.append(int(inp[0]))
	mth.append(int(inp[1]))
	arr.append(input())
for i in range(t):
	col = [0]
	row = [0]
	maxCol = 0
	maxRow = 0
	for j in arr[i]:
		if j == 'L':
			maxCol -= 1
			col.append(maxCol)
		elif j == 'R':
			maxCol += 1
			col.append(maxCol)
		elif j == 'U':
			maxRow -= 1
			row.append(maxRow)
		else:
			maxRow += 1
			row.append(maxRow)
	rowAdd = 0
	colAdd = 0
	maxRow = 0
	maxCol = 0
	for j in col:
		if j + colAdd < 0:
			if maxCol + 1 < mth[i]:
				colAdd += 1
				maxCol += 1
			else:
				break
		else:
			if j + colAdd >= mth[i]:
				break
			if j + colAdd > maxCol:
				maxCol = j + colAdd
	for j in row:
		if j + rowAdd < 0:
			if maxRow + 1 < nth[i]:
				rowAdd += 1
				maxRow += 1
			else:
				break
		else:
			if j + rowAdd > maxRow:
				maxRow = j + rowAdd
			if j + rowAdd >= nth[i]:
				break
	print(rowAdd + 1, colAdd + 1)


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


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def dadd(d, p, val):
	if p in d:
		d[p].append(val)
	else:
		d[p] = [val]

def gi():
	return [xx for xx in input().split()]

def gtc(tc, *ans):
	print('Case #' + str(tc) + ':', *ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def bits(i, n):
	p = bin(i)[2:]
	return (n - len(p)) * '0' + p

def prec(a, pre):
	for i in a:
		pre.append(pre[-1] + i)
	pre.pop(0)

def YN(flag):
	print('YES' if flag else 'NO')

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
INF = 10 ** 18
uu = t
mod = 10 ** 9 + 7
while t > 0:
	t -= 1
	(n, m) = mi()
	s = ii()
	k = len(s)
	x = y = flag = 0
	mx = my = 0
	mix = miy = 0
	for i in range(k):
		if s[i] == 'L':
			x -= 1
		if s[i] == 'R':
			x += 1
		if s[i] == 'U':
			y -= 1
		if s[i] == 'D':
			y += 1
		(pmx, pmix, pmy, pmiy) = (mx, mix, my, miy)
		mx = max(mx, x)
		mix = min(mix, x)
		my = max(my, y)
		miy = min(miy, y)
		if mx + abs(mix) >= m or my + abs(miy) >= n:
			flag = 1
			break
	if flag == 1:
		(mx, my, mix, miy) = (pmx, pmy, pmix, pmiy)
	print(n - my, m - mx)


import sys, collections, math, bisect, heapq, random, functools
input = sys.stdin.readline
out = sys.stdout.flush

def solve():
	(n, m) = map(int, input().split())
	(x, y) = (1, 1)
	(cx, cy) = (1, 1)
	s = input().rstrip('\n')
	(left, right, bottom, top) = (0, 0, 0, 0)
	(lp, rp, bp, tp) = ([0, 0], [0, 0], [0, 0], [0, 0])
	(px, py) = (0, 0)
	for i in range(len(s)):
		if s[i] == 'L':
			if cy - 1 <= 0:
				if y + 1 > m or y + right + 1 > m:
					break
				else:
					y += 1
					py += 1
			else:
				cy -= 1
			if cy - y < left:
				left = cy - y
				lp = [cx, cy]
		elif s[i] == 'R':
			if cy + 1 > m:
				if y - 1 <= 0 or y - abs(left) - 1 <= 0:
					break
				else:
					y -= 1
					py -= 1
			else:
				cy += 1
			if cy - y > right:
				right = cy - y
				rp = [cx, cy]
		elif s[i] == 'U':
			if cx - 1 <= 0:
				if x + 1 > n or x + bottom + 1 > n:
					break
				else:
					x += 1
					px += 1
			else:
				cx -= 1
			if cx - x < top:
				top = cx - x
				tp = [cx, cy]
		else:
			if cx + 1 > n:
				if x - 1 <= 0 or x - abs(top) - 1 <= 0:
					break
				else:
					x -= 1
					px -= 1
			else:
				cx += 1
			if cx - x > bottom:
				bottom = cx - x
				bp = [cx, cy]
	print(x, y)
for i 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 __future__ import division, print_function
import math
import sys
import os
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')

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 I():
	return int(input())

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
import itertools
from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

def S():
	return list(map(str, input().strip()))

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from math import factorial, inf
from itertools import groupby
from itertools import permutations as comb
mod = 1000000007
MOD = 998244353

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

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a, b, c):
	print(c, a, b, flush=True)
	n = I()
	return n

def linear_sieve(n):
	is_composite = [False] * n
	prime = []
	for i in range(2, n):
		if not is_composite[i]:
			prime.append(i)
		for j in prime:
			is_composite[i * j] = True
			if i % prime == 0:
				break
	return prime

def dfs(i, p, d):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n // i
	if n > 2:
		l.append(n)
	return l

def binpow(a, b, c):
	res = 1
	a = a % c
	while b > 0:
		if b & 1:
			res = res * a % c
		b = b >> 1
		a = a * a % c
	return res
d = []
primes = []
prim = [0] * (10 ** 5 + 1)

def sieve(n):
	for i in range(n):
		d.append(i)
	for i in range(2, n):
		if d[i] == i:
			prim[i] = 1
			primes.append(i)
		j = 0
		while j < len(primes) and primes[j] <= d[i] and (primes[j] * i < n):
			d[i * primes[j]] = primes[j]
			j += 1

def primeFactors(n):
	factors = []
	while n != 1:
		factors.append(d[n])
		n //= d[n]
	return factors
t = 1
t = I()
for _ in range(t):
	(n, m) = lint()
	s = S()
	(x, y) = (0, 0)
	(yma, ymi) = (0, 0)
	(xma, xmi) = (0, 0)
	(ansx, ansy) = (1, 1)
	for i in range(len(s)):
		if s[i] == 'L':
			x -= 1
			xmi = min(xmi, x)
		elif s[i] == 'R':
			x += 1
			xma = max(x, xma)
		elif s[i] == 'U':
			y += 1
			yma = max(y, yma)
		else:
			y -= 1
			ymi = min(ymi, y)
		if yma - ymi + 1 <= n and xma - xmi + 1 <= m:
			ansx = 1 - xmi
			ansy = 1 + yma
		else:
			break
	print(ansy, ansx)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = input()
	(x, y, min_x, min_y, max_x, max_y) = (0, 0, 0, 0, 0, 0)
	(ans_x, ans_y) = (0, 0)
	for i in range(len(s)):
		if max_x - min_x >= m or max_y - min_y >= n:
			break
		ans_x = abs(min_x) + 1
		ans_y = abs(min_y) + 1
		if s[i] == 'R':
			x += 1
			max_x = max(x, max_x)
		if s[i] == 'L':
			x -= 1
			min_x = min(x, min_x)
		if s[i] == 'D':
			y += 1
			max_y = max(y, max_y)
		if s[i] == 'U':
			y -= 1
			min_y = min(y, min_y)
	if max_x - min_x >= m or max_y - min_y >= n:
		pass
	else:
		ans_x = abs(min_x) + 1
		ans_y = abs(min_y) + 1
	print(f'{ans_y} {ans_x}')


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
readline = sys.stdin.readline
T = int(readline())
for t in range(T):
	(N, M) = map(int, readline().split())
	S = readline().rstrip()
	(y, x) = (0, 0)
	(x_max, x_min, y_max, y_min) = (0, 0, 0, 0)
	for s in S:
		if s == 'L':
			if -(x - 1) + x_max + 1 <= M:
				x -= 1
				if x < x_min:
					x_min = x
			else:
				break
		elif s == 'R':
			if 1 - x_min + (x + 1) <= M:
				x += 1
				if x > x_max:
					x_max = x
			else:
				break
		elif s == 'U':
			if -(y - 1) + y_max + 1 <= N:
				y -= 1
				if y < y_min:
					y_min = y
			else:
				break
		elif s == 'D':
			if 1 - y_min + (y + 1) <= N:
				y += 1
				if y > y_max:
					y_max = y
			else:
				break
	print(-y_min + 1, -x_min + 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)


def solve():
	(n, m) = map(int, input().split())
	(cx, cy) = (0, 0)
	(minx, miny) = (0, 0)
	(maxx, maxy) = (0, 0)
	r = (1, 1)
	for c in input():
		if c == 'D':
			cy += 1
			maxy = max(maxy, cy)
		elif c == 'R':
			cx += 1
			maxx = max(maxx, cx)
		elif c == 'U':
			cy -= 1
			miny = min(miny, cy)
		elif c == 'L':
			cx -= 1
			minx = min(minx, cx)
		if maxy - miny + 1 > n or maxx - minx + 1 > m:
			break
		r = (1 - miny, 1 - minx)
	return r
for _ in range(int(input())):
	print(*solve())


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)


def solve(r, c, s):
	pos = [1, 1]
	pos_range = {'U': 1, 'D': 1, 'L': 1, 'R': 1}
	for command in s:
		if command == 'R':
			pos[1] += 1
			pos_range['R'] = max(pos_range['R'], pos[1])
		elif command == 'L':
			pos[1] -= 1
			pos_range['L'] = min(pos_range['L'], pos[1])
		elif command == 'U':
			pos[0] -= 1
			pos_range['U'] = min(pos_range['U'], pos[0])
		elif command == 'D':
			pos[0] += 1
			pos_range['D'] = max(pos_range['D'], pos[0])
		else:
			raise NotImplementedError()
		if pos_range['D'] - pos_range['U'] + 1 > r or pos_range['R'] - pos_range['L'] + 1 > c:
			if command == 'R':
				pos[1] -= 1
				pos_range['R'] -= 1
			elif command == 'L':
				pos[1] += 1
				pos_range['L'] += 1
			elif command == 'U':
				pos[0] += 1
				pos_range['U'] += 1
			elif command == 'D':
				pos[0] -= 1
				pos_range['D'] -= 1
			else:
				raise NotImplementedError()
			break
	starting_pos = [2 - pos_range['U'], 2 - pos_range['L']]
	return starting_pos
t = int(input())
for i in range(t):
	(r, c) = list(map(int, input().split(' ')))
	s = input()
	result = solve(r, c, s)
	print(result[0], result[1])


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)


t = int(input())

def f(n, m, s):
	(staten, statem) = (0, 0)
	(maxn, maxm, minn, minm) = (0, 0, 0, 0)
	j = 0
	while maxn - minn <= n - 1 and maxm - minm <= m - 1 and (j < len(s)):
		if s[j] == 'L':
			statem -= 1
			minm = min(minm, statem)
		if s[j] == 'R':
			statem += 1
			maxm = max(maxm, statem)
		if s[j] == 'D':
			staten += 1
			maxn = max(maxn, staten)
		if s[j] == 'U':
			staten -= 1
			minn = min(minn, staten)
		j += 1
		if j == len(s) and maxn - minn <= n - 1 and (maxm - minm <= m - 1):
			j += 1
	(staten, statem) = (0, 0)
	(maxn, maxm, minn, minm) = (0, 0, 0, 0)
	for i in range(j - 1):
		if s[i] == 'L':
			statem -= 1
			minm = min(minm, statem)
		if s[i] == 'R':
			statem += 1
			maxm = max(maxm, statem)
		if s[i] == 'D':
			staten += 1
			maxn = max(maxn, staten)
		if s[i] == 'U':
			staten -= 1
			minn = min(minn, staten)
	return (1 - minn, 1 - minm)
for i in range(t):
	(n, m) = tuple(map(int, input().split()))
	s = str(input())
	(a, b) = f(n, m, s)
	print(a, b)


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 io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	(m, n) = map(int, input().split())
	s = input()
	direc = {ord('U'): [-1, 0], ord('D'): [1, 0], ord('L'): [0, -1], ord('R'): [0, 1]}
	minh = 0
	maxh = 0
	minv = 0
	maxv = 0
	v = 0
	h = 0
	flag = True
	for c in s[:-2]:
		(preminh, premaxh, preminv, premaxv) = (minh, maxh, minv, maxv)
		v += direc[c][0]
		h += direc[c][1]
		minh = min(minh, h)
		maxh = max(maxh, h)
		minv = min(minv, v)
		maxv = max(maxv, v)
		if maxv - minv >= m or maxh - minh >= n:
			flag = False
			break
	if not flag:
		print(-preminv + 1, -preminh + 1)
	else:
		print(-minv + 1, -minh + 1)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


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)