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.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
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;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GMultidimensionalQueries solver = new GMultidimensionalQueries();
        solver.solve(1, in, out);
        out.close();
    }

    static class GMultidimensionalQueries {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int k = in.scanInt();
            MinSeg tMin[] = new MinSeg[1 << (k - 1)];
            for (int i = 0; i < 1 << (k - 1); i++) tMin[i] = new MinSeg(n);
            MaxSeg tMax[] = new MaxSeg[1 << (k - 1)];
            for (int i = 0; i < 1 << (k - 1); i++) tMax[i] = new MaxSeg(n);


            int[] a = new int[k];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < k; j++) a[j] = in.scanInt();
                for (int mask = 0; mask < 1 << (k - 1); mask++) {
                    int v = a[k - 1];
                    for (int j = 0; j < k - 1; j++) v += (mask & (1 << j)) != 0 ? a[j] : -a[j];
                    tMin[mask].setMin(i, v);
                    tMax[mask].setMax(i, v);
                }
            }

            int q = in.scanInt();
            while (q-- > 0) {
                int type = in.scanInt();
                if (type == 1) {
                    int pp = in.scanInt() - 1;
                    for (int j = 0; j < k; j++) a[j] = in.scanInt();
                    for (int mask = 0; mask < 1 << (k - 1); mask++) {
                        int v = a[k - 1];
                        for (int j = 0; j < k - 1; j++) v += (mask & (1 << j)) != 0 ? a[j] : -a[j];
                        tMin[mask].setMin(pp, v);
                        tMax[mask].setMax(pp, v);
                    }
                } else {
                    int l = in.scanInt() - 1;
                    int r = in.scanInt() - 1;
                    int res = 0;
                    for (int mask = 0; mask < 1 << (k - 1); mask++) {
                        int cur = tMax[mask].max(l, r) - tMin[mask].min(l, r);
                        res = Math.max(res, cur);
                    }
                    out.println(res);
                }
            }


        }

    }

    static class MaxSeg {
        int[] tree;
        int n;

        public MaxSeg(int n) {
            this.n = n;
            tree = new int[2 * n];
            Arrays.fill(tree, Integer.MIN_VALUE);
        }

        public void setMax(int i, int value) {
            i += this.tree.length / 2;
            this.tree[i] = value;
            for (; i > 1; i >>= 1)
                this.tree[i >> 1] = Math.max(this.tree[i], this.tree[i ^ 1]);
        }

        public int max(int a, int b) {
            int res = Integer.MIN_VALUE;
            for (a += this.tree.length / 2, b += this.tree.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
                res = Math.max(res, this.tree[a]);
                res = Math.max(res, this.tree[b]);
            }
            return res;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }

    static class MinSeg {
        int[] tree;
        int n;

        public MinSeg(int n) {
            this.n = n;
            tree = new int[2 * n];
            Arrays.fill(tree, Integer.MAX_VALUE);
        }

        public void setMin(int i, int value) {
            i += this.tree.length / 2;
            this.tree[i] = value;
            for (; i > 1; i >>= 1)
                this.tree[i >> 1] = Math.min(this.tree[i], this.tree[i ^ 1]);
        }

        public int min(int a, int b) {
            int res = Integer.MAX_VALUE;
            for (a += this.tree.length / 2, b += this.tree.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
                res = Math.min(res, this.tree[a]);
                res = Math.min(res, this.tree[b]);
            }
            return res;
        }

    }
}

