#include <bits/stdc++.h>
using namespace std;
const int D5 = 100000;
struct mirror {
  int a, b, c;
  bool operator<(const mirror& x) const { return a < x.a; }
};
int h1, h2, n;
vector<mirror> gora, dol;
int main() {
  scanf("%d %d %d", &h1, &h2, &n);
  for (int i = 0; i < (n); ++i) {
    mirror temp;
    char c;
    scanf("%d %c %d %d", &temp.c, &c, &temp.a, &temp.b);
    if (c == 'T')
      gora.push_back(temp);
    else
      dol.push_back(temp);
  }
  sort(gora.begin(), gora.end());
  sort(dol.begin(), dol.end());
  int best = 0;
  for (int k = n; k >= -n; --k) {
    if (k == 0) continue;
    int celY;
    if (k % 2 == 0)
      celY = k * 100 + h2;
    else
      celY = (k + 1) * 100 - h2;
    int wskG = 0, wskD = 0;
    int pd = -1, pg = -1;
    int a = (celY - h1), b = h1;
    int nres = 0;
    if (k < 0) {
      for (int j = 0; j > k; --j) {
        if (abs(j) % 2 == 0) {
          while (wskD < (int)dol.size() &&
                 !(((j * 100 - b) * D5 <= dol[wskD].a * a) &&
                   ((j * 100 - b) * D5 >= dol[wskD].b * a))) {
            wskD++;
          }
          if (wskD < (int)dol.size()) {
            nres += dol[wskD].c;
            wskD++;
          } else {
            nres = -1000000;
          }
        } else {
          while (wskG < (int)gora.size() &&
                 !(((j * 100 - b) * D5 <= gora[wskG].a * a) &&
                   ((j * 100 - b) * D5 >= a * gora[wskG].b))) {
            wskG++;
          }
          if (wskG < (int)gora.size()) {
            nres += gora[wskG].c;
            wskG++;
          } else {
            nres = -1000000;
          }
        }
      }
    } else {
      for (int j = 1; j <= k; ++j) {
        if (k == -100) {
          printf("wskD : %d, wskG : %d\n", wskD, wskG);
          double x = (double)(j * 100 - b) * D5 / a;
          printf("x : %.5lf\n", x);
        }
        if (abs(j) % 2 == 0) {
          while (wskD < (int)dol.size() &&
                 !(((j * 100 - b) * D5 >= dol[wskD].a * a) &&
                   ((j * 100 - b) * D5 <= dol[wskD].b * a))) {
            wskD++;
          }
          if (wskD < (int)dol.size()) {
            nres += dol[wskD].c;
            wskD++;
          } else {
            nres = -1000000;
          }
        } else {
          while (wskG < (int)gora.size() &&
                 !(((j * 100 - b) * D5 >= gora[wskG].a * a) &&
                   ((j * 100 - b) * D5 <= a * gora[wskG].b))) {
            wskG++;
          }
          if (wskG < (int)gora.size()) {
            nres += gora[wskG].c;
            wskG++;
          } else {
            nres = -1000000;
          }
        }
      }
    }
    if (nres > best) best = nres;
  }
  printf("%d\n", best);
  return 0;
}
