#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
const int H = 100000;
const double eps = 1e-6;
int hl, hr, n;
int res;
struct In {
  int vi, ci, ai, bi;
} s[MAXN];
int mark[MAXN];
double x1, x2, y;
int dblcmp(double d) {
  if (fabs(d) < eps)
    return 0;
  else
    return (d > 0) ? 1 : -1;
}
bool check(int x) {
  memset(mark, 0, sizeof(mark));
  double a1 = x1, b = 2 * y, a2 = x1 + y;
  int l, r;
  int i, j = 0;
  while (a1 < H) {
    for (i = 0; i < n; i++)
      if (s[i].ci == 1) {
        if (dblcmp(s[i].ai - a1) <= 0 && dblcmp(s[i].bi - a1) >= 0) {
          mark[i]++;
          j += s[i].vi;
          if (mark[i] > 1) return true;
          break;
        }
      }
    if (i == n) return false;
    a1 += b;
  }
  while (a2 < H) {
    for (i = 0; i < n; i++)
      if (s[i].ci == 0) {
        if (dblcmp(s[i].ai - a2) <= 0 && dblcmp(s[i].bi - a2) >= 0) {
          mark[i]++;
          j += s[i].vi;
          if (mark[i] > 1) return true;
          break;
        }
      }
    if (i == n) return false;
    a2 += b;
  }
  if (res < j) {
    res = j;
  }
  return false;
}
void even() {
  int i, j, k;
  for (i = 0; i <= MAXN; i += 2) {
    j = hl + hr + i * 100;
    x1 = (double)H * hl / (double)j;
    x2 = (double)H * hr / (double)j;
    y = (double)H * 100 / (double)j;
    check(i);
  }
}
void odd() {
  int i, j;
  for (i = 1; i <= MAXN; i += 2) {
    j = hl + 100 - hr + i * 100;
    x1 = (double)H * hl / (double)j;
    x2 = (double)H * (100 - hr) / (double)j;
    y = (double)H * 100 / (double)j;
    check(i);
  }
}
void find_res() {
  res = 0;
  even();
  odd();
  hl = 100 - hl;
  hr = 100 - hr;
  int i;
  for (i = 0; i < n; i++) {
    if (s[i].ci == 1)
      s[i].ci = 0;
    else
      s[i].ci = 1;
  }
  even();
  odd();
  printf("%d\n", res);
}
int main() {
  while (cin >> hl >> hr >> n) {
    int i, j;
    char c[5];
    for (i = 0; i < n; i++) {
      scanf("%d%s%d%d", &s[i].vi, c, &s[i].ai, &s[i].bi);
      if (c[0] == 'T')
        s[i].ci = 0;
      else
        s[i].ci = 1;
    }
    find_res();
  }
  return 0;
}
