PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000235. XOR hình chữ nhật tĩnh (Static Rectangle XOR)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

XOR hình chữ nhật tĩnh (Static Rectangle XOR)

Static Rectangle XOR

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a static n×mn\times m matrix of nonnegative integers, each query (r1,c1,r2,c2)(r_1,c_1,r_2,c_2) asks for the bitwise XOR of all cells in the inclusive rectangle. Indices are 1-based.

Input

The first line contains n,m,Qn,m,Q, followed by nn rows of mm integers and QQ lines of r1,c1,r2,c2r_1,c_1,r_2,c_2.

Output

Print one rectangle XOR per query.

Subtasks

  • Subtask 1 (30 points): 1≤n,m≤301\le n,m\le 30; nm≤300000nm\le300000; 0≤ai,j<2300\le a_{i,j}<2^{30}; 1≤Q≤301\le Q\le 30; 1≤r1≤r2≤n1\le r_1\le r_2\le n; 1≤c1≤c2≤m1\le c_1\le c_2\le m.
  • Subtask 2 (30 points): 1≤n,m≤7001\le n,m\le 700; nm≤300000nm\le300000; 0≤ai,j<2300\le a_{i,j}<2^{30}; 1≤Q≤2000001\le Q\le 200000; 1≤r1≤r2≤n1\le r_1\le r_2\le n; 1≤c1≤c2≤m1\le c_1\le c_2\le m; n=mn=m.
  • Subtask 3 (40 points): 1≤n,m≤7001\le n,m\le 700; nm≤300000nm\le300000; 0≤ai,j<2300\le a_{i,j}<2^{30}; 1≤Q≤2000001\le Q\le 200000; 1≤r1≤r2≤n1\le r_1\le r_2\le n; 1≤c1≤c2≤m1\le c_1\le c_2\le m.

Example 1

Input

2 2 1
1 2
3 4
1 1 2 2

Output

4

Explanation

The full rectangle XOR is 1 XOR 2 XOR 3 XOR 4 = 4.

Example 2

Input

1 3 2
7 7 0
1 1 1 2
1 2 1 2

Output

0
7

Explanation

The two sevens cancel; the second query contains a single seven.