#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, c, d, x, y, p, q, t, ans, res, ma[2009], mi, T, k;
long long tree[2009][2009];
long long hold[2009][2009];
int len[2009];
struct node {
  int x, y, v;
};
node g[2009][2009];
struct node2 {
  int t, X1, Y1, X2, Y2, pid;
  node2() {}
  node2(int x, int a, int b = 0, int c = 0, int d = 0, int e = 0) {
    t = x;
    X1 = a;
    Y1 = b;
    X2 = c;
    Y2 = d;
    pid = e;
  }
};
vector<node2> Q, P;
char s[20];
void update2(int idx, int idy, int v) {
  for (; idy <= 2009 - 4; idy += idy & -idy) tree[idx][idy] += v;
}
void update(int idx, int idy, int v) {
  for (; idx <= 2009 - 4; idx += idx & -idx) update2(idx, idy, v);
}
long long read2(int idx, int idy) {
  long long sum = 0;
  for (; idy > 0; idy -= idy & -idy) sum += tree[idx][idy];
  return sum;
}
long long read(int idx, int idy) {
  long long sum = 0;
  for (; idx > 0; idx -= idx & -idx) sum += read2(idx, idy);
  return sum;
}
void init(int id) {
  for (int i = 1; i <= len[id]; i++) {
    update(g[id][i].x, g[id][i].y, g[id][i].v);
  }
}
void revert(int id) {
  for (int i = 1; i <= len[id]; i++) {
    update(g[id][i].x, g[id][i].y, -g[id][i].v);
  }
}
void print(int id) {
  cout << "garland=" << id << endl;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) cout << read(i, j) << "\t";
    cout << endl;
  }
  cout << endl;
}
bool cmp(node a, node b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
int main() {
  scanf("%I64d%I64d%I64d", &m, &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &len[i]);
    for (int j = 1; j <= len[i]; j++) {
      scanf("%d%d%d", &g[i][j].x, &g[i][j].y, &g[i][j].v);
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%s%I64d", s, &a);
    if (s[0] == 'S') {
      Q.push_back(node2(0, a));
    } else {
      scanf("%I64d%I64d%I64d", &b, &c, &d);
      Q.push_back(node2(1, a, b, c, d, T));
      P.push_back(node2(1, a, b, c, d));
      T++;
    }
  }
  for (int i = 1; i <= k; i++) {
    init(i);
    for (int j = 0; j < P.size(); j++) {
      long long f[4] = {0};
      hold[j][i] = (f[0] = read(P[j].X2, P[j].Y2)) -
                   (f[1] = read(P[j].X1 - 1, P[j].Y2)) -
                   (f[2] = read(P[j].X2, P[j].Y1 - 1)) +
                   (f[3] = read(P[j].X1 - 1, P[j].Y1 - 1));
    }
    revert(i);
  }
  for (int j = 0; j < Q.size(); j++) {
    if (Q[j].t == 0)
      ma[Q[j].X1] = 1 - ma[Q[j].X1];
    else {
      ans = 0;
      for (int i = 1; i <= k; i++) {
        if (ma[i] == 0) ans += hold[Q[j].pid][i];
      }
      cout << ans << endl;
    }
  }
  return 0;
}
