#include <bits/stdc++.h>
typedef struct smirror {
  int left, right, score;
} mirror;
int max(int a, int b) { return a > b ? a : b; }
int shoot_in(double x, mirror a[]) {
  for (int i = 1; i <= a[0].score; ++i)
    if (a[i].left <= x && x <= a[i].right) return i;
  return -1;
}
int deal(int n, mirror A[], mirror B[], int hl, int hr) {
  int counter = 1, hx = hl, tag, score0 = 0;
  int h0;
  if (n % 2 == 1)
    h0 = hl + hr + (n - 1) * 100;
  else
    h0 = n * 100 + hl - hr;
  bool ba[105], bb[105];
  memset(ba, 0, sizeof(ba));
  memset(bb, 0, sizeof(bb));
  double d;
  for (counter = 1; counter <= n; counter++) {
    d = (hx * 100000) / (1.0 * h0);
    if (counter % 2 == 1) {
      tag = shoot_in(d, B);
      if (tag >= 0 && !bb[tag]) {
        score0 += B[tag].score;
        bb[tag] = 1;
      } else {
        score0 = 0;
        break;
      }
    } else {
      tag = shoot_in(d, A);
      if (tag >= 0 && !ba[tag]) {
        score0 += A[tag].score;
        ba[tag] = 1;
      } else {
        score0 = 0;
        break;
      }
    }
    hx += 100;
  }
  return score0;
}
int main() {
  mirror mi[2][105];
  int num[2] = {0, 0}, hl, hr, n;
  scanf("%d%d%d", &hl, &hr, &n);
  while (n--) {
    int score, set = 1;
    char t;
    scanf("%d %c", &score, &t);
    if (t == 'T') set = 0;
    ++num[set];
    scanf("%d %d", &mi[set][num[set]].left, &mi[set][num[set]].right);
    mi[set][num[set]].score = score;
  }
  mi[0][0].score = num[0], mi[1][0].score = num[1];
  int ans = 0;
  for (int i = 1; i <= num[0] + num[1]; ++i)
    ans = max(ans, deal(i, mi[0], mi[1], hl, hr));
  for (int i = 1; i <= num[0] + num[1]; ++i)
    ans = max(ans, deal(i, mi[1], mi[0], 100 - hl, 100 - hr));
  printf("%d\n", ans);
  return 0;
}
