#include <bits/stdc++.h>
int t[110000], f[110000];
int L = 100000;
int n, val[200], hr, hl;
double H = 100.0;
bool flag[200];
void Initial() {
  memset(t, 0, sizeof(t));
  memset(f, 0, sizeof(f));
}
void Input() {
  for (int i = 1; i <= n; i++) {
    int l, r;
    char str[10];
    scanf("%d%s%d%d", &val[i], str, &l, &r);
    if (str[0] == 'F') {
      for (int j = l; j <= r; j++) f[j] = i;
    } else
      for (int j = l; j <= r; j++) t[j] = i;
  }
}
void Solve() {
  int ans = 0, i, j;
  for (i = 1; i <= n; i++) {
    double tmp = 0;
    if (i & 1)
      tmp += hl / H + (i - 1) + hr / H;
    else
      tmp += hl / H + (i - 1) + (H - hr) / H;
    double l = L / tmp;
    double pos = l * hl / H;
    int des = 1, test = 0;
    memset(flag, false, sizeof(flag));
    for (j = 1; j <= i; j++) {
      if (des) {
        if (f[(int)floor(pos)] == 0 && f[(int)ceil(pos)] == 0) {
          test = -1;
          break;
        }
        int id = f[(int)floor(pos)];
        if (flag[id]) {
          test = -1;
          break;
        }
        flag[id] = true;
        test += val[id];
      } else {
        if (t[(int)floor(pos)] == 0 && t[(int)ceil(pos)] == 0) {
          test = -1;
          break;
        }
        int id = t[(int)floor(pos)];
        if (flag[id]) {
          test = -1;
          break;
        }
        flag[id] = true;
        test += val[id];
      }
      pos += l;
      des = 1 - des;
    }
    ans = ((ans) > (test) ? (ans) : (test));
    tmp = 0;
    if (i & 1)
      tmp += (H - hl) / H + (i - 1) + (H - hr) / H;
    else
      tmp += (H - hl) / H + (i - 1) + hr / H;
    l = L / tmp;
    pos = l * (H - hl) / H;
    des = 0;
    test = 0;
    memset(flag, false, sizeof(flag));
    for (j = 1; j <= i; j++) {
      if (des) {
        if (f[(int)floor(pos)] == 0 && f[(int)ceil(pos)] == 0) {
          test = -1;
          break;
        }
        int id = f[(int)floor(pos)];
        if (flag[id]) {
          test = -1;
          break;
        }
        flag[id] = true;
        test += val[id];
      } else {
        if (t[(int)floor(pos)] == 0 && t[(int)ceil(pos)] == 0) {
          test = -1;
          break;
        }
        int id = t[(int)floor(pos)];
        if (flag[id]) {
          test = -1;
          break;
        }
        flag[id] = true;
        test += val[id];
      }
      des = 1 - des;
      pos += l;
    }
    ans = ((ans) > (test) ? (ans) : (test));
  }
  printf("%d\n", ans);
}
int main() {
  int i, j;
  while (scanf("%d%d%d", &hl, &hr, &n) != EOF) {
    Initial();
    Input();
    Solve();
  }
  return 0;
}
