#include <bits/stdc++.h>
using namespace std;
namespace io {
char __buf[1 << 20], *__p1, *__p2;
inline int read() {
  int __x = 0, __f = 1;
  char __c = getchar();
  while (__c < '0' || __c > '9') {
    if (__c == '-') __f = -1;
    __c = getchar();
  }
  while (__c >= '0' && __c <= '9') {
    __x = __x * 10 + __c - '0';
    __c = getchar();
  }
  return __x * __f;
}
char __F[200];
inline void write(long long __x) {
  if (__x < 0) {
    putchar('-');
    __x = -__x;
  }
  if (__x >= 10) write(__x / 10);
  putchar(__x % 10 + '0');
}
}  // namespace io
using namespace io;
const int maxn = 2005;
struct node {
  int x, y;
  long long z;
};
long long c[maxn][maxn];
int a[maxn], b[maxn], n, m, k, q, lon[maxn], las[maxn];
vector<node> p[maxn];
char s[10];
int lowbit(int x) { return x & (-x); }
void add(int x, int y, long long sum) {
  for (register int i = x; i <= n; i += lowbit(i)) {
    for (register int j = y; j <= m; j += lowbit(j)) {
      c[i][j] += sum;
    }
  }
}
long long ask(int x, int y) {
  long long sum = 0;
  for (register int i = x; i; i -= lowbit(i)) {
    for (register int j = y; j; j -= lowbit(j)) {
      sum += c[i][j];
    }
  }
  return sum;
}
long long query(int x, int y, int z, int w) {
  return ask(z, w) - ask(x - 1, w) - ask(z, y - 1) + ask(x - 1, y - 1);
}
int main() {
  int x, y, z, w, siz;
  n = read(), m = read(), k = read();
  for (register int i = 1; i <= k; i++) {
    siz = read();
    while (siz--) {
      x = read(), y = read(), z = read();
      p[i].push_back((node){x, y, z});
      add(x, y, z);
    }
    lon[i] = las[i] = 1;
  }
  q = read();
  while (q--) {
    scanf("%s", s);
    if (s[0] == 'S') {
      x = read();
      lon[x] ^= 1;
      continue;
    }
    for (register int i = 1; i <= k; i++) {
      if (lon[i] ^ las[i]) {
        int pd = lon[i] ? 1 : -1;
        for (register int j = 0; j < p[i].size(); j++) {
          add(p[i][j].x, p[i][j].y, p[i][j].z * pd);
        }
        las[i] = lon[i];
      }
    }
    x = read(), y = read(), z = read(), w = read();
    write(query(x, y, z, w));
    putchar('\n');
  }
  return 0;
}
