#include <bits/stdc++.h>
using namespace std;
int n, m, w, q;
long long ans[2003];
int Arr[2003][2003][3], maxP = 0;
int Pos[2003][4];
bool visit[2003], st[2003][2003];
char str[233];
long long BIT[2003][2003];
void add(int x, int y, long long f) {
  for (int i = x; i <= n; i += ((i) & (-(i))))
    for (int j = y; j <= m; j += ((j) & (-(j)))) BIT[i][j] += f;
}
long long ask(int x, int y) {
  long long res = 0;
  for (int i = x; i; i -= ((i) & (-(i))))
    for (int j = y; j; j -= ((j) & (-(j)))) res += BIT[i][j];
  return res;
}
int main(void) {
  cin >> n >> m >> w;
  for (int i = 1, x; i <= w; ++i) {
    cin >> x;
    Arr[i][0][0] = x;
    for (int j = 1; j <= x; ++j)
      scanf("%d%d%d", Arr[i][j], Arr[i][j] + 1, Arr[i][j] + 2);
  }
  cin >> q;
  for (int i = 1, x, x1, y1, x2, y2; i <= q; ++i) {
    scanf("%s", str);
    if (str[0] == 'S') {
      scanf("%d", &x);
      visit[x] = !visit[x];
    } else {
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      for (int j = 1; j <= w; ++j) st[maxP][j] = visit[j];
      Pos[maxP][0] = x1;
      Pos[maxP][1] = y1;
      Pos[maxP][2] = x2;
      Pos[maxP][3] = y2;
      maxP++;
    }
  }
  for (int x = 1; x <= w; ++x) {
    for (int i = Arr[x][0][0]; i; --i)
      add(Arr[x][i][0], Arr[x][i][1], Arr[x][i][2]);
    for (int a = 0; a < maxP; ++a)
      if (st[a][x] == false)
        ans[a] += ask(Pos[a][2], Pos[a][3]) +
                  ask(Pos[a][0] - 1, Pos[a][1] - 1) -
                  ask(Pos[a][0] - 1, Pos[a][3]) - ask(Pos[a][2], Pos[a][1] - 1);
    for (int i = Arr[x][0][0]; i; --i)
      add(Arr[x][i][0], Arr[x][i][1], -Arr[x][i][2]);
  }
  for (int i = 0; i < maxP; ++i) cout << ans[i] << endl;
  return 0;
}
