---
category_name: school
problem_code: ZUBREACH
problem_name: 'J - Reached Safely Or Not'
languages_supported:
- C
- CPP14
- JAVA
- PYTH
- 'PYTH 3.5'
- PYPY
max_timelimit: '1'
source_sizelimit: '50000'
problem_author: zubaerkh
problem_tester: null
date_added: 5-11-2017
tags:
- zubaerkh
time:
view_start_date: 1517085000
submit_start_date: 1517085000
visible_start_date: 1517085000
end_date: 1735669800
current: 1525198931
is_direct_submittable: false
layout: problem
---
All submissions for this problem are available.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
<pre><b>Input:</b>
2
20 20
4 5
13
LLUUUUURRRRRR
10 10
3 4
7
UDUDDRR
<b>Output:</b>
Case 1: REACHED
Case 2: DANGER
</pre>