#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n, m, q, p, flag[N], tb[N], cha[N];
char str[20];
long long a[N][N];
struct aa {
  int x, y, w;
} b[N][N];
int add(int x, int y, long long z) {
  int j;
  while (x <= n) {
    j = y;
    while (j <= m) {
      a[x][j] += z;
      j += j & (-j);
    }
    x += x & (-x);
  }
  return 0;
}
long long sum(int x, int y) {
  long long s, j;
  s = 0;
  while (x > 0) {
    j = y;
    while (j > 0) {
      s += a[x][j];
      j -= j & (-j);
    }
    x -= x & (-x);
  }
  return s;
}
int main(void) {
  int i, j, k, x1, x2, y1, y2;
  memset(flag, 0, sizeof(flag));
  scanf("%d%d%d", &n, &m, &p);
  for (i = 1; i <= p; i++) {
    scanf("%d", &tb[i]);
    for (j = 1; j <= tb[i]; j++) {
      scanf("%d%d%d", &b[i][j].x, &b[i][j].y, &b[i][j].w);
    }
    cha[i] = 1;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%s", str + 1);
    if (str[1] == 'S') {
      scanf("%d", &k);
      cha[k] ^= 1;
    } else {
      for (i = 1; i <= p; i++)
        if (cha[i]) {
          for (j = 1; j <= tb[i]; j++)
            add(b[i][j].x, b[i][j].y, b[i][j].w * ((flag[i] == 1 ? (-1) : 1)));
          flag[i] ^= 1;
          cha[i] = 0;
        }
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      printf("%I64d\n", sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) +
                            sum(x1 - 1, y1 - 1));
    }
  }
  return 0;
}
