#include <bits/stdc++.h>
using namespace std;
struct Mirror {
  int score, l, r;
};
int hl, hr, n;
vector<Mirror> mf, mc;
bool uzf[105], uzc[105];
bool Comp(Mirror a, Mirror b) { return a.l < b.l; }
int bounce(double x, double &dx, bool ceiling, int nr) {
  if (!nr) return 0;
  if (ceiling) {
    for (int i = 0; i < (int)mc.size(); i++)
      if (!uzc[i] && x + 1e-5 > mc[i].l && x - 1e-5 < mc[i].r) {
        uzc[i] = 1;
        return mc[i].score + bounce(x + dx * 100, dx, 0, nr - 1);
      }
  } else {
    for (int i = 0; i < (int)mf.size(); i++)
      if (!uzf[i] && x + 1e-5 > mf[i].l && x - 1e-5 < mf[i].r) {
        uzf[i] = 1;
        return mf[i].score + bounce(x + dx * 100, dx, 1, nr - 1);
      }
  }
  return -2000000000;
}
int main() {
  scanf("%d %d %d\n", &hl, &hr, &n);
  for (int i = 1; i <= n; i++) {
    char c;
    Mirror x;
    scanf("%d %c %d %d\n", &x.score, &c, &x.l, &x.r);
    if (c == 'T')
      mc.push_back(x);
    else
      mf.push_back(x);
  }
  sort(mf.begin(), mf.end(), Comp);
  sort(mc.begin(), mc.end(), Comp);
  int sol = 0;
  for (int i = n; i >= 1; i--) {
    memset(uzf, 0, sizeof(uzf));
    memset(uzc, 0, sizeof(uzc));
    double dx =
        ((double)100000) / (100 * (i - 1) + hl + ((i % 2) ? hr : (100 - hr)));
    double x = dx * hl;
    int score = bounce(x, dx, 0, i);
    if (score > sol) sol = score;
    memset(uzf, 0, sizeof(uzf));
    memset(uzc, 0, sizeof(uzc));
    dx = ((double)100000) /
         (100 * (i - 1) + 100 - hl + ((i % 2) ? (100 - hr) : hr));
    x = dx * (100 - hl);
    score = bounce(x, dx, 1, i);
    if (score > sol) sol = score;
  }
  printf("%d\n", sol);
  return 0;
}
