#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
long long Bit[N + 10][N + 10], ans[N + 10];
int On[N + 10], l[N + 10], d[N + 10], r[N + 10], u[N + 10];
vector<pair<pair<int, int>, int> > gar[N + 10];
vector<int> g[N + 10];
void update(int idx1, int idx2, int val) {
  for (int i = idx1; i <= N; i += (i & -i)) {
    for (int j = idx2; j <= N; j += (j & -j)) {
      Bit[i][j] += val;
    }
  }
}
long long query(int idx1, int idx2) {
  long long total = 0;
  for (int i = idx1; i > 0; i -= (i & -i)) {
    for (int j = idx2; j > 0; j -= (j & -j)) {
      total += Bit[i][j];
    }
  }
  return total;
}
int main() {
  int n, m, k, q, cur = 1;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int len;
    scanf("%d", &len);
    for (int j = 1; j <= len; j++) {
      int x, y, cost;
      scanf("%d%d%d", &x, &y, &cost);
      gar[i].push_back(make_pair(make_pair(x, y), cost));
    }
  }
  scanf("%d", &q);
  while (q--) {
    char str[10];
    scanf("%s", str);
    if (!strcmp(str, "SWITCH")) {
      int id;
      scanf("%d", &id);
      On[id] ^= 1;
    } else {
      scanf("%d%d%d%d", d + cur, l + cur, u + cur, r + cur);
      for (int i = 1; i <= k; i++) {
        if (!On[i]) {
          g[i].push_back(cur);
        }
      }
      cur++;
    }
  }
  for (int i = 1; i <= k; i++) {
    for (auto it : gar[i]) {
      update(it.first.first, it.first.second, it.second);
    }
    for (auto it : g[i]) {
      ans[it] += query(u[it], r[it]);
      ans[it] += query(d[it] - 1, l[it] - 1);
      ans[it] -= query(u[it], l[it] - 1);
      ans[it] -= query(d[it] - 1, r[it]);
    }
    for (auto it : gar[i]) {
      update(it.first.first, it.first.second, -it.second);
    }
  }
  for (int i = 1; i < cur; i++) {
    printf("%lld\n", ans[i]);
  }
}
