#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, k, q;
long long T[N][N];
char type[10];
void upd(int x, int y, int v) {
  for (int i = x; i <= n; i += i & -i)
    for (int j = y; j <= m; j += j & -j) T[i][j] += v;
}
long long get(int x, int y) {
  long long r = 0;
  for (int i = x; i > 0; i -= i & -i)
    for (int j = y; j > 0; j -= j & -j) r += T[i][j];
  return r;
}
long long get(int x1, int y1, int x2, int y2) {
  return get(x2, y2) - get(x1 - 1, y2) - get(x2, y1 - 1) + get(x1 - 1, y1 - 1);
}
struct Query {
  vector<int> ok;
  int x1;
  int y1;
  int x2;
  int y2;
  Query(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0, int sz = 0)
      : x1(x1), x2(x2), y1(y1), y2(y2) {
    ok.assign(sz + 1, 0);
  }
};
struct bulb {
  int x;
  int y;
  int w;
  bulb(int X, int Y, int W) {
    x = X, y = Y;
    w = W;
  }
};
vector<int> avail;
vector<bulb> chain[N];
vector<Query> Ask;
vector<long long> ans;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int len;
    scanf("%d", &len);
    for (int j = 0; j < len; j++) {
      int x, y, w;
      scanf("%d%d%d", &x, &y, &w);
      chain[i].push_back(bulb(x, y, w));
    }
  }
  avail.assign(k + 1, 1);
  cin >> q;
  while (q--) {
    scanf("%s", type);
    if (type[0] == 'S') {
      int x;
      scanf("%d", &x);
      avail[x] ^= 1;
    } else {
      int x1, y1, x2, y2;
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      Query cur = Query(x1, y1, x2, y2);
      cur.ok = avail;
      Ask.push_back(cur);
    }
  }
  ans.assign(Ask.size(), 0LL);
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < chain[i].size(); j++)
      upd(chain[i][j].x, chain[i][j].y, chain[i][j].w);
    for (int j = 0; j < Ask.size(); j++) {
      if (Ask[j].ok[i])
        ans[j] += get(Ask[j].x1, Ask[j].y1, Ask[j].x2, Ask[j].y2);
    }
    for (int j = 0; j < chain[i].size(); j++)
      upd(chain[i][j].x, chain[i][j].y, -chain[i][j].w);
  }
  for (int i = 0; i < ans.size(); i++) printf("%lld\n", ans[i]);
}
