#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) {
  bool va[105], vb[105];
  memset(va, 0, sizeof(va));
  memset(vb, 0, sizeof(vb));
  int sum = 0, h = n * 100 - hr + hl;
  if (n % 2) h = (n - 1) * 100 + hr + hl;
  double d = 1.0 * hl * (1e5) / (h * 1.0);
  for (int i = 1; i <= n; ++i) {
    if (i > 1) d += (1e5) / (h * 1.0) * 100.0;
    if (i % 2) {
      int tag = shoot_in(d, B);
      if (tag == -1 || vb[tag]) return -1;
      vb[tag] = 1;
      sum += B[tag].score;
    } else {
      int tag = shoot_in(d, A);
      if (tag == -1 || va[tag]) return -1;
      va[tag] = 1;
      sum += A[tag].score;
    }
  }
  return sum;
}
int main() {
  mirror mi[2][105];
  int num[2] = {0, 0}, hl, hr, n, ans = 0;
  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];
  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;
}
