#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    srand(time(NULL));
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    int n;
    cin >> n;
  }
} __S;
inline bool check(int l, int r, int x) { return (l < x) && (x < r); }
int main(void) {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<vector<int> > val(n, vector<int>(m));
  vector<vector<pair<int, int> > > idx(
      n, vector<pair<int, int> >(m, make_pair(k, 0)));
  vector<int> len(k);
  vector<vector<int> > x(k);
  vector<vector<int> > y(k);
  vector<vector<int> > z(k);
  vector<vector<long long> > sum;
  for (int i = 0; i < (int)(k); i++) {
    scanf("%d", &len[i]);
    vector<long long> s(1, 0);
    for (int j = 0; j < (int)(len[i]); j++) {
      int xx, yy, zz;
      scanf("%d%d%d", &xx, &yy, &zz);
      xx--, yy--;
      idx[xx][yy] = make_pair(i, j);
      s.push_back(s.back() + zz);
      val[xx][yy] = zz;
      x[i].push_back(xx);
      y[i].push_back(yy);
      z[i].push_back(zz);
    }
    sum.push_back(s);
  }
  int q;
  scanf("%d", &q);
  vector<bool> u(k, true);
  for (int _ = 0; _ < (int)(q); _++) {
    char c[10];
    scanf("%s", c);
    string s = c;
    if (s == "SWITCH") {
      int i;
      scanf("%d", &i);
      i--;
      u[i] = !u[i];
      continue;
    }
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x1--, y1--, x2--, y2--;
    long long ans = 0;
    vector<vector<int> > v(k + 1);
    for (int x = x1; x <= x2; x++) {
      v[idx[x][y1].first].push_back(idx[x][y1].second);
      v[idx[x][y2].first].push_back(idx[x][y2].second);
    }
    for (int y = y1; y <= y2; y++) {
      v[idx[x1][y].first].push_back(idx[x1][y].second);
      v[idx[x2][y].first].push_back(idx[x2][y].second);
    }
    for (int i = 0; i < (int)(k); i++) {
      if (!u[i]) continue;
      if (check(x1, x2, x[i].front()) && check(y1, y2, y[i].front()))
        v[i].push_back(0);
      if (check(x1, x2, x[i].back()) && check(y1, y2, y[i].back()))
        v[i].push_back(sum[i].size() - 2);
      sort(v[i].begin(), v[i].end());
      for (int jj = 0; jj < (int)(v[i].size()); jj++) {
        if (jj + 1 < v[i].size() && v[i][jj + 1] == v[i][jj]) continue;
        int j = v[i][jj];
        if (j == len[i] - 1) {
          ans += z[i][j];
          continue;
        }
        if (check(x1, x2, x[i][j + 1]) && check(y1, y2, y[i][j + 1])) {
          int r = v[i][jj + 1] + 1;
          int l = v[i][jj];
          ans += sum[i][r] - sum[i][l];
          jj++;
        } else {
          ans += z[i][j];
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
