Problem: Like all children, Alesha loves New Year celebration. During the celebration he and his whole family dress up the fir-tree. Like all children, Alesha likes to play with garlands — chains consisting of a lightbulbs.

Alesha uses a grid field sized n × m for playing. The rows of the field are numbered from 1 to n from the top to the bottom and columns are numbered from 1 to m from the left to the right.

Alesha has k garlands which he places at the field. He does so in the way such that each lightbulb of each garland lies in the center of some cell in the field, and each cell contains at most one lightbulb. Of course lightbulbs, which are neighbours in some garland, appears in cells neighbouring by a side.

<image>

The example of garland placing.

Each garland is turned off or turned on at any moment. If some garland is turned on then each of its lightbulbs is turned on, the same applies for garland turned off. Each lightbulb in the whole garland set is unique, and thus, being turned on, brings Alesha some pleasure, described by an integer value. Turned off lightbulbs don't bring Alesha any pleasure.

Alesha can turn garlands on and off and wants to know the sum of pleasure value which the lightbulbs, placed in the centers of the cells in some rectangular part of the field, bring him. Initially all the garlands are turned on.

Alesha is still very little and can't add big numbers. He extremely asks you to help him.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m, k ≤ 2000) — the number of field rows, the number of field columns and the number of garlands placed at the field respectively.

Next lines contains garlands set description in the following format:

The first line of a single garland description contains a single integer len (1 ≤ len ≤ 2000) — the number of lightbulbs in the garland.

Each of the next len lines contains three integers i, j and w (1 ≤ i ≤ n, 1 ≤ j ≤ m, 1 ≤ w ≤ 109) — the coordinates of the cell containing a lightbullb and pleasure value Alesha gets from it if it is turned on. The lightbulbs are given in the order they are forming a chain in the garland. It is guaranteed that neighbouring lightbulbs are placed in the cells neighbouring by a side.

The next line contains single integer q (1 ≤ q ≤ 106) — the number of events in Alesha's game. The next q lines describes events in chronological order. The i-th of them describes the i-th event in the one of the following formats:

  * SWITCH i — Alesha turns off i-th garland if it is turned on, or turns it on if it is turned off. It is guaranteed that 1 ≤ i ≤ k. 
  * ASK x1 y1 x2 y2 — Alesha wants to know the sum of pleasure values the lightbulbs, placed in a rectangular part of the field. Top-left cell of a part has coordinates (x1, y1) and right-bottom cell has coordinates (x2, y2). It is guaranteed that 1 ≤ x1 ≤ x2 ≤ n and 1 ≤ y1 ≤ y2 ≤ m. There is no more than 2000 events of this type in the input. 



All the numbers in the input are integers.

Please note that the input is quite large, so be careful while using some input ways. In particular, it's not recommended to use cin in codes on C++ and class Scanner in codes on Java.

Output

For each ASK operation print the sum Alesha wants to know in a separate line. Print the answers in chronological order.

Examples

Input

4 4 3
5
1 1 2
1 2 3
2 2 1
2 1 4
3 1 7
4
1 3 1
2 3 3
2 4 3
1 4 1
7
4 1 1
4 2 9
3 2 8
3 3 3
4 3 4
4 4 1
3 4 1
2
ASK 2 2 3 3
ASK 1 1 4 4


Output

15
52


Input

4 4 1
8
4 1 1
3 1 2
2 1 1
1 1 7
1 2 5
2 2 4
2 3 1
1 3 1
3
ASK 1 1 3 2
SWITCH 1
ASK 1 1 3 2


Output

19
0

Note

<image>

This image illustrates the first sample case.

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        ConsoleIO io = new ConsoleIO();
        new Main(io).solve();
        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ArrayList<ArrayList<Integer>> gr;

    long MOD = 1_000_000_007;
    int N, M, Q;


    boolean[] swi;
    int[][] gar;
    int[][] val;
    long[] bigVals;
    int[][][] exist;
    List<Pair>[] squaresPerG;

    public void solve() {
        N = io.ri();
        M = io.ri();
        int K = io.ri();

        int thresN = (int)Math.sqrt(N);
        int thresM = (int)Math.sqrt(M);
        int sizeN = N/thresN, sizeM = M/thresM;
        bigVals = new long[sizeN * sizeM];
        squaresPerG = new List[K];

        swi  = new boolean[K];
        Arrays.fill(swi,true);
        gar = new int[N][M];
        val = new int[N][M];

        for (int i = 0; i < K; i++) {
            int len = io.ri();
            for (int j = 0; j < len; j++) {
                int x = io.ri() - 1;
                int y = io.ri() - 1;
                gar[x][y] = i + 1;
                int w = io.ri();
                val[x][y] = w;
                int bx = x / thresN;
                int by = y / thresM;
                List<Pair> lp = squaresPerG[i];
                if (lp == null)
                    lp = squaresPerG[i] = new ArrayList<>();
                if (bx < sizeN && by < sizeM) {
                    bigVals[bx * sizeM + by] += w;
                    boolean ex = false;
                    int z = bx*sizeM+by;
                    for (Pair t : lp) {
                        if (t.a == z) {
                            t.b += w;
                            ex = true;
                            break;
                        }
                    }
                    if (!ex) {
                        lp.add(new Pair(z, w));
                    }
                }
            }
        }

        Q = io.ri();
        StringBuilder sb = new StringBuilder();
        for (int qq = 0; qq < Q; qq++) {
            char c = io.readSymbol();
            if (c == 'S') {
                int k = io.ri()-1;
                List<Pair> lp = squaresPerG[k];
                swi[k] ^= true;
                boolean need = swi[k];
                for(int i = 0;i<lp.size();i++) {
                    Pair p = lp.get(i);
                    if (need)
                        bigVals[p.a] += p.b;
                    else
                        bigVals[p.a] -= p.b;
                }
            } else {
                int x1 = io.ri() - 1;
                int y1 = io.ri() - 1;
                int x2 = io.ri() - 1;
                int y2 = io.ri() - 1;

                int sx = (x1 + thresN - 1) / thresN;
                int sy = (y1 + thresM - 1) / thresM;
                int tx = (x2 + 1) / thresN;
                int ty = (y2 + 1) / thresM;

                long cur = 0;
                for (int i = sx; i < tx; i++) {
                    int t = i*sizeM+ty;
                    for (int j = i*sizeM+sy; j < t; j++) {
                        cur += bigVals[j];
                    }
                }

                int csx = sx * thresN;
                int ctx = tx * thresN - 1;
                int csy = sy * thresM;
                int cty = ty * thresM - 1;

                for (int i = x1; i <= x2; i++) {
                    int[] te = gar[i];
                    int[] ve = val[i];
                    for (int j = y1; j <= y2; j++) {
                        if (i >= csx && i <= ctx && j >= csy && j <= cty) {
                            j = cty;
                            continue;
                        }
                        int k = te[j] - 1;
                        if (k >= 0 && swi[k])
                            cur += ve[j];
                    }
                }
                if(sb.length()>0)sb.append(System.lineSeparator());
                sb.append(cur);
            }
        }

        io.writeLine(sb.toString());
    }

}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
    public char readSymbol() {
        try {
            while (true) {
                int c = br.read();
                if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
                    return (char) c;
                }
            }
        } catch (Exception ex) {
            return 0;
        }
    }
    public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}
}
class Pair {
    public Pair(int a, long b) {this.a = a;this.b = b;}
    public int a;
    public long b;
}
class Tri {
    public Tri(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}