#include#include #include #include #define Max_len 101 using namespace std; typedef struct node{ int x; int y; int num; int k; }node; int flag, flag1; int m, n, record_k; int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; int visited[Max_len][Max_len]; int pro[Max_len][Max_len]; char map[Max_len][Max_len]; int record[Max_len]; queue temp; void bfs(int x, int y, int z); int is_g(int x, int y); int main(){ int N; int i, k, v, x, y, w, j; node no; scanf("%d", &N); while(N--){ memset(visited, 0, sizeof(visited)); memset(pro, 0, sizeof(pro)); flag = 0; scanf("%d %d", &m, &n); for(i = 0; i < m; i++){ scanf("%s", map[i]); } w = 0; for(i = 0; i < m && !w; i++){ for(j = 0; j < n && !w; j++){ if(map[i][j] == 'y'){ x = i; y = j; w = 1; } } } scanf("%d", &record_k); for(i = 0; i < record_k; i++){ scanf("%d", &record[i]); } no.x = x; no.y = y; no.num = 0; no.k = 0; temp.push(no); v = 0; while(!temp.empty()){ flag1 = 0; memset(visited, 0, sizeof(visited)); no = temp.front(); // printf("%d %d\n", no.x, no.y); bfs(no.x, no.y, no.k); if(flag == 1){ break; } if(no.k < record_k){ temp.pop(); no.k++; // printf("%d %d %d\n", no.x, no.y, no.k); temp.push(no); } else{ temp.pop(); } } if(flag == 1){ printf("good luck!\n"); } else{ printf("poor yzq!\n"); } while(!temp.empty()){ temp.pop(); } } return 0; } int is_g(int x, int y){ if(x >= 0 && y >= 0 && y <= n - 1 && x <= m - 1){ return 1; } else{ return 0; } } void bfs(int x, int y, int k){ node no1, no2; queue q; int i; no1.x = x; no1.y = y; no1.num = 0; q.push(no1); while(!q.empty()){ no1 = q.front(); q.pop(); // printf("%d %d\n", no1.x, no1.y); if(map[no1.x][no1.y] == 'd'){ flag = 1; return; } else if(map[no1.x][no1.y] == '*' && !pro[no1.x][no1.y] && k < record_k){ pro[no1.x][no1.y] = 1; no1.k = k + 1; temp.push(no1); flag1 = 1; } for(i = 0; i < 4; i++){ no2 = no1; no2.x += dir[i][0]; no2.y += dir[i][1]; if(!visited[no2.x][no2.y] && map[no2.x][no2.y] != 'x' && no2.num < record[k] && is_g(no2.x, no2.y) && !pro[no2.x][no2.y]){ no2.num ++; visited[no2.x][no2.y] = 1; q.push(no2); } } } }