#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
const int LEN = 100000;
const int HIG = 100;
const double EPS = 0.0001;
int hl, hr, n;
struct seg {
  int a, b;
  int v;
  seg(int aa, int bb, int cc) {
    a = aa;
    b = bb;
    v = cc;
  }
};
vector<seg> gora;
vector<seg> dol;
void readData() {
  int v, a, b;
  char c;
  scanf("%d%d%d", &hl, &hr, &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d %c%d%d", &v, &c, &a, &b);
    if (c == 'T') {
      gora.push_back(seg(a, b, v));
    } else {
      dol.push_back(seg(a, b, v));
    }
  }
}
int segin(double xx, seg t) {
  if (((double)t.a <= xx + EPS) && ((double)t.b >= xx - EPS)) {
    return t.v;
  }
  return -1;
}
int dajVal(double t, vector<seg>& x) {
  int si = x.size();
  int res = -1;
  for (int i = 0; i < (si); ++i) {
    res = max(res, segin(t, x[i]));
  }
  return res;
}
int dajWhe(double t, vector<seg>& x) {
  int si = x.size();
  for (int i = 0; i < (si); ++i) {
    if (segin(t, x[i]) > -1) return i;
  }
  return -1;
}
int sprawdz(int t) {
  int ll, rr;
  double pos;
  double start, finish;
  int leng;
  if (t % 2 == 0) {
    ll = hl;
    rr = HIG - hr;
  } else {
    ll = hl;
    rr = hr;
  }
  leng = ll + rr + (t - 1) * HIG;
  start = ((double)ll * LEN) / leng;
  finish = ((double)rr * LEN) / leng;
  if (t > 1)
    pos = (LEN - start - finish) / (t - 1);
  else
    pos = 1;
  double obe = start;
  int res1 = 0, res2 = 0;
  bool zle1 = false;
  bool zle2 = false;
  int l1, l2;
  int ttt;
  l1 = -1;
  l2 = -1;
  for (int i = 0; i < (t); ++i) {
    if (i % 2 == 1) {
      ttt = dajVal(obe, gora);
      if (ttt == -1 || dajWhe(obe, gora) == l1) {
        zle1 = true;
      }
      l1 = dajWhe(obe, gora);
      res1 += ttt;
    } else {
      ttt = dajVal(obe, dol);
      if (ttt == -1 || dajWhe(obe, dol) == l2) {
        zle1 = true;
      }
      l2 = dajWhe(obe, dol);
      res1 += ttt;
    }
    obe += pos;
  }
  ll = HIG - ll;
  rr = HIG - rr;
  leng = ll + rr + (t - 1) * HIG;
  start = ((double)ll * LEN) / leng;
  finish = ((double)rr * LEN) / leng;
  if (t > 1)
    pos = (LEN - start - finish) / (t - 1);
  else
    pos = 1;
  obe = start;
  res2 = 0;
  zle2 = false;
  l1 = -1;
  l2 = -1;
  for (int i = 0; i < (t); ++i) {
    if (i % 2 == 0) {
      ttt = dajVal(obe, gora);
      if (ttt == -1 || l1 == dajWhe(obe, gora)) {
        zle2 = true;
      }
      l1 = dajWhe(obe, gora);
      res2 += ttt;
    } else {
      ttt = dajVal(obe, dol);
      if (ttt == -1 || l2 == dajWhe(obe, dol)) {
        zle2 = true;
      }
      l2 = dajWhe(obe, dol);
      res2 += ttt;
    }
    obe += pos;
  }
  if (zle1 && zle2) return -1;
  if (zle1) return res2;
  if (zle2) return res1;
  return max(res1, res2);
}
int main() {
  int res = 0;
  readData();
  for (int i = 1; i <= (102); ++i) {
    res = max(res, sprawdz(i));
  }
  printf("%d\n", res);
}
