#include <bits/stdc++.h>
using namespace std;
const int N = 2004;
int n;
vector<pair<long long int, pair<long long int, long long int> > > gar[N];
bool stat[N], query[N][N];
vector<pair<pair<long long int, long long int>,
            pair<long long int, long long int> > >
    queryo;
long long int ans[N];
long long int BIT[N][N];
void update_bit(int x, int y, int val) {
  while (x < N) {
    long long int y1 = y;
    while (y1 < N) {
      BIT[x][y1] += val;
      y1 += (y1 & -y1);
    }
    x += (x & -x);
  }
}
long long int query_bit(int x, int y) {
  long long int sum = 0;
  while (x) {
    long long int y1 = y;
    while (y1) {
      sum += BIT[x][y1];
      y1 -= (y1 & -y1);
    }
    x -= (x & -x);
  }
  return sum;
}
long long int query_main(int x1, int y1, int x2, int y2) {
  return query_bit(x2, y2) - query_bit(x2, y1 - 1) - query_bit(x1 - 1, y2) +
         query_bit(x1 - 1, y1 - 1);
}
int main() {
  int t, k, m;
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
  for (int i = 1; i < k + 1; ++i) {
    int len;
    scanf("%d", &len);
    for (int j = 0; j < len; ++j) {
      long long int x, y, w;
      scanf("%lld", &x), scanf("%lld", &y), scanf("%lld", &w);
      gar[i].push_back(make_pair(x, make_pair(y, w)));
    }
  }
  for (int i = 1; i < k + 1; ++i) stat[i] = 1;
  int qry = 0;
  int q;
  scanf("%d", &q);
  while (q--) {
    char c[10];
    scanf("%s", c);
    if (c[0] == 'S') {
      int x;
      scanf("%d", &x);
      stat[x] ^= 1;
    } else {
      long long int x1, y1, x2, y2;
      scanf("%lld", &x1), scanf("%lld", &y1), scanf("%lld", &x2),
          scanf("%lld", &y2);
      for (int j = 1; j < k + 1; ++j) query[qry][j] = stat[j];
      queryo.push_back(make_pair(make_pair(x1, y1), make_pair(x2, y2)));
      qry++;
    }
  }
  for (int i = 1; i < k + 1; ++i) {
    for (int j = 0; j < (int)gar[i].size(); ++j)
      update_bit(gar[i][j].first, gar[i][j].second.first,
                 gar[i][j].second.second);
    for (int j = 0; j < qry; ++j) {
      if (query[j][i]) {
        int x1, y1, x2, y2;
        x1 = queryo[j].first.first;
        y1 = queryo[j].first.second;
        x2 = queryo[j].second.first;
        y2 = queryo[j].second.second;
        ans[j] += query_main(x1, y1, x2, y2);
      }
    }
    for (int j = 0; j < (int)gar[i].size(); ++j)
      update_bit(gar[i][j].first, gar[i][j].second.first,
                 -gar[i][j].second.second);
  }
  for (int i = 0; i < qry; ++i) printf("%lld\n", ans[i]);
  return 0;
}
