#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
int h1, h2, n, n0, n1;
int l[2][100], r[2][100], v[2][100];
int check0(double len) {
  double h = h1;
  int pre = -1, ret = 0;
  for (double pos = h * len / 100; pos < 100000 - eps; pos += len * 2) {
    bool flag = 0;
    for (int i = 0; i < n0; i++)
      if (l[0][i] - eps < pos && r[0][i] + eps > pos) {
        if (pre == i) return 0;
        pre = i;
        ret += v[0][i];
        flag = 1;
        break;
      }
    if (!flag) return 0;
  }
  pre = -1;
  for (double pos = h * len / 100 + len; pos < 100000 - eps; pos += len * 2) {
    bool flag = 0;
    for (int i = 0; i < n1; i++)
      if (l[1][i] - eps < pos && r[1][i] + eps > pos) {
        if (pre == i) return 0;
        pre = i;
        ret += v[1][i];
        flag = 1;
        break;
      }
    if (!flag) return 0;
  }
  return ret;
}
int check1(double len) {
  double h = 100 - h1;
  int pre = -1, ret = 0;
  for (double pos = h * len / 100; pos < 100000 - eps; pos += len * 2) {
    bool flag = 0;
    for (int i = 0; i < n1; i++)
      if (l[1][i] - eps < pos && r[1][i] + eps > pos) {
        if (pre == i) return 0;
        pre = i;
        ret += v[1][i];
        flag = 1;
        break;
      }
    if (!flag) return 0;
  }
  pre = -1;
  for (double pos = h * len / 100 + len; pos < 100000 - eps; pos += len * 2) {
    bool flag = 0;
    for (int i = 0; i < n0; i++)
      if (l[0][i] - eps < pos && r[0][i] + eps > pos) {
        if (pre == i) return 0;
        pre = i;
        ret += v[0][i];
        flag = 1;
        break;
      }
    if (!flag) return 0;
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &h1, &h2, &n);
  n0 = n1 = 0;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    char c;
    scanf("%d %c%d%d", &x, &c, &y, &z);
    if (c == 'F') {
      v[0][n0] = x;
      l[0][n0] = y;
      r[0][n0++] = z;
    } else {
      v[1][n1] = x;
      l[1][n1] = y;
      r[1][n1++] = z;
    }
  }
  int ans = 0;
  for (int i = 0; i <= n * 2; i++)
    ans =
        max(ans, max(check0((double)100000 / (2 * i + (double)(h1 + h2) / 100)),
                     check0((double)100000 /
                            (2 * i + 1 + (double)(h1 + 100 - h2) / 100))));
  for (int i = 0; i <= n * 2; i++)
    ans = max(ans, max(check1((double)100000 /
                              (2 * i + 1 + (double)(100 - h1 + h2) / 100)),
                       check1((double)100000 /
                              (2 * i + (double)(200 - h1 - h2) / 100))));
  printf("%d\n", ans);
  return 0;
}
