#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int m;
  double h1, h2;
  vector<pair<pair<double, double>, int> > atas, bawah;
  scanf("%lf%lf%d", &h1, &h2, &m);
  for (int i = 0; i < m; i++) {
    pair<pair<double, double>, int> buff;
    char p[5];
    scanf("%d%s%lf%lf", &buff.second, p, &buff.first.first, &buff.first.second);
    if (p[0] == 'T')
      atas.push_back(buff);
    else
      bawah.push_back(buff);
  }
  sort(atas.begin(), atas.end());
  sort(bawah.begin(), bawah.end());
  int ans = 0;
  for (int pantul = 1; pantul <= m; pantul++) {
    bool able;
    double x, now;
    int status, bwh, ats, bbwh, bats, val;
    if (pantul % 2 == 1)
      x = 100000.0 / (h1 / 100.0 + (double)((pantul - 1) * 1.0) + h2 / 100.0);
    else
      x = 100000.0 /
          (h1 / 100.0 + (double)((pantul - 1) * 1.0) + (100.0 - h2) / 100.0);
    now = x * h1 / 100.0;
    able = true;
    status = 0;
    bwh = 0;
    ats = 0;
    bbwh = -1;
    bats = -1;
    val = 0;
    while (now <= 100000.0) {
      able = false;
      if (status == 0) {
        while (bwh != bawah.size()) {
          if (bawah[bwh].first.first <= now && bawah[bwh].first.second >= now) {
            if (bwh == bbwh)
              break;
            else {
              bbwh = bwh;
              val += bawah[bwh].second;
              status = 1;
              now += x;
              able = true;
              break;
            }
          } else if (bawah[bwh].first.first > now)
            break;
          else
            bwh++;
        }
      } else if (status == 1) {
        while (ats != atas.size()) {
          if (atas[ats].first.first <= now && atas[ats].first.second >= now) {
            if (ats == bats)
              break;
            else {
              bats = ats;
              val += atas[ats].second;
              status = 0;
              now += x;
              able = true;
              break;
            }
          } else if (atas[ats].first.first > now)
            break;
          else
            ats++;
        }
      }
      if (!able) break;
    }
    if (able) {
      ans = max(ans, val);
    }
    if (pantul % 2 == 1) {
      x = 100000.0 / ((100.0 - h1) / 100.0 + (double)((pantul - 1) * 1.0) +
                      (100.0 - h2) / 100.0);
    } else {
      x = 100000.0 /
          ((100.0 - h1) / 100.0 + (double)((pantul - 1) * 1.0) + h2 / 100.0);
    }
    now = x * (100.0 - h1) / 100.0;
    able = true;
    status = 1;
    bwh = 0;
    ats = 0;
    bbwh = -1;
    bats = -1;
    val = 0;
    while (now <= 100000.0) {
      able = false;
      if (status == 0) {
        while (bwh != bawah.size()) {
          if (bawah[bwh].first.first <= now && bawah[bwh].first.second >= now) {
            if (bwh == bbwh)
              break;
            else {
              val += bawah[bwh].second;
              status = 1;
              now += x;
              able = true;
              bbwh = bwh;
              break;
            }
          } else if (bawah[bwh].first.first > now)
            break;
          else
            bwh++;
        }
      } else if (status == 1) {
        while (ats != atas.size()) {
          if (atas[ats].first.first <= now && atas[ats].first.second >= now) {
            if (ats == bats)
              break;
            else {
              val += atas[ats].second;
              status = 0;
              now += x;
              able = true;
              bats = ats;
              break;
            }
          } else if (atas[ats].first.first > now)
            break;
          else
            ats++;
        }
      }
      if (!able) break;
    }
    if (able) {
      ans = max(ans, val);
    }
  }
  printf("%d\n", ans);
  return 0;
}
