#include <bits/stdc++.h>
const double eps = 1e-5;
const double pi = acos(-1);
const int oo = 1000000000;
const int mod = 1000000007;
const double E = 2.7182818284590452353602874713527;
using namespace std;
struct case1 {
  int l, r, v;
} p[101], q[101];
int ans = 0;
bool cmp(case1 a, case1 b) { return a.l < b.l; }
void work(case1 p[], int s1, case1 q[], int s2, int h1, int h2) {
  for (int i = 1; i <= 4000000; i++) {
    double x, T;
    if (i & 1) {
      x = 100000. / (h1 + h2 + (i - 1) * 100) * h1;
      T = 10000000. / (h1 + h2 + (i - 1) * 100);
    } else {
      x = 100000. / (h1 + 100 - h2 + (i - 1) * 100) * h1;
      T = 10000000. / (h1 + 100 - h2 + (i - 1) * 100);
    }
    int t1 = 1, t2 = 1, v = 0;
    bool f1 = 0, f2 = 0;
    for (int j = 1; j <= i; j++) {
      if (j & 1) {
        while (t1 <= s1 && p[t1].r < x - eps) {
          f1 = 0;
          t1++;
        }
        if (f1) goto end;
        if (t1 > s1 || p[t1].l > x + eps) goto end;
        f1 = 1;
        v += p[t1].v;
      } else {
        while (t2 <= s2 && q[t2].r < x - eps) {
          f2 = 0;
          t2++;
        }
        if (f2) goto end;
        if (t2 > s2 || q[t2].l > x + eps) goto end;
        f2 = 1;
        v += q[t2].v;
      }
      x += T;
    }
    ans = max(ans, v);
  end:;
  }
}
int main() {
  int h1, h2, n, o1 = 0, o2 = 0;
  cin >> h1 >> h2 >> n;
  for (int i = 1; i <= n; i++) {
    int a, c, d;
    char b;
    scanf("%d %c%d%d", &a, &b, &c, &d);
    if (b == 'F')
      p[++o1] = (case1){c, d, a};
    else
      q[++o2] = (case1){c, d, a};
  }
  sort(p + 1, p + o1 + 1, cmp);
  sort(q + 1, q + o2 + 1, cmp);
  work(p, o1, q, o2, h1, h2);
  work(q, o2, p, o1, 100 - h1, 100 - h2);
  cout << ans << endl;
  return 0;
}
