#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m, k, value[2002][2002];
long long aib[2002][2002];
void add(int L, int C, int val) {
  for (; C <= m; C += (C & (-C))) aib[L][C] += val;
}
long long compute(int L, int C) {
  long long ans = 0;
  for (; C; C -= C & (-C)) ans += aib[L][C];
  return ans;
}
bool on[2002], on2[2002];
vector<pair<int, int> > light[2002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i) {
    int z;
    cin >> z;
    for (int j = 0; j < z; ++j) {
      int a, b;
      cin >> a >> b;
      cin >> value[a][b];
      light[i].push_back({a, b});
    }
    on[i] = 1;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) add(i, j, value[i][j]);
  for (int i = 1; i <= k; ++i) on2[i] = on[i];
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    string s;
    cin >> s;
    if (s[0] == 'A') {
      int xa, ya, xb, yb;
      cin >> xa >> ya >> xb >> yb;
      long long ans = 0;
      for (int j = 1; j <= k; ++j) {
        if (on2[j] != on[j]) {
          for (int p = 0; p < light[j].size(); ++p)
            if (on[j])
              add(light[j][p].first, light[j][p].second,
                  -value[light[j][p].first][light[j][p].second]);
            else
              add(light[j][p].first, light[j][p].second,
                  value[light[j][p].first][light[j][p].second]);
        }
      }
      for (int j = xa; j <= xb; ++j)
        ans = ans + compute(j, yb) - compute(j, ya - 1);
      for (int j = 1; j <= k; ++j) on[j] = on2[j];
      cout << ans << '\n';
    } else {
      int cc;
      cin >> cc;
      on2[cc] ^= 1;
    }
  }
  return 0;
}
