#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int tot;
int visit[2][maxn];
int cnt[2];
int ans;
int hl, hr, n;
struct Point {
  int x, y, v;
  Point(int x = 0, int y = 0, int v = 0) : x(x), y(y), v(v) {}
} p[2][maxn];
const double eps = 1e-8;
int sign(double a) { return a < -eps ? -1 : a > eps; }
bool cmp(Point a, Point b) { return a.x < b.x; }
void solve(int hl, int hr, int now) {
  tot++;
  double x = hl * 1.0e5 / (hl + hr + 0.0);
  int res = 0;
  int ti[2] = {0};
  for (; ti[now] < cnt[now]; ti[now]++)
    if (sign(x - p[now][ti[now]].x) >= 0 && sign(x - p[now][ti[now]].y) <= 0) {
      res += p[now][ti[now]].v;
      visit[now][ti[now]] = tot;
      break;
    }
  if (ti[now] >= cnt[now]) return;
  double tx = x;
  for (; 1;) {
    tx += x / hl * 100;
    now ^= 1;
    if (sign(tx - 1e5) > 0) break;
    for (; ti[now] < cnt[now]; ti[now]++)
      if (sign(tx - p[now][ti[now]].x) >= 0 &&
          sign(tx - p[now][ti[now]].y) <= 0) {
        res += p[now][ti[now]].v;
        if (visit[now][ti[now]] == tot) return;
        visit[now][ti[now]] = tot;
        break;
      }
    if (ti[now] >= cnt[now]) return;
  }
  ans = max(ans, res);
}
int main() {
  char s[10];
  while (~scanf("%d%d%d", &hl, &hr, &n)) {
    cnt[0] = cnt[1] = 0;
    for (int i = 0; i < n; i++) {
      int v, c, a, b;
      scanf("%d%s%d%d", &v, s, &a, &b);
      if (s[0] == 'T')
        p[0][cnt[0]++] = Point(a, b, v);
      else
        p[1][cnt[1]++] = Point(a, b, v);
    }
    sort(p[0], p[0] + cnt[0], cmp);
    sort(p[1], p[1] + cnt[1], cmp);
    ans = 0;
    for (int i = 0; i <= n + 10; i++) {
      if (i & 1) {
        solve(100 - hl, hr + 100 * i, 0);
        solve(hl, 100 - hr + 100 * i, 1);
      } else {
        solve(hl, hr + 100 * i, 1);
        solve(100 - hl, 100 - hr + 100 * i, 0);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
