public static void main(String[] args) throws Throwable {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
		String line = in.readLine();
		for ( ; line!=null; ) {
			int n = Integer.parseInt(line);
			if(n==0)break;
			vAx = new ArrayList<Integer>();
			vAy = new ArrayList<Integer>();
			vAs = new ArrayList<Integer>();
			vDx = new ArrayList<Integer>();
			vDy = new ArrayList<Integer>();
			vDs = new ArrayList<Integer>();
			m = new String[n][n];
			for (int i = 0; i < n; i++) {
				line = in.readLine();
				for (int j = 0; j < line.length(); j++) {
					m[i][j] = line.charAt(j)+"";
					if(m[i][j].equals(".")) dot++;
				}
			}
			in.readLine();
			for ( ;(line=in.readLine())!=null && !line.equals("Down"); ) {
				StringTokenizer st = new StringTokenizer(line);
				int y = (Integer.parseInt(st.nextToken()))-1;
				int x = (Integer.parseInt(st.nextToken()))-1;
				int sum = Integer.parseInt(st.nextToken());
				vAx.add(x);
				vAy.add(y);
				vAs.add(sum);
			}
			for ( ;(line=in.readLine())!=null && line.trim().contains(" "); ) {
				StringTokenizer st = new StringTokenizer(line);
				int y = Integer.parseInt(st.nextToken())-1;
				int x = Integer.parseInt(st.nextToken())-1;
				int sum = Integer.parseInt(st.nextToken());
				vDx.add(x);
				vDy.add(y);
				vDs.add(sum);
			}
			solve( );
			imprimir();
		}
		System.out.print(new String(sb));
	}