#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
int hl = 0, hr = 0, n = 0;
int cnt0 = 0, cnt1 = 0;
int H = 100, L = 1e5;
struct node {
  int v, l, r;
};
node up[100 + 5], down[100 + 5];
bool cmp(node a, node b) { return a.l < b.l; }
int cal(int p, double w) {
  int res = 0;
  double tmp = 0;
  if (p == 0)
    tmp = w * hl / H;
  else
    tmp = w * (H - hl) / H;
  int u = 0, d = 0, lastu = -1, lastd = -1;
  while (L - tmp > -eps && (u < cnt0 || d < cnt1)) {
    if (p != 0) {
      while (u < cnt0 && tmp - up[u].r > eps) u++;
      if (u >= cnt0 || u == lastu || tmp - up[u].l < -eps) return 0;
      res += up[u].v;
      lastu = u;
    } else {
      while (d < cnt1 && tmp - down[d].r > eps) d++;
      if (d >= cnt1 || d == lastd || tmp - down[d].l < -eps) return 0;
      res += down[d].v;
      lastd = d;
    }
    p = 1 - p;
    tmp += w;
  }
  return res;
}
int main() {
  scanf("%d%d%d", &hl, &hr, &n);
  for (int i = 0; i < n; i++) {
    up[i].l = up[i].v = up[i].r = down[i].l = down[i].r = down[i].v = 0;
  }
  int v = 0, l, r;
  char pp;
  cnt0 = cnt1 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %c %d %d", &v, &pp, &l, &r);
    if (pp == 'T') {
      up[cnt0].v = v;
      up[cnt0].l = l;
      up[cnt0++].r = r;
    } else {
      down[cnt1].v = v;
      down[cnt1].l = l;
      down[cnt1++].r = r;
    }
  }
  sort(up, up + cnt0, cmp);
  sort(down, down + cnt1, cmp);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    double tmp = 0;
    if (i & 1) {
      tmp = 1.0 * H * L / ((i - 1) * H + hl + hr);
      res = max(res, cal(0, tmp));
      tmp = 1.0 * H * L / ((i + 1) * H - hl - hr);
      res = max(res, cal(1, tmp));
    } else {
      tmp = 1.0 * H * L / (i * H + hl - hr);
      res = max(res, cal(0, tmp));
      tmp = 1.0 * H * L / (i * H - hl + hr);
      res = max(res, cal(1, tmp));
    }
  }
  printf("%d\n", res);
  return 0;
}
