#include <bits/stdc++.h>
using namespace std;
struct pnt {
  long long x, y, v;
  pnt() { x = y = v = 1e9; }
} inp[2][120];
long long hl, hr, n, t[2], ans;
long long pxl, pyl, pxr = 1e5, pyr, rlen;
bool fun(pnt a, pnt b) { return a.x <= b.x; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> hl >> hr >> n;
  for (long long i = 1, v, x, y; i <= n; ++i) {
    char s;
    cin >> v >> s >> x >> y;
    t[!(s - 'F')]++;
    inp[!(s - 'F')][t[!(s - 'F')]].v = v;
    inp[!(s - 'F')][t[!(s - 'F')]].x = x;
    inp[!(s - 'F')][t[!(s - 'F')]].y = y;
  }
  sort(inp[0] + 1, inp[0] + t[0] + 1, fun);
  sort(inp[1] + 1, inp[1] + t[1] + 1, fun);
  if (!t[0] or !t[1]) {
    cout << 0 << endl;
    return 0;
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (long long i = 1; i <= n; ++i) {
    long long tyl = 100, tyr = 100;
    long long res = 0, cnt[2] = {1, 1};
    rlen = 100 - rlen;
    pyr += 2 * rlen;
    bool chk = 0, sgn = 0;
    for (long long j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          ++cnt[sgn];
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl += 100;
      tyr += 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (int i = 1; i <= n; ++i) {
    long long tyl = 0, tyr = 0;
    long long res = 0, cnt[2] = {1, 1};
    bool sgn = 1, chk = 0;
    pyr -= 2 * rlen;
    rlen = 100 - rlen;
    for (int j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          cnt[sgn]++;
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl -= 100;
      tyr -= 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
