Everybody is worried about Rakesh as the boy does not have much knowledge about the real world. He can not go from one place to another on his own. It's high time he learned to explore the city. He is going to a relative's house situated on the other side of the city on his own. As this is his first time, he is carrying a GPS tracker of a special kind. The tracker continuously sends information to the family of Rakesh about his movement. The information is sent using the following four letters: U, D, R, and L. Those letters indicate the moves taken by Rakesh. 

The city can be considered as a grid. Rakesh starts his journey from (0, 0) position of the grid. His relative's house is situated at (Rx, Ry). Rakesh can move in four directions: up, down, right, or left indicated by U, D, R, and L respectively. 

Any position of the city with x ordinate negative or greater than M is considered as dangerous. Also, any position of the city with y ordinate negative or greater than N is considered as dangerous. You will be given the total sequence of Rakesh's movement. You need to determine if Rakesh ended up being at his relative's house, at a dangerous place, or at a random place in the city.

To make things clear,

-  U indicates a move that increases position along y-axis by 1 
-  D indicates a move that decreases position along y-axis by 1 
-  R indicates a move that increases position along x-axis by 1 
-  L indicates a move that decreases position along x-axis by 1 

Note that we are interested in the position of Rakesh at the end of his journey only. He may visit some dangerous place or his relative's house at some intermediate point but that won't affect the answer.

-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of each test case follows.

- The first line of each test case contains two integers M and N.
- The second line contains two integers Rx and Ry.
- The third line contains the length of Rakesh's move sequence.
- The next line contains the move sequence containing letters U, D, R, and L only with no space.

-----Output-----
For each test case, print "Case i: ", and then the answer, where i is the testcase number, 1-indexed. The answer should be any of the following three strings:
-  "REACHED" if Rakesh could reach his relative's house 
-  "DANGER" if Rakesh ended up being in a dangerous place 
-  "SOMEWHERE" if Rakesh ended up being in somewhere safe place in the city other than his relative's place 
Don't print any quotation mark. Check the sample output.

-----Constraints-----

- 1 ≤ T ≤ 10
- 0 ≤ M, N ≤ 10000
- 0 ≤ Rx ≤  M 
- 0 ≤ Ry ≤  N 
- 0 ≤ Sum of the lengths of all sequences ≤ 10000

-----Example-----
Input:
2
20 20
4 5
13
LLUUUUURRRRRR
10 10
3 4
7
UDUDDRR

Output:
Case 1: REACHED
Case 2: DANGER

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
try:
	t = int(input())
	for i in range(t):
		print('Case {}:'.format(i + 1), end=' ')
		(m, n) = map(int, input().split())
		(x, y) = map(int, input().split())
		l = int(input())
		a = input()
		destx = a.count('R') - a.count('L')
		desty = a.count('U') - a.count('D')
		if (destx < 0 or destx > m) or (desty < 0 or desty > n):
			result = 'DANGER'
		elif destx == x and desty == y:
			result = 'REACHED'
		else:
			result = 'SOMEWHERE'
		print(result)
except:
	pass


for w in range(int(input())):
	(m, n) = list(map(int, input().split()))
	(rx, ry) = list(map(int, input().split()))
	u = int(input())
	s = input()
	x = y = 0
	for i in range(len(s)):
		if s[i] == 'U':
			y += 1
		elif s[i] == 'D':
			y -= 1
		elif s[i] == 'L':
			x -= 1
		elif s[i] == 'R':
			x += 1
	w += 1
	if rx == x and ry == y:
		print('Case ' + str(w) + ': REACHED')
	elif x < 0 or y < 0 or x > m or (y > n):
		print('Case ' + str(w) + ': DANGER')
	else:
		print('Case ' + str(w) + ': SOMEWHERE')


