#include <bits/stdc++.h>
using namespace std;
const int maxn = 2001;
struct Point {
  int x, y, w;
  bool operator<(const Point &r) const { return r.x == x ? y < r.y : x < r.x; }
} a[maxn][maxn];
struct Node {
  int id, x1, y1, x2, y2;
};
vector<Node> tmp[maxn];
long long ans[maxn], C[maxn][maxn];
int Belong[maxn][maxn], len[maxn];
int flag[maxn], n, m;
char s[10];
void add(int x, int y, int id, int w) {
  for (int i = x; i <= n; i += (i & -x))
    for (int j = y; j <= m; j += (j & -j)) {
      if (Belong[i][j] == id)
        C[i][j] += w;
      else
        C[i][j] = w, Belong[i][j] = id;
    }
}
long long sum(int x, int y, int id) {
  long long ret = 0;
  for (int i = x; i > 0; i -= (i & -i))
    for (int j = y; j > 0; j -= (j & -j))
      if (Belong[i][j] == id) ret += C[i][j];
  return ret;
}
int main() {
  int q, k, x, x1, y1, x2, y2, cnt = 0;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) flag[i] = 1;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &len[i]);
    for (int j = 1; j <= len[i]; j++)
      scanf("%d%d%d", &a[i][j].x, &a[i][j].y, &a[i][j].w);
    sort(a[i] + 1, a[i] + len[i] + 1);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s", s);
    if (s[0] == 'S')
      scanf("%d", &x), flag[x] ^= 1;
    else {
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      ++cnt;
      for (int j = 1; j <= k; j++)
        if (flag[j] == 1) tmp[j].push_back((Node){cnt, x1, y1, x2, y2});
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= len[i]; j++) add(a[i][j].x, a[i][j].y, i, a[i][j].w);
    for (int j = 0; j < tmp[i].size(); j++)
      ans[tmp[i][j].id] += sum(tmp[i][j].x2, tmp[i][j].y2, i) -
                           sum(tmp[i][j].x1 - 1, tmp[i][j].y2, i) -
                           sum(tmp[i][j].x2, tmp[i][j].y1 - 1, i) +
                           sum(tmp[i][j].x1 - 1, tmp[i][j].y1 - 1, i);
  }
  for (int i = 1; i <= cnt; i++) printf("%lld\n", ans[i]);
  return 0;
}
