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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long val;
  int l, r;
  Node() : l(0), r(0), val(0) {}
  static int alloc() {
    static int ptr = 1;
    return ptr++;
  }
};
Node tree[10000000];
void init(int nod, int l, int r) {
  if (l == r) {
    return;
  }
  int m = (l + r) / 2;
  tree[nod].l = Node::alloc();
  init(tree[nod].l, l, m);
  tree[nod].r = Node::alloc();
  init(tree[nod].r, m + 1, r);
}
void update(int nod, int old, int l, int r, int pos, int val) {
  if (l == r) {
    tree[nod].val = tree[old].val + val;
    return;
  }
  int m = (l + r) / 2;
  if (pos <= m) {
    if (tree[nod].l == 0) {
      tree[nod].l = Node::alloc();
      tree[nod].r = tree[old].r;
    } else if (tree[nod].l == tree[old].l) {
      tree[nod].l = Node::alloc();
    }
    update(tree[nod].l, tree[old].l, l, m, pos, val);
  } else {
    if (tree[nod].r == 0) {
      tree[nod].r = Node::alloc();
      tree[nod].l = tree[old].l;
    } else if (tree[nod].r == tree[old].r) {
      tree[nod].r = Node::alloc();
    }
    update(tree[nod].r, tree[old].r, m + 1, r, pos, val);
  }
  tree[nod].val = tree[tree[nod].l].val + tree[tree[nod].r].val;
}
long long query(int tree1, int tree2, int l, int r, int st, int ed) {
  if (r < st || ed < l) {
    return 0;
  }
  if (st <= l && r <= ed) {
    return tree[tree2].val - tree[tree1].val;
  }
  int m = (l + r) / 2;
  return query(tree[tree1].l, tree[tree2].l, l, m, st, ed) +
         query(tree[tree1].r, tree[tree2].r, m + 1, r, st, ed);
}
struct Garland {
  vector<tuple<int, int, int>> elems;
  int mini, maxi, minj, maxj;
  vector<int> treehead;
  Garland() : mini(3000), minj(3000), maxi(-1), maxj(-1) {}
  void add(int i, int j, int w) {
    elems.emplace_back(i, j, w);
    if (i < mini) mini = i;
    if (j < minj) minj = j;
    if (i > maxi) maxi = i;
    if (j > maxj) maxj = j;
  }
  void make() {
    sort(elems.begin(), elems.end());
    int leaf = maxj - minj + 1;
    treehead.push_back(Node::alloc());
    init(treehead[0], 0, leaf - 1);
    int j = 0;
    for (int i = mini; i <= maxi; ++i) {
      int rowid = i - mini + 1;
      treehead.push_back(Node::alloc());
      while (j < elems.size() && get<0>(elems[j]) == i) {
        update(treehead[rowid], treehead[rowid - 1], 0, leaf - 1,
               get<1>(elems[j]) - minj, get<2>(elems[j]));
        ++j;
      }
    }
  }
  long long sum(int i1, int j1, int i2, int j2) {
    i1 = max(i1, mini);
    i2 = min(i2, maxi);
    j1 = max(j1, minj);
    j2 = min(j2, maxj);
    if (i1 > i2 || j1 > j2) {
      return 0;
    }
    int strow = i1 - mini + 1, edrow = i2 - mini + 1;
    int leaf = maxj - minj + 1;
    return query(treehead[strow - 1], treehead[edrow], 0, leaf - 1, j1 - minj,
                 j2 - minj);
  }
};
Garland gland[2000];
bool status[2000];
int n, m, k, q;
char cmd[20];
void proc() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < k; ++i) {
    int cnt;
    scanf("%d", &cnt);
    gland[i].elems.reserve(cnt + 1);
    for (int j = 0; j < cnt; ++j) {
      int a, b, w;
      scanf("%d %d %d", &a, &b, &w);
      gland[i].add(a, b, w);
    }
    gland[i].make();
    status[i] = true;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%s", cmd);
    if (cmd[0] == 'S') {
      int v;
      scanf("%d", &v);
      --v;
      status[v] = !status[v];
    } else {
      int i1, j1, i2, j2;
      scanf("%d %d %d %d", &i1, &j1, &i2, &j2);
      long long ans = 0;
      for (int p = 0; p < k; ++p) {
        if (status[p] == false) {
          continue;
        }
        ans += gland[p].sum(i1, j1, i2, j2);
      }
      printf("%lld\n", ans);
    }
  }
}
int main() {
  proc();
  return 0;
}