import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
public class Main{
private static class Node {
private int i;
private int j;
private Node(int i, int j) {
this.i = i;
this.j = j;
}
}
private static void fill(int[][] a, int value) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
a[i][j] = value;
}
}
}
private static void bfsSecondPlayer(char[][] map, int[][] moves, Node start) {
Queue<Node> queue = new LinkedList<>();
moves[start.i][start.j] = 0;
queue.add(start);
while (!queue.isEmpty()) {
Node curNode = queue.poll();
int i = curNode.i;
int j = curNode.j;
if (i > 0 && map[i - 1][j] != 'R' && map[i - 1][j] != 'e' && moves[i][j] + 1 < moves[i - 1][j]) {
moves[i - 1][j] = moves[i][j] + 1;
queue.add(new Node(i - 1, j));
}
if (i < moves.length - 1 && map[i + 1][j] != 'R' && map[i + 1][j] != 'e' && moves[i][j] + 1 < moves[i + 1][j]) {
moves[i + 1][j] = moves[i][j] + 1;
queue.add(new Node(i + 1, j));
}
if (j > 0 && map[i][j - 1] != 'R' && map[i][j - 1] != 'e' && moves[i][j] + 1 < moves[i][j - 1]) {
moves[i][j - 1] = moves[i][j] + 1;
queue.add(new Node(i, j - 1));
}
if (i < moves[0].length - 1 && map[i][j + 1] != 'R' && map[i][j + 1] != 'e' && moves[i][j] + 1 < moves[i][j + 1]) {
moves[i][j + 1] = moves[i][j] + 1;
queue.add(new Node(i, j + 1));
}
}
}
private static boolean bfsFirstPlayer(char[][] map, int[][] moves, int[][] secondPlayerMoves, Node start) {
Queue<Node> queue = new LinkedList<>();
queue.add(start);
moves[start.i][start.j] = 0;
while (!queue.isEmpty()) {
Node curNode = queue.poll();
int i = curNode.i;
int j = curNode.j;
if (map[i][j] == 'e') {
return true;
}
if (i
> 0 && map
[i
- 1][j
] != 'R' && moves
[i
][j
] + 1 < Math.
min(moves
[i
- 1][j
], secondPlayerMoves
[i
- 1][j
])) { moves[i - 1][j] = moves[i][j] + 1;
queue.add(new Node(i - 1, j));
}
if (i
< moves.
length - 1 && map
[i
+ 1][j
] != 'R' && moves
[i
][j
] + 1 < Math.
min(moves
[i
+ 1][j
], secondPlayerMoves
[i
+ 1][j
])) { moves[i + 1][j] = moves[i][j] + 1;
queue.add(new Node(i + 1, j));
}
if (j
> 0 && map
[i
][j
- 1] != 'R' && moves
[i
][j
] + 1 < Math.
min(moves
[i
][j
- 1], secondPlayerMoves
[i
][j
- 1])) { moves[i][j - 1] = moves[i][j] + 1;
queue.add(new Node(i, j - 1));
}
if (i
< moves
[0].
length - 1 && map
[i
][j
+ 1] != 'R' && moves
[i
][j
] + 1 < Math.
min(moves
[i
][j
+ 1], secondPlayerMoves
[i
][j
+ 1])) { moves[i][j + 1] = moves[i][j] + 1;
queue.add(new Node(i, j + 1));
}
}
return false;
}
int tests
= Integer.
parseInt(bufferedReader.
readLine()); for (int r = 0; r < tests; r++) {
String[] sizes
= bufferedReader.
readLine().
split(" "); int n
= Integer.
parseInt(sizes
[0]); int m
= Integer.
parseInt(sizes
[1]); char[][] map = new char[n][m];
Node g = null;
Node l = null;
Node e = null;
for (int i = 0; i < n; i++) {
map[i] = bufferedReader.readLine().toCharArray();
for (int j = 0; j < m; j++) {
if (map[i][j] == 'g') {
g = new Node(i, j);
}
else if (map[i][j] == 'l') {
l = new Node(i, j);
}
else if (map[i][j] == 'e') {
e = new Node(i, j);
}
}
}
int[][] secondPlayerDistances = new int[n][m];
fill
(secondPlayerDistances,
Integer.
MAX_VALUE); bfsSecondPlayer(map, secondPlayerDistances, l);
int[][] firstPlayerDistances = new int[n][m];
fill
(firstPlayerDistances,
Integer.
MAX_VALUE); boolean ok = bfsFirstPlayer(map, firstPlayerDistances, secondPlayerDistances, g);
System.
out.
println(ok
? "YES" : "NO"); }
}
}