for w in range(int(input())):
	(danx, dany) = list(map(int, input().split()))
	(detx, dety) = list(map(int, input().split()))
	u = int(input())
	l = input()
	x = y = 0
	for i in range(len(l)):
		if l[i] == 'U':
			y += 1
		elif l[i] == 'D':
			y -= 1
		elif l[i] == 'L':
			x -= 1
		elif l[i] == 'R':
			x += 1
	w += 1
	if detx == x and dety == y:
		print('Case ' + str(w) + ': REACHED')
	elif x < 0 or y < 0 or x > danx or (y > dany):
		print('Case ' + str(w) + ': DANGER')
	else:
		print('Case ' + str(w) + ': SOMEWHERE')


T = int(input())
i = 1
while T:
	T -= 1
	(M, N) = map(int, input().split())
	(cur_x, cur_y) = (0, 0)
	(dest_x, dest_y) = map(int, input().split())
	L = int(input())
	direction_seqn = input()
	for direction in direction_seqn:
		if direction == 'U':
			cur_y += 1
		elif direction == 'D':
			cur_y -= 1
		elif direction == 'R':
			cur_x += 1
		elif direction == 'L':
			cur_x -= 1
	print('Case ' + str(i) + ': ', end='')
	i += 1
	if (cur_x, cur_y) == (dest_x, dest_y):
		print('REACHED')
	elif cur_x < 0 or cur_x > M or cur_y < 0 or (cur_y > N):
		print('DANGER')
	else:
		print('SOMEWHERE')


t = int(input())
c = 1
while t > 0:
	inp = [int(i) for i in input().split(' ')]
	m = inp[0]
	n = inp[1]
	inp = [int(i) for i in input().split(' ')]
	rx = inp[0]
	ry = inp[1]
	path_len = int(input())
	path = input()
	posx = 0
	posy = 0
	for p in path:
		if p == 'L':
			posx -= 1
		elif p == 'R':
			posx += 1
		elif p == 'U':
			posy += 1
		elif p == 'D':
			posy -= 1
	if posx > m or posx < 0 or posy > n or (posy < 0):
		print('Case ' + str(c) + ': ' + 'DANGER')
	elif posx != rx or posy != ry:
		print('Case ' + str(c) + ': ' + 'SOMEWHERE')
	elif posx == rx and posy == ry:
		print('Case ' + str(c) + ': ' + 'REACHED')
	t -= 1
	c += 1


t = int(input())
for j in range(0, t):
	(m, n) = map(int, input().split(' '))
	(u, v) = map(int, input().split(' '))
	k = int(input())
	s = input()
	p = 0
	q = 0
	for i in range(0, len(s)):
		if s[i] == 'L':
			p -= 1
		elif s[i] == 'R':
			p += 1
		elif s[i] == 'U':
			q += 1
		elif s[i] == 'D':
			q -= 1
	if p < 0 or p > m or q < 0 or (q > n):
		print('Case ' + str(j + 1) + ': ' + 'DANGER')
	elif p == u and q == v:
		print('Case ' + str(j + 1) + ': ' + 'REACHED')
	else:
		print('Case ' + str(j + 1) + ': ' + 'SOMEWHERE')


for f in range(int(input())):
	(m, n) = list(map(int, input().split()))
	(rx, ry) = list(map(int, input().split()))
	l = int(input())
	s = input()
	x = 0
	y = 0
	for i in s:
		if i == 'U':
			y += 1
		elif i == 'D':
			y -= 1
		elif i == 'R':
			x += 1
		else:
			x -= 1
	if x < 0 or y < 0 or x > m or (y > n):
		print('Case', str(f + 1) + ':', 'DANGER')
	elif x == rx and y == ry:
		print('Case', str(f + 1) + ':', 'REACHED')
	else:
		print('Case', str(f + 1) + ':', 'SOMEWHERE')


for T in range(int(input())):
	(M, N) = list(map(int, input().split()))
	R = list(map(int, input().split()))
	L = int(input())
	S = input()
	loc = [0, 0]
	for i in S:
		if i == 'U':
			loc[1] += 1
		elif i == 'D':
			loc[1] -= 1
		elif i == 'R':
			loc[0] += 1
		else:
			loc[0] -= 1
	if loc[0] < 0 or loc[0] > M or loc[1] < 0 or (loc[1] > N):
		print('Case {}: {}'.format(T + 1, 'DANGER'))
	elif loc == R:
		print('Case {}: {}'.format(T + 1, 'REACHED'))
	else:
		print('Case {}: {}'.format(T + 1, 'SOMEWHERE'))


