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;
template <class TAT>
inline void read(TAT &a) {
  static char cc;
  static bool f;
  while ((cc = getchar()) != '-' && (cc < '0' || cc > '9'))
    ;
  if (cc == '-')
    f = 1, a = 0;
  else
    f = 0, a = cc - '0';
  while ((cc = getchar()) >= '0' && cc <= '9') a = a * 10 + cc - '0';
  if (f) a = -a;
}
template <class TAT>
inline void write(TAT a) {
  static char cc[27];
  static int ct;
  if (a == 0) {
    putchar('0');
    return;
  }
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  ct = 0;
  while (a) cc[++ct] = a % 10 + '0', a /= 10;
  while (ct) putchar(cc[ct--]);
}
template <class TAT>
inline void Ckmin(TAT &a, const TAT &b) {
  if (a > b) a = b;
}
template <class TAT>
inline void Ckmax(TAT &a, const TAT &b) {
  if (a < b) a = b;
}
void begin() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void end() {
  fclose(stdin);
  fclose(stdout);
}
const int maxn = 2e3 + 115;
int n, m, K, Q;
int bel[maxn][maxn];
int num[maxn][maxn];
struct Point {
  int x, y;
  Point() {}
  Point(int _x, int _y) : x(_x), y(_y) {}
};
struct Link {
  int len;
  int L, R, U, D;
  vector<Point> pos;
  vector<long long> sum;
  long long Getsum(int l, int r) { return sum[r] - sum[l - 1]; }
  bool contain(int L, int R, int U, int D, int x) {
    return (pos[x].x >= U && pos[x].x <= D && pos[x].y >= L && pos[x].y <= R);
  }
} A[maxn];
bool status[maxn];
int app[maxn][maxn], apt[maxn];
void Init() {
  int x, y, z;
  read(n), read(m), read(K);
  for (int i = 1; i <= K; ++i) {
    A[i].L = A[i].U = 2e9;
    A[i].R = A[i].D = -2e9;
    A[i].pos.push_back(Point(0, 0));
    A[i].sum.push_back(0);
    read(A[i].len);
    for (int j = 1; j <= A[i].len; ++j) {
      read(x), read(y), read(z);
      Ckmin(A[i].L, y);
      Ckmax(A[i].R, y);
      Ckmin(A[i].U, x);
      Ckmax(A[i].D, x);
      A[i].pos.push_back(Point(x, y));
      A[i].sum.push_back(A[i].sum[j - 1] + z);
      bel[x][y] = i;
      num[x][y] = j;
    }
  }
  for (int i = 1; i <= K; ++i) status[i] = 1;
}
void Solve() {
  char ch;
  int x, L, R, U, D;
  long long Ans;
  read(Q);
  for (int i = 1; i <= Q; ++i) {
    while ((ch = getchar()) != 'A' && ch != 'S')
      ;
    if (ch == 'S') {
      read(x);
      status[x] ^= 1;
    } else {
      read(U), read(L), read(D), read(R);
      Ans = 0;
      for (int j = 1; j <= K; ++j) {
        if (status[j] == 1) {
          if (U + 1 <= A[j].U && L + 1 <= A[j].L && D - 1 >= A[j].D &&
              R - 1 >= A[j].R) {
            Ans += A[j].sum[A[j].len];
          }
        }
      }
      memset(apt, 0, sizeof(apt));
      for (int j = U; j <= D; ++j) {
        if (bel[j][L]) app[bel[j][L]][++apt[bel[j][L]]] = num[j][L];
        if (R != L) {
          if (bel[j][R]) app[bel[j][R]][++apt[bel[j][R]]] = num[j][R];
        }
      }
      for (int j = L + 1; j <= R - 1; ++j) {
        if (bel[U][j]) app[bel[U][j]][++apt[bel[U][j]]] = num[U][j];
        if (U != D) {
          if (bel[D][j]) app[bel[D][j]][++apt[bel[D][j]]] = num[D][j];
        }
      }
      for (int j = 1; j <= K; ++j) {
        if (status[j] && apt[j]) {
          int *t, total;
          t = app[j];
          total = apt[j];
          sort(t + 1, t + 1 + total);
          if (t[1] > 1) {
            if (A[j].contain(L, R, U, D, 1)) {
              Ans += A[j].Getsum(1, t[1] - 1);
            }
          }
          for (int k = 1; k < total; ++k) {
            assert(t[k] != t[k + 1]);
            if (t[k] + 1 != t[k + 1]) {
              if (A[j].contain(L, R, U, D, t[k] + 1)) {
                Ans += A[j].Getsum(t[k] + 1, t[k + 1] - 1);
              }
            }
          }
          if (t[total] < A[j].len) {
            if (A[j].contain(L, R, U, D, A[j].len)) {
              Ans += A[j].Getsum(t[total] + 1, A[j].len);
            }
          }
          for (int k = 1; k <= total; ++k) {
            Ans += A[j].Getsum(t[k], t[k]);
          }
        }
      }
      write(Ans);
      putchar('\n');
    }
  }
}
int main() {
  Init();
  Solve();
  return 0;
}