#include <bits/stdc++.h>
using namespace std;
bool scan(int& first) { return scanf("%d", &first) == 1; }
bool scan(long long& first) { return scanf("%I64d", &first) == 1; }
bool scan(char* s) { return scanf("%s", s) == 1; }
template <typename T, typename... TT>
bool scan(T& first, TT&... xx) {
  return scan(first) && scan(xx...);
}
const int N = 2020, Q = 1000100, inf = 1e9;
pair<int, int> mp[N][N], p[N][N];
int len[N];
long long sum[N][N];
bool on[N];
int n, m, k, q;
int first, second, xx, yy;
inline bool in(pair<int, int> p) {
  return first <= p.first && p.first <= xx && second <= p.second &&
         p.second <= yy;
}
int main() {
  char op[100];
  while (scan(n, m, k)) {
    memset(mp, 0, sizeof mp);
    for (int i = 1; i <= (k); ++i) {
      scan(len[i]);
      sum[i][0] = 0;
      for (int j = 1; j <= (len[i]); ++j) {
        scan(p[i][j].first, p[i][j].second, sum[i][j]);
        sum[i][j] += sum[i][j - 1];
        mp[p[i][j].first][p[i][j].second] = pair<int, int>(i, j);
      }
    }
    memset(on, true, sizeof on);
    scan(q);
    for (int qi = 1; qi <= (q); ++qi) {
      scan(op);
      if (op[0] == 'S')
        scan(first), on[first] ^= 1;
      else {
        scan(first, second, xx, yy);
        long long ans = 0;
        for (int i = 1; i <= (k); ++i) {
          if (on[i] && first <= p[i][len[i]].first &&
              p[i][len[i]].first <= xx && second <= p[i][len[i]].second &&
              p[i][len[i]].second <= yy)
            ans += sum[i][len[i]];
        }
        for (int i = first; i <= xx; ++i) {
          for (int j = second; j <= yy; j += max(1, yy - second)) {
            int u = mp[i][j].first, v = mp[i][j].second;
            if (!u || !on[u]) continue;
            if (v > 1 && !in(p[u][v - 1])) ans -= sum[u][v - 1];
            if (v < len[u] && !in(p[u][v + 1])) ans += sum[u][v];
          }
        }
        for (int j = second + 1; j <= yy - 1; ++j) {
          for (int i = first; i <= xx; i += max(1, xx - first)) {
            int u = mp[i][j].first, v = mp[i][j].second;
            if (!u || !on[u]) continue;
            if (v > 1 && !in(p[u][v - 1])) ans -= sum[u][v - 1];
            if (v < len[u] && !in(p[u][v + 1])) ans += sum[u][v];
          }
        }
        printf("%I64d\n", ans);
      }
    }
  }
  return 0;
}
