public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		do {
			line = in.readLine();
			if (line == null || line.length() == 0)
				break;
			int[] nn = retInts(line);
			SegTree[] st = new SegTree[nn[0]];
			String[] d;
			for (int i = 0; i < nn[0]; i++) {
				d = in.readLine().trim().split(" ");
				st[i] = new SegTree(1, nn[1]);
				for (int j = 0; j < d.length; j++) 
					st[i].set(j+1, Integer.parseInt(d[j]));
			}
			int q = Integer.parseInt(in.readLine());
			for (int i = 0; i < q; i++) {
				d = in.readLine().trim().split(" ");
				if(d[0].equals("q")){
					int x0 = Integer.parseInt(d[1]);
					int y0 = Integer.parseInt(d[2]);
					int x1 = Integer.parseInt(d[3]);
					int y1 = Integer.parseInt(d[4]);
					long max = Long.MIN_VALUE;
					long min = Long.MAX_VALUE;
					for (int j = x0; j <= x1; j++) {
						max = Math.max(max, st[j-1].getMax(y0, y1));
						min = Math.min(min, st[j-1].getMin(y0, y1));
					}
					out.append(max+" "+min+"\n");
				}else{
					int x = Integer.parseInt(d[1]);
					int y = Integer.parseInt(d[2]);
					int v = Integer.parseInt(d[3]);
					st[x-1].set(y, v);
				}
			}
		} while (line != null && line.length() != 0);
		System.out.print(out);
	}