#include <iostream>
#include <vector>
using namespace std;
const int INF = 10000000;
const string GAYBRASH = "GAYBRASH";
const string LICHACK = "LICHACK";
struct node{
int x;
int y;
};
vector<node> getChildrenBFS(char ** map, node parent, string hero){
string bannedChars = "R";
if(hero == LICHACK) bannedChars.push_back('e');
vector<node> children;
node leftChild = {parent.x - 1, parent.y};
node rightChild = {parent.x + 1, parent.y};
node downChild = {parent.x, parent.y + 1};
node upChild = {parent.x, parent.y - 1};
if(bannedChars.find(map[leftChild.y][leftChild.x]) == string::npos){
children.push_back(leftChild);
}
if(bannedChars.find(map[rightChild.y][rightChild.x]) == string::npos){
children.push_back(rightChild);
}
if(bannedChars.find(map[downChild.y][downChild.x]) == string::npos){
children.push_back(downChild);
}
if(bannedChars.find(map[upChild.y][upChild.x]) == string::npos){
children.push_back(upChild);
}
return children;
}
void dfsSecondPlayer(char ** map, int ** moves, string hero, node currentNode, int move){
moves[currentNode.y][currentNode.x] = move;
move++;
vector<node> children = getChildrenBFS(map, currentNode, hero);
vector<node> queue;
for(auto e: children) {
if (move < moves[e.y][e.x]) {
dfsSecondPlayer(map, moves, hero, e, move);
}
}
}
void dfsFirstPlayer(char ** map, int ** moves, int ** secondPlayer, string hero, node currentNode, int move){
moves[currentNode.y][currentNode.x] = move;
move++;
vector<node> children = getChildrenBFS(map, currentNode, hero);
vector<node> queue;
for(auto e: children){
if(move < moves[e.y][e.x] && move < secondPlayer[e.y][e.x]){
dfsFirstPlayer(map, moves, secondPlayer, hero, e, move);
}
}
}
int main() {
int tests;
cin >> tests;
for(; tests > 0; tests--){
int m;
int n;
cin >> m >> n;
cin.ignore();
node g;
node l;
node e;
char **map = new char*[m];
for(int i = 0; i < m; i++){
map[i] = new char[n];
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
map[i][j] = cin.get();
switch(map[i][j]){
case 'g':
g.x = j;
g.y = i;
break;
case 'l':
l.x = j;
l.y = i;
break;
case 'e':
e.x = j;
e.y = i;
break;
}
}
cin.ignore();
}
int **liChack = new int*[m];
for(int i = 0; i < m; i++){
liChack[i] = new int[n];
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
liChack[i][j] = INF;
}
}
dfsSecondPlayer(map, liChack, LICHACK, l, 0);
int **gaybrash = new int*[m];
for(int i = 0; i < m; i++){
gaybrash[i] = new int[n];
}
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
gaybrash[i][j] = INF;
}
}
dfsFirstPlayer(map, gaybrash, liChack, GAYBRASH, g, 0);
bool OK = gaybrash[e.y][e.x] != INF;
cout << (OK ? "YES" : "NO") << endl;
for(int i = 0; i < m; i++){
delete[] map[i];
}
delete[] map;
for(int i = 0; i < m; i++){
delete[] gaybrash[i];
}
delete[] gaybrash;
for(int i = 0; i < m; i++){
delete[] liChack[i];
}
delete[] liChack;
}
return 0;
}