#include <bits/stdc++.h>
using namespace std;
const int K = 2e3 + 12;
struct Node {
  int x, y, c;
  Node(int x, int y, int c) {
    this->x = x;
    this->y = y;
    this->c = c;
  }
};
struct Query {
  int idx;
  int x1, y1, x2, y2;
  Query(int idx, int x1, int y1, int x2, int y2) {
    this->idx = idx;
    this->x1 = x1;
    this->y1 = y1;
    this->x2 = x2;
    this->y2 = y2;
  }
};
int n, m, k;
vector<Node> nodes[K];
vector<Query> query[K];
bool sw[K];
long long fen[K * K];
void add(int x, int y, int c) {
  ++x, ++y;
  for (int i = x; i <= n; i += i & (-i))
    for (int j = y; j <= m; j += j & (-j)) fen[i * m + j] += c;
}
void build_tree(int idx, int type) {
  for (auto node : nodes[idx]) {
    add(node.x, node.y, node.c * type);
  }
}
long long get_sum(int x, int y) {
  ++x, ++y;
  long long res = 0;
  for (int i = x; i > 0; i -= i & (-i))
    for (int j = y; j > 0; j -= j & (-j)) res += fen[i * m + j];
  return res;
}
long long get_sum(int x1, int y1, int x2, int y2) {
  long long res = get_sum(x2, y2) - get_sum(x1 - 1, y2) - get_sum(x2, y1 - 1) +
                  get_sum(x1 - 1, y1 - 1);
  return res;
}
string next_string() {
  char ch;
  string ans = "";
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (ch >= 'A' && ch <= 'Z') {
    ans += ch;
    ch = getchar();
  }
  return ans;
}
template <typename T>
T next_int() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return p * x;
}
int main() {
  n = next_int<int>();
  m = next_int<int>();
  k = next_int<int>();
  for (int i = 0; i < k; ++i) {
    int len = next_int<int>();
    sw[i] = 1;
    while (len--) {
      int x = next_int<int>();
      int y = next_int<int>();
      int c = next_int<int>();
      --x, --y;
      nodes[i].push_back(Node(x, y, c));
    }
  }
  int idx = 0;
  int q = next_int<int>();
  while (q--) {
    string type = next_string();
    if (type[0] == 'A') {
      int x1 = next_int<int>();
      int y1 = next_int<int>();
      int x2 = next_int<int>();
      int y2 = next_int<int>();
      --x1, --y1, --x2, --y2;
      for (int i = 0; i < k; ++i) {
        if (sw[i]) {
          query[i].push_back(Query(idx, x1, y1, x2, y2));
        }
      }
      ++idx;
    } else {
      int idx = next_int<int>();
      sw[--idx] ^= 1;
    }
  }
  vector<long long> ans(idx);
  for (int i = 0; i < k; ++i) {
    build_tree(i, 1);
    for (auto q : query[i]) {
      ans[q.idx] += get_sum(q.x1, q.y1, q.x2, q.y2);
    }
    build_tree(i, -1);
  }
  for (auto i : ans) {
    printf("%I64d\n", i);
  }
}
