#include <bits/stdc++.h>
const int N = 2005;
long long tree[N][N];
void update(int pos1, int pos2, long long val) {
  for (; pos1 < N; pos1 += pos1 & -pos1) {
    for (int pos = pos2; pos < N; pos += pos & -pos) {
      tree[pos1][pos] += val;
    }
  }
}
long long getsum(int pos1, int pos2) {
  long long res = 0;
  for (; pos1; pos1 -= pos1 & -pos1) {
    for (int pos = pos2; pos; pos -= pos & -pos) {
      res += tree[pos1][pos];
    }
  }
  return res;
}
int x[N][N], y[N][N], w[N][N];
int len[N];
bool st[N];
int X1[N], Y1[N], X2[N], Y2[N], qcnt = 1;
int swc[1000006] = {0};
long long ans[N][N];
char str[10];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d", &len[i]);
    for (int j = 0; j < len[i]; ++j) {
      scanf("%d%d%d", &x[i][j], &y[i][j], &w[i][j]);
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%s", str);
    if (str[0] == 'S')
      scanf("%d", &swc[i]);
    else {
      scanf("%d%d%d%d", &X1[qcnt], &Y1[qcnt], &X2[qcnt], &Y2[qcnt]);
      qcnt++;
    }
  }
  for (int i = 1; i <= k; ++i) {
    for (int j = 0; j < len[i]; ++j) update(y[i][j], x[i][j], w[i][j]);
    for (int j = 1; j < qcnt; ++j) {
      ans[i][j] = getsum(Y2[j], X2[j]) - getsum(Y2[j], X1[j] - 1) -
                  getsum(Y1[j] - 1, X2[j]) + getsum(Y1[j] - 1, X1[j] - 1);
    }
    for (int j = 0; j < len[i]; ++j) update(y[i][j], x[i][j], -w[i][j]);
  }
  for (int i = 1, cnt = 1; i <= q; ++i) {
    if (swc[i])
      st[swc[i]] ^= 1;
    else {
      long long tmp = 0;
      for (int j = 1; j <= k; ++j) {
        if (!st[j]) tmp += ans[j][cnt];
      }
      cnt++;
      printf("%I64d\n", tmp);
    }
  }
}
