#include <bits/stdc++.h>
int i, n, hl, hr, v[150], a[150], b[150], c[150], ans, bb[150], m;
char s[10];
void ok(int x, int y, int madao) {
  double len, j;
  int p, kirito, u, gtm, k;
  len = ((double)m * 100) / (100 * i - 100 + x + y);
  j = x * len / 100;
  p = madao;
  kirito = 0;
  memset(bb, 0, sizeof(bb));
  for (u = 1; u <= i; u++) {
    gtm = 0;
    for (k = 1; k <= n; k++) {
      if (c[k] == p && a[k] <= j && j <= b[k]) {
        gtm = k;
        break;
      }
    }
    if (gtm == 0 || bb[gtm]) return;
    j += len;
    p = (p + 1) % 2;
    kirito += v[gtm];
    bb[gtm] = 1;
  }
  if (kirito > ans) ans = kirito;
  return;
}
int main() {
  scanf("%d%d%d", &hl, &hr, &n);
  m = 100000;
  for (i = 1; i <= n; i++) {
    scanf("%d%s%d%d", &v[i], s, &a[i], &b[i]);
    if (s[0] == 'T')
      c[i] = 1;
    else
      c[i] = 0;
  }
  ans = 0;
  i = 3;
  for (i = 1; i <= n; i++)
    if (i % 2 == 1) {
      ok(100 - hl, 100 - hr, 1);
      ok(hl, hr, 0);
    } else {
      ok(100 - hl, hr, 1);
      ok(hl, 100 - hr, 0);
    }
  printf("%d\n", ans);
  return 0;
}
