#include <bits/stdc++.h>
using namespace std;
int h1, h2, n, cc, fc;
int vc[101], vf[101];
pair<pair<int, int>, int> c[101], f[101];
int main() {
  cc = fc = 0;
  cin >> h1 >> h2 >> n;
  for (int i = 0; i < (n); ++i) {
    int v;
    cin >> v;
    char side;
    cin >> side;
    if (side == 'F') {
      f[fc].second = v;
      cin >> f[fc].first.first >> f[fc].first.second;
      ++fc;
    } else {
      c[cc].second = v;
      cin >> c[cc].first.first >> c[cc].first.second;
      ++cc;
    }
  }
  sort(c, c + cc);
  sort(f, f + fc);
  int res = 0;
  int const H = 100, L = 100000;
  double const EPS = 1.0e-4;
  for (int side = 0; side < (2); ++side)
    for (int k = 0; k < (n + 101); ++k) {
      int r = 0;
      char used[2][100];
      memset(used, 0, sizeof(used));
      int hh1 = h1, hh2 = h2;
      if (side == 1) hh1 = H - h1;
      if (side == 0 && (k & 1) == 1) hh2 = H - h2;
      if (side == 1 && (k & 1) == 0) hh2 = H - h2;
      double x = (hh1 * L) / double(hh1 + hh2 + k * H);
      double y = (H * x) / hh1;
      double curr = x;
      int currs = side;
      int i = 0, j = 0;
      bool good = true;
      while (L - curr > EPS) {
        if (currs == 1) {
          while (i < cc && c[i].first.second + EPS < curr) ++i;
          if (i == cc || c[i].first.first > curr + EPS || used[currs][i]) {
            if (!used[currs][i]) used[currs][i] = 0;
            good = false;
            break;
          }
          used[currs][i] = 1;
          r += c[i].second;
          curr += y;
          currs = 1 - currs;
        } else {
          while (j < fc && f[j].first.second + EPS < curr + EPS) ++j;
          if (j == fc || f[j].first.first > curr + EPS || used[currs][j]) {
            if (!used[currs][j]) used[currs][j] = 0;
            good = false;
            break;
          }
          used[currs][j] = 1;
          r += f[j].second;
          curr += y;
          currs = 1 - currs;
        }
      }
      if (good) res = max(res, r);
    }
  cout << res << endl;
  return 0;
}
