#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010 + 10;
const long long mod = 1e9 + 7;
long long a[2005][2005];
struct node {
  int x, y, z;
};
struct node1 {
  int x1, y1, x2, y2;
} ask[1000005];
int lowbit(int x) { return (x & (-x)); }
void modify(int x, int y, int data) {
  for (int i = x; i < 2005; i += lowbit(i))
    for (int j = y; j < 2005; j += lowbit(j)) a[i][j] += (long long)data;
}
long long get_sum(int x, int y) {
  long long res = 0;
  for (int i = x; i > 0; i -= lowbit(i))
    for (int j = y; j > 0; j -= lowbit(j)) res += a[i][j];
  return res;
}
long long query(int x1, int y1, int x2, int y2) {
  return get_sum(x2, y2) - get_sum(x1 - 1, y2) - get_sum(x2, y1 - 1) +
         get_sum(x1 - 1, y1 - 1);
}
vector<node> v[2005];
int on[2005];
vector<int> g[2005];
long long ans[1000005];
int main() {
  int n, m, k;
  int i, j = 0;
  scanf("%d %d %d", &n, &m, &k);
  for (i = 1; i <= k; i++) {
    on[i] = 1;
    int num;
    scanf("%d", &num);
    while (num--) {
      node b;
      scanf("%d %d %d", &b.x, &b.y, &b.z);
      v[i].push_back(b);
    }
  }
  char op[10];
  int q;
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%s", op);
    if (op[0] == 'A') {
      j++;
      scanf("%d %d %d %d", &ask[j].x1, &ask[j].y1, &ask[j].x2, &ask[j].y2);
      for (int r = 1; r <= k; r++) {
        if (on[r] == 1) g[r].push_back(j);
      }
    } else {
      int x;
      scanf("%d", &x);
      on[x] ^= 1;
    }
  }
  for (i = 1; i <= k; i++) {
    for (int r = 0; r < v[i].size(); r++)
      modify(v[i][r].x, v[i][r].y, v[i][r].z);
    for (int r = 0; r < g[i].size(); r++) {
      ans[g[i][r]] += query(ask[g[i][r]].x1, ask[g[i][r]].y1, ask[g[i][r]].x2,
                            ask[g[i][r]].y2);
    }
    for (int r = 0; r < v[i].size(); r++)
      modify(v[i][r].x, v[i][r].y, -v[i][r].z);
  }
  for (i = 1; i <= j; i++) printf("%I64d\n", ans[i]);
}
