#include <bits/stdc++.h>
using namespace std;
int N, M, K, Q, q;
struct BIT {
  long long a[2002][2002];
  void add(int x, int y, int t) {
    for (int i = x; i <= N; i += i & -i) {
      for (int j = y; j <= M; j += j & -j) a[i][j] += t;
    }
  }
  long long get(int x, int y) {
    long long ans = 0;
    for (int i = x; i; i -= i & -i) {
      for (int j = y; j; j -= j & -j) ans += a[i][j];
    }
    return ans;
  }
} a;
long long get(int x1, int y1, int x2, int y2) {
  return a.get(x2, y2) - a.get(x2, y1 - 1) - a.get(x1 - 1, y2) +
         a.get(x1 - 1, y1 - 1);
}
int fir[2005], nex[2005 * 2005], enx[2005 * 2005], eny[2005 * 2005],
    enw[2005 * 2005], tot;
void insert(int i, int X, int Y, int W) {
  nex[++tot] = fir[i];
  fir[i] = tot;
  enx[tot] = X;
  eny[tot] = Y;
  enw[tot] = W;
}
int X1[2005], Y1[2005], X2[2005], Y2[2005];
int cha[2005];
bool opt[2005][2005];
long long ans[2005];
int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 1; i <= K; i++) {
    int cnt_n;
    scanf("%d", &cnt_n);
    for (int j = 1; j <= cnt_n; j++) {
      int X, Y, W;
      scanf("%d%d%d", &X, &Y, &W);
      insert(i, X, Y, W);
    }
    cha[i] = 1;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    char st[20];
    scanf("%s", st);
    if (st[0] == 'S') {
      int x;
      scanf("%d", &x);
      cha[x] ^= 1;
    } else {
      ++q;
      scanf("%d%d%d%d", &X1[q], &Y1[q], &X2[q], &Y2[q]);
      for (int j = 1; j <= K; j++) opt[q][j] = cha[j];
    }
  }
  for (int i = 1; i <= K; i++) {
    for (int k = fir[i]; k; k = nex[k]) a.add(enx[k], eny[k], enw[k]);
    for (int j = 1; j <= q; j++)
      if (opt[j][i]) {
        ans[j] += get(X1[j], Y1[j], X2[j], Y2[j]);
      }
    for (int k = fir[i]; k; k = nex[k]) a.add(enx[k], eny[k], -enw[k]);
  }
  for (int i = 1; i <= q; i++) printf("%I64d\n", ans[i]);
  return 0;
}
