#include <bits/stdc++.h>
using namespace std;
int sgn(double x) { return x < -1e-8 ? -1 : x > 1e-8; }
int x[2][500][3];
int ct[2];
int h1, h2;
void sort() {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < ct[i]; j++) {
      for (int k = j + 1; k < ct[i]; k++) {
        if (x[i][k][1] < x[i][j][1]) {
          swap(x[i][j][0], x[i][k][0]);
          swap(x[i][j][1], x[i][k][1]);
          swap(x[i][j][2], x[i][k][2]);
        }
      }
    }
  }
}
void add(int i, int c, int a, int b) {
  x[i][ct[i]][0] = c;
  x[i][ct[i]][1] = a;
  x[i][ct[i]][2] = b;
  ct[i]++;
}
int ck(double ang, int i, int a, int b) {
  double pos = ang * (100 - h1);
  int p1 = 0, p2 = 0, ans = 0;
  for (int j = 1; j <= i; j++) {
    if (j & 1) {
      for (int k = p1; k <= ct[a]; k++) {
        if (sgn(x[a][k][1] - pos) <= 0 && sgn(x[a][k][2] - pos) >= 0) {
          ans += x[a][k][0];
          p1 = k + 1;
          break;
        } else if (k == ct[a])
          return 0;
        else {
          if (sgn(x[a][k][1] - pos) > 0) return 0;
        }
      }
    } else {
      for (int k = p2; k <= ct[b]; k++) {
        if (sgn(x[b][k][1] - pos) <= 0 && sgn(x[b][k][2] - pos) >= 0) {
          ans += x[b][k][0];
          p2 = k + 1;
          break;
        } else if (k == ct[b])
          return 0;
        else {
          if (sgn(x[b][k][1] - pos) > 0) return 0;
        }
      }
    }
    pos += 100 * ang;
  }
  return ans;
}
int gao(int a, int b) {
  if (a == 1) {
    h1 = 100 - h1, h2 = 100 - h2;
  }
  double x = h1;
  int ans = 0;
  for (int i = 1; i <= ct[a] + ct[b]; i++) {
    if (i & 1)
      x = 200 - x;
    else
      x = -x;
    double ang = 100000 / fabs(x - h2);
    ans = max(ans, ck(ang, i, a, b));
  }
  return ans;
}
int main() {
  int n;
  scanf("%d%d%d", &h1, &h2, &n);
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    char p;
    scanf("%d %c %d %d", &c, &p, &a, &b);
    if (p == 'F') {
      add(1, c, a, b);
    } else {
      add(0, c, a, b);
    }
  }
  sort();
  int ans = gao(0, 1);
  ans = max(ans, gao(1, 0));
  printf("%d\n", ans);
}
