#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
map<long long, pair<long long, int> > scores[2];
pair<long long, int> getScore(int i, long long xt, long long xb) {
  long long xfloor = xt / xb;
  map<long long, pair<long long, int> >::iterator it =
      scores[i].upper_bound(xfloor);
  if (it == scores[i].begin()) return make_pair(0, -1);
  --it;
  if (it == scores[i].end()) return make_pair(0, -1);
  if (it->first * xb >= xt) return make_pair(0, -1);
  if (it->second.first * xb <= xt) return make_pair(0, -1);
  return it->second;
}
int main() {
  int h1, h2;
  int n;
  cin >> h1 >> h2 >> n;
  for (int i = 0; i < (n); i++) {
    int score, start, end;
    char pos;
    cin >> score >> pos >> start >> end;
    for (int j = start; j <= end; j++) {
      int id = pos == 'T' ? 0 : 1;
      scores[id][start] = make_pair(end, score);
    }
  }
  int best = 0;
  for (int i = 1; i <= 100; i++) {
    int tot = 0;
    long long nextAfter[2] = {0, 0};
    for (int j = 1; j <= i; j++) {
      int scoresId = j % 2;
      long long dy = (j - 1) * 100 + h1;
      long long ty = 100 * i + h1 + (i % 2 == 0 ? -h2 : h2 - 100);
      long long dxt = 100000 * dy;
      long long dxb = ty;
      pair<long long, int> score = getScore(scoresId, dxt, dxb);
      if (score.second == -1 || nextAfter[scoresId] == score.first) {
        tot = 0;
        break;
      } else {
        tot += score.second;
        nextAfter[scoresId] = score.first;
      }
    }
    if (tot > best) best = tot;
    tot = 0;
    nextAfter[0] = nextAfter[1] = 0;
    for (int j = 1; j <= i; j++) {
      int scoresId = 1 - j % 2;
      long long dy = 100 - h1 + (j - 1) * 100;
      long long ty = 100 * i - h1 + (i % 2 == 0 ? h2 : 100 - h2);
      long long dxt = 100000 * dy;
      long long dxb = ty;
      pair<long long, int> score = getScore(scoresId, dxt, dxb);
      if (score.second == -1 || nextAfter[scoresId] == score.first) {
        tot = 0;
        break;
      } else {
        tot += score.second;
        nextAfter[scoresId] = score.first;
      }
    }
    if (tot > best) best = tot;
  }
  cout << best << endl;
  return 0;
}