for j in range(int(input())):
	(m, n) = list(map(int, input().split()))
	(X, Y) = list(map(int, input().split()))
	l = int(input())
	s = input()
	x = 0
	y = 0
	for i in s:
		if i == 'L':
			x = x - 1
		elif i == 'R':
			x = x + 1
		elif i == 'U':
			y = y + 1
		else:
			y = y - 1
	if x == X and y == Y:
		print(f'Case {j + 1}: REACHED')
	elif x > m or x < 0 or y < 0 or (y > n):
		print(f'Case {j + 1}: DANGER')
	else:
		print(f'Case {j + 1}: SOMEWHERE')


t = int(input())
for j in range(t):
	(m, n) = map(int, input().split(' '))
	(rx, ry) = map(int, input().split(' '))
	steps = int(input())
	route = input()
	rak = [0, 0]
	for i in range(steps):
		if route[i] == 'L':
			rak[0] -= 1
		elif route[i] == 'R':
			rak[0] += 1
		elif route[i] == 'U':
			rak[1] += 1
		elif route[i] == 'D':
			rak[1] -= 1
	if rak[0] == rx and rak[1] == ry:
		print('Case ' + str(j + 1) + ': ' + 'REACHED')
	elif rak[0] > m or rak[0] < 0 or rak[1] < 0 or (rak[1] > n):
		print('Case ' + str(j + 1) + ': ' + 'DANGER')
	else:
		print('Case ' + str(j + 1) + ': ' + 'SOMEWHERE')


j = 0
for _ in range(int(input())):
	(m, n) = map(int, input().split())
	(rx, ry) = map(int, input().split())
	l = int(input())
	s = input()
	x = 0
	y = 0
	for i in range(l):
		if s[i] == 'U':
			y += 1
		elif s[i] == 'D':
			y -= 1
		elif s[i] == 'L':
			x -= 1
		elif s[i] == 'R':
			x += 1
	j = j + 1
	print('Case ' + str(j) + ': ', end='')
	if x == rx and y == ry:
		print('REACHED')
	elif x < 0 or x > rx:
		print('DANGER')
	elif y < 0 or y > ry:
		print('DANGER')
	else:
		print('SOMEWHERE')


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	(rx, ry) = map(int, input().split())
	x = 0
	y = 0
	num = int(input())
	s = input()
	for j in s:
		if j == 'U':
			y = y + 1
		elif j == 'D':
			y = y - 1
		elif j == 'R':
			x = x + 1
		elif j == 'L':
			x = x - 1
	if x == rx and y == ry:
		print('Case ' + str(i + 1) + ': REACHED')
	elif x != rx and y != ry and (x <= m) and (y <= n) and (x > 0) and (y > 0):
		print('Case ' + str(i + 1) + ': SOMEWHERE')
	elif x > m or y > n or x < 0 or (y < 0):
		print('Case ' + str(i + 1) + ': DANGER')


t = int(input())
q = 0
while t:
	q += 1
	t -= 1
	(m, n) = input().split()
	m = int(m)
	n = int(n)
	(rx, ry) = input().split()
	rx = int(rx)
	ry = int(ry)
	l = int(input())
	a = input().split()
	a = str(a)
	x = y = 0
	for i in range(2, l + 2):
		if a[i] == 'L':
			x -= 1
		elif a[i] == 'R':
			x += 1
		if a[i] == 'U':
			y += 1
		elif a[i] == 'D':
			y -= 1
	if x == rx and y == ry:
		print('Case ' + str(q) + ': REACHED')
	elif (x > m or x < 0) or (y < 0 or y > n):
		print('Case ' + str(q) + ': DANGER')
	else:
		print('Case ' + str(q) + ': SOMEWHERE')