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.util.InputMismatchException;
import java.io.IOException;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[][] tMin = new int[1 << (k - 1)][2 * n];
            for (int i = 0; i < 1 << (k - 1); i++) Arrays.fill(tMin[i], Integer.MAX_VALUE);
            int[][] tMax = new int[1 << (k - 1)][2 * n];
            for (int i = 0; i < 1 << (k - 1); i++) Arrays.fill(tMax[i], Integer.MIN_VALUE);
            int[] a = new int[k];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < k; j++) {
                    a[j] = in.nextInt();
                }
                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];
                    }
                    setMin(tMin[mask], i, v);
                    setMax(tMax[mask], i, v);
                }
            }
            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int cmd = in.nextInt();
                if (cmd == 1) {
                    int pos = in.nextInt() - 1;
                    for (int j = 0; j < k; j++) {
                        a[j] = in.nextInt();
                    }
                    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];
                        }
                        setMin(tMin[mask], pos, v);
                        setMax(tMax[mask], pos, v);
                    }
                } else {
                    int l = in.nextInt() - 1;
                    int r = in.nextInt() - 1;
                    int res = 0;
                    for (int mask = 0; mask < 1 << (k - 1); mask++) {
                        int cur = max(tMax[mask], l, r) - min(tMin[mask], l, r);
                        res = Math.max(res, cur);
                    }
                    out.println(res);
                }
            }
        }

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

        static int max(int[] t, int a, int b) {
            int res = Integer.MIN_VALUE;
            for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
                if ((a & 1) != 0)
                    res = Math.max(res, t[a]);
                if ((b & 1) == 0)
                    res = Math.max(res, t[b]);
            }
            return res;
        }

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

        static int min(int[] t, int a, int b) {
            int res = Integer.MAX_VALUE;
            for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
                if ((a & 1) != 0)
                    res = Math.min(res, t[a]);
                if ((b & 1) == 0)
                    res = Math.min(res, t[b]);
            }
            return res;
        }

    }

    static class InputReader {
        final InputStream is;
        final byte[] buf = new byte[1024];
        int pos;
        int size;

        public InputReader(InputStream is) {
            this.is = is;
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res = res * 10 + c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sign;
        }

        int read() {
            if (size == -1)
                throw new InputMismatchException();
            if (pos >= size) {
                pos = 0;
                try {
                    size = is.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (size <= 0)
                    return -1;
            }
            return buf[pos++] & 255;
        }

        static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

