#include <bits/stdc++.h>
using namespace std;
int dx[5] = {0, 0, 0, 1, -1}, dy[5] = {0, 1, -1, 0, 0};
const int base = 1000000007;
const int maxn = 1000002;
struct pt3 {
  int first, second, w;
  pt3(){};
  pt3(int a, int b, int c) {
    first = a;
    second = b;
    w = c;
  }
};
int n, m, K, Q;
int sz[maxn];
bool need[maxn], state[maxn];
long long tr[2002][2002];
pt3 gar[2002][2002];
void update(int i, int j, int w) {
  for (int first = i; first <= m; first += first & (-first))
    for (int second = j; second <= n; second += second & (-second))
      tr[first][second] += w;
}
long long get(int i, int j) {
  long long res = 0;
  for (int first = i; first > 0; first -= first & (-first))
    for (int second = j; second > 0; second -= second & (-second))
      res += tr[first][second];
  return res;
}
long long sum(int first, int second, int u, int v) {
  return get(u, v) - get(u, second - 1) - get(first - 1, v) +
         get(first - 1, second - 1);
}
int main() {
  int i, j, k, u, v, first, second;
  char s[102];
  scanf("%d%d%d\n", &m, &n, &K);
  for (i = 1; i <= K; i++) {
    scanf("%d\n", &sz[i]);
    for (j = 1; j <= sz[i]; j++) {
      scanf("%d%d%d\n", &gar[i][j].first, &gar[i][j].second, &gar[i][j].w);
      update(gar[i][j].first, gar[i][j].second, gar[i][j].w);
    }
    need[i] = 0;
    state[i] = 1;
  }
  scanf("%d", &Q);
  for (i = 1; i <= Q; i++) {
    scanf("%s", s);
    if (s[0] == 'S') {
      scanf("%d\n", &j);
      need[j] ^= 1;
    } else {
      for (j = 1; j <= K; j++)
        if (need[j]) {
          for (k = 1; k <= sz[j]; k++)
            update(gar[j][k].first, gar[j][k].second,
                   (state[j] == 0) ? gar[j][k].w : -gar[j][k].w);
          need[j] = 0;
          state[j] ^= 1;
        }
      scanf("%d%d%d%d\n", &first, &second, &u, &v);
      printf("%I64d\n", sum(first, second, u, v));
    }
  }
  return 0;
}
