#include<iostream>
#include<vector>
using namespace std;

int main() {
/*******입력*******/
int T;//테스트케이스
int N, M, x, y;
cin >> T;

for (int a = 0; a < T; a++)
{
	cin >> N >> M >> x >> y;
	int map[501][501];
	int data;
	for (int i = 1; i <= M; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			cin >> data;
			map[i][j] = data;
		}
	}

	int k;//회전판 갯수
	cin >> k;
	int plate[8];
	for (int i = 0; i < k; i++)
	{
		cin >> data;
		plate[i] = data;
	}

	int ans = map[y][x];
	map[y][x] = 0;
	int L;//로봇이 움직이는 횟수
	cin >> L;
	char moveD;// 이동방향(E,W,S,N)
	int rotD, rotN;// 회전방향(1,2) , 회전 칸
	int xx, yy, rr = 0;

	for (int i = 0; i < L; i++)
	{
		cin >> moveD >> rotD >> rotN;
		//회전판
		if (rotD == 1)
		{
			rr = (rr + k - rotN) % k;
		}
		else if (rotD == 2)
		{
			rr = (rr + rotN) % k;
		}

		//좌표이동
		if (moveD == 'E') {
			xx = 1;
			yy = 0;
		}
		else if (moveD == 'W') {
			xx = -1;
			yy = 0;
		}
		else if (moveD == 'S') {
			xx = 0;
			yy = 1;
		}
		else if (moveD == 'N') {
			xx = 0;
			yy = -1;
		}
		for (int j = 0; j < plate[rr]; j++)
		{
			y += yy;
			x += xx;
			if (map[y][x] == -1 || y > M || y<0 || x > N || x < 0)
			{
				y -= yy;
				x -= xx;
				break;
			}
			else
			{
				ans += map[y][x];
				map[y][x] = 0;
			}
		}
	}

	cout << "#" << a + 1 << " " << ans << " " << x << " " << y<<endl;
}
return 0;
}