#include <bits/stdc++.h>
using namespace std;
struct Bk {
  int y, l, r, bel;
  Bk(int _y, int _l, int _r, int _bel) : y(_y), l(_l), r(_r), bel(_bel) {}
  Bk() {}
} B[1020304];
int n, hl, hr, pt[1020304], app[120], fl[1020304];
int main() {
  cin >> hl >> hr >> n;
  int Tot = 0;
  for (int i = 1; i <= n; ++i) {
    int p, l, r, y;
    char f;
    scanf("%d%*c%c%d%d", &p, &f, &l, &r);
    pt[i] = p;
    if (f == 'T')
      y = 100;
    else
      y = 0;
    fl[i] = y == 100;
    for (int j = -n; j <= n; ++j) {
      B[++Tot] = Bk(y + 200 * j, l, r, i);
    }
  }
  pair<double, double> sPt = make_pair(0, hl);
  int ans = 0;
  for (int j = -2 * n; j <= 2 * n; ++j) {
    if (j == -3) {
      int z = j;
    }
    pair<double, double> nPt =
        make_pair(100000, ((abs(j) & 1) ? (100 - hr) : (hr)) + 100 * j);
    double k;
    if (nPt.second != hl)
      k = 100000. / (nPt.second - sPt.second);
    else
      continue;
    memset(app, 0, sizeof(app));
    int tAns = 0;
    pair<int, int> Cnt = make_pair(0, 0);
    for (int i = 1; i <= Tot; ++i) {
      double tConv = ((double)B[i].y - hl) * k;
      if (tConv >= B[i].l && tConv <= B[i].r) {
        ++app[B[i].bel];
        if (app[B[i].bel] > 1) {
          tAns = -(0x3f3f3f3f);
          break;
        }
        tAns += pt[B[i].bel];
        if (fl[B[i].bel])
          ++Cnt.first;
        else
          ++Cnt.second;
      }
    }
    if (tAns == 110) {
      int z = tAns;
    }
    if (Cnt.first + Cnt.second == abs(j)) ans = max(ans, tAns);
  }
  cout << ans << endl;
  return 0;
}
