#include <bits/stdc++.h>
using namespace std;
int n;
int h0, h1;
struct line {
  int p;
  int type;
  double a, b;
};
line data[100];
int go(int h0, int h1, int f) {
  int ret = 0;
  for (int i = 1; i <= 100; ++i) {
    int y = -100 * i;
    if (i % 2)
      y += 100 - h1;
    else
      y += h1;
    double a = (y - h0) / 100000.0;
    int score = 0;
    int chk[100] = {0};
    for (int j = 0; j < i; ++j) {
      int y2 = -100 * j;
      double x = (y2 - h0) / a;
      int flag = 0;
      for (int k = 0; k < n; ++k) {
        if (data[k].type != (f + j) % 2) continue;
        if (x >= data[k].a && x <= data[k].b) {
          if (chk[k]) {
            break;
          }
          chk[k] = 1;
          flag = 1;
          score += data[k].p;
          break;
        }
      }
      if (flag == 0) {
        score = -1;
        break;
      }
    }
    ret = max(ret, score);
  }
  return ret;
}
int main() {
  scanf("%d %d %d", &h0, &h1, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &data[i].p);
    char tmp[10];
    scanf("%s", tmp);
    if (*tmp == 'F')
      data[i].type = 0;
    else
      data[i].type = 1;
    scanf("%lf %lf", &data[i].a, &data[i].b);
  }
  int res = 0;
  res = max(res, go(h0, h1, 0));
  res = max(res, go(100 - h0, 100 - h1, 1));
  printf("%d\n", res);
  return 0;
}
