#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
pair<pair<int, int>, int> mirror[2][111];
int N1, N2, hl, hr, N;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int calc() {
  int res = 0;
  long long L = 100000;
  long long dy = hr - hl;
  for (int ii = (0); ii < (N + 1); ii++) {
    if (ii & 1) {
      dy -= (100 - hr) * 2;
    } else {
      dy -= 2 * hr;
    }
    long long ay = -dy;
    long long x = hl * L;
    long long dx = 100 * L;
    int ib = 0, it = 0;
    int boni = 0;
    while (true) {
      if (x >= L * ay) {
        res = max(res, boni);
        break;
      }
      while (ib < N2 && mirror[1][ib].first.second * ay < x) {
        ib++;
      }
      if (ib == N2) break;
      if (mirror[1][ib].first.first * ay > x) break;
      boni += mirror[1][ib++].second;
      x += dx;
      if (x >= L * ay) {
        res = max(res, boni);
        break;
      }
      while (it < N1 && mirror[0][it].first.second * ay < x) {
        it++;
      }
      if (it == N1) break;
      if (mirror[0][it].first.first * ay > x) break;
      boni += mirror[0][it++].second;
      x += dx;
    }
  }
  return res;
}
int main() {
  N1 = 0;
  N2 = 0;
  cin >> hl >> hr >> N;
  for (int i = (0); i < (N); i++) {
    int v, a, b;
    string tmp;
    cin >> v >> tmp >> a >> b;
    if (tmp == "T") {
      mirror[0][N1++] = make_pair(make_pair(a, b), v);
    } else if (tmp == "F") {
      mirror[1][N2++] = make_pair(make_pair(a, b), v);
    } else {
      cout << "FAIL\n";
    }
  }
  sort(mirror[0], mirror[0] + N1);
  sort(mirror[1], mirror[1] + N2);
  int res = calc();
  for (int i = (0); i < (N); i++) swap(mirror[0][i], mirror[1][i]);
  hl = 100 - hl;
  hr = 100 - hr;
  swap(N1, N2);
  res = max(calc(), res);
  cout << res << endl;
  return 0;
}
