#include <bits/stdc++.h>
using namespace std;
int Sz[2002 + 2];
vector<pair<int, pair<int, int> > > pp[2002 + 2];
bool inv[2002 + 2];
bool Ad[2002 + 2];
long long BIT[2002 + 2][2002 + 2];
void add(int x, int y, long long v) {
  for (int i = x; i <= 2002; i += i & -i) {
    for (int j = y; j <= 2002; j += j & -j) {
      BIT[i][j] += v;
    }
  }
}
long long read(int x, int y) {
  long long ret = 0;
  for (int i = x; i > 0; i -= i & -i) {
    for (int j = y; j > 0; j -= j & -j) {
      ret += BIT[i][j];
    }
  }
  return ret;
}
long long go(int a, int b, int c, int d) {
  long long ret = read(c, d);
  ret -= read(c, b - 1);
  ret -= read(a - 1, d);
  ret += read(a - 1, b - 1);
  return ret;
}
int main() {
  int n, m, k, i, j, x, y, z, a, b, c, d, q;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &Sz[i]);
    for (int j = 1; j <= Sz[i]; j++) {
      scanf("%d%d%d", &x, &y, &z);
      pp[i].push_back(make_pair(x, make_pair(y, z)));
    }
  }
  scanf("%d", &q);
  while (q--) {
    char s[9];
    scanf("%s", s);
    if (s[0] == 'S') {
      scanf("%d", &x);
      inv[x] ^= 1;
    } else {
      scanf("%d%d", &a, &b);
      scanf("%d%d", &c, &d);
      for (i = 1; i <= k; i++) {
        if (inv[i]) continue;
        for (j = 0; j < Sz[i]; j++) {
          x = pp[i][j].first;
          y = pp[i][j].second.first;
          z = pp[i][j].second.second;
          if (!Ad[i])
            add(x, y, z);
          else
            add(x, y, -z);
        }
        Ad[i] ^= 1;
        inv[i] ^= 1;
      }
      long long ans = go(a, b, c, d);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
