#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int K = 2e3 + 100;
struct abc {
  int x, y, w;
};
int n, m, k, num[K], cha[K], flag[K];
abc a[K][K];
char s[7];
long long sum[K][K];
int lowbit(int x) { return x & (-x); }
void add(int x, int y, long long t) {
  while (x <= n) {
    int j = y;
    while (j <= m) {
      sum[x][j] += t;
      j += lowbit(j);
    }
    x += lowbit(x);
  }
}
long long get_sum(int x, int y) {
  long long temp = 0;
  while (x > 0) {
    int j = y;
    while (j > 0) {
      temp += sum[x][j];
      j -= lowbit(j);
    }
    x -= lowbit(x);
  }
  return temp;
}
int main() {
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &num[i]);
    for (int j = 1; j <= num[i]; j++)
      scanf("%d", &a[i][j].x), scanf("%d", &a[i][j].y), scanf("%d", &a[i][j].w);
    cha[i] = 1;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'S') {
      int k;
      scanf("%d", &k);
      cha[k] = 1 - cha[k];
    } else {
      for (int i = 1; i <= k; i++)
        if (cha[i]) {
          for (int j = 1; j <= num[i]; j++)
            add(a[i][j].x, a[i][j].y, a[i][j].w * ((flag[i] == 0) ? 1 : -1));
          cha[i] = 0, flag[i] = 1 - flag[i];
        }
      int x1, y1, x2, y2;
      scanf("%d", &x1), scanf("%d", &y1), scanf("%d", &x2), scanf("%d", &y2);
      printf("%lld\n", get_sum(x2, y2) - get_sum(x1 - 1, y2) -
                           get_sum(x2, y1 - 1) + get_sum(x1 - 1, y1 - 1));
    }
  }
  return 0;
}
