You are given an array a of n points in k-dimensional space. Let the distance between two points a_x and a_y be ∑ _{i = 1}^{k} |a_{x, i} - a_{y, i}| (it is also known as Manhattan distance).

You have to process q queries of the following two types:

  * 1 i b_1 b_2 ... b_k — set i-th element of a to the point (b_1, b_2, ..., b_k);
  * 2 l r — find the maximum distance between two points a_i and a_j, where l ≤ i, j ≤ r.

Input

The first line contains two numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 5) — the number of elements in a and the number of dimensions of the space, respectively.

Then n lines follow, each containing k integers a_{i, 1}, a_{i, 2}, ..., a_{i, k} (-10^6 ≤ a_{i, j} ≤ 10^6) — the coordinates of i-th point.

The next line contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Then q lines follow, each denoting a query. There are two types of queries:

  * 1 i b_1 b_2 ... b_k (1 ≤ i ≤ n, -10^6 ≤ b_j ≤ 10^6) — set i-th element of a to the point (b_1, b_2, ..., b_k);
  * 2 l r (1 ≤ l ≤ r ≤ n) — find the maximum distance between two points a_i and a_j, where l ≤ i, j ≤ r.



There is at least one query of the second type.

Output

Print the answer for each query of the second type.

Example

Input


5 2
1 2
2 3
3 4
4 5
5 6
7
2 1 5
2 1 3
2 3 5
1 5 -1 -2
2 1 5
1 4 -1 -2
2 1 5


Output


8
4
4
12
10
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GMultidimensionalQueries solver = new GMultidimensionalQueries();
        solver.solve(1, in, out);
        out.close();
    }

    static class GMultidimensionalQueries {
        private int get(int[] p, int mask) {
            int toRet = 0;
            for (int i = 0; i < p.length; i++) {
                toRet += p[i] * ((mask & 1 << i) != 0 ? -1 : 1);
            }
            return toRet;
        }

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[][] arr = new int[n][k];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < k; j++)
                    arr[i][j] = sc.nextInt();
            }
            int N = 1;
            while (N < n)
                N <<= 1;
            SegmentTree[] trees = new SegmentTree[1 << k];
            for (int i = 0; i < 1 << k; i++) {
                int[] temp = new int[N + 1];
                for (int j = 0; j < n; j++)
                    temp[j + 1] = get(arr[j], i);
                trees[i] = new SegmentTree(temp);
            }
            int q = sc.nextInt();
            while (q-- > 0) {
                int type = sc.nextInt();
                if (type == 2) {
                    long max = 0;
                    int l = sc.nextInt(), r = sc.nextInt();
                    for (int i = 0; i < (1 << k); i++) {
                        int temp = trees[i].query(l, r);
                        int temp2 = trees[((1 << k) - 1) ^ i].query(l, r);
                        max = Math.max(max, temp + temp2);
                    }
                    pw.println(max);
                } else {
                    int idx = sc.nextInt();
                    int[] temp = new int[k];
                    for (int i = 0; i < k; i++)
                        temp[i] = sc.nextInt();
                    for (int i = 0; i < 1 << k; i++) {
                        trees[i].update_point(idx, get(temp, i));
                    }
                }
            }
        }

        public class SegmentTree {
            int N;
            int[] array;
            int[] max;

            SegmentTree(int[] in) {
                array = in;
                N = in.length - 1;
                max = new int[N << 1];        //no. of nodes = 2*N - 1, we add one to cross out index zero
                build(1, 1, N);
            }

            void build(int node, int b, int e) {
                if (b == e) {
                    max[node] = array[e];
                } else {
                    int mid = b + e >> 1;
                    build(node << 1, b, mid);
                    build(node << 1 | 1, mid + 1, e);
                    max[node] = Math.max(max[node << 1], max[node << 1 | 1]);
                }
            }

            void update_point(int index, int val) {
                array[index] = val;
                index += N - 1;
                max[index] = val;
                while (index > 1) {
                    index >>= 1;
                    max[index] = Math.max(max[index << 1], max[index << 1 | 1]);
                }
            }

            int query(int i, int j) {
                return query(1, 1, N, i, j);
            }

            int query(int node, int b, int e, int i, int j) {
                if (i > e || j < b)
                    return (int) -1e9;
                if (b >= i && e <= j)
                    return max[node];
                int mid = b + e >> 1;
                int q1 = query(node << 1, b, mid, i, j);
                int q2 = query(node << 1 | 1, mid + 1, e, i, j);
                return Math.max(q1, q2);
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

