#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return a < 0 ? (-a) : a;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
struct Segment {
  long long x1, x2;
  long long cost;
  friend bool operator<(const Segment &s1, const Segment &s2) {
    return s1.x1 < s2.x2;
  }
};
vector<Segment> v[2];
const long long h = 100;
const long long l = 100000;
long long calc(long long hl, long long hr, int cb, int ct) {
  vector<bool> f[] = {vector<bool>(v[0].size(), false),
                      vector<bool>(v[1].size(), false)};
  long long res = 0;
  double p;
  if (ct < cb)
    p = (hl + hr) + 2 * ct * h;
  else
    p = (hl - hr) + 2 * ct * h;
  double a = (double)l * h / p;
  double d = a * hl / h;
  int cur[2];
  cur[0] = cur[1] = 0;
  for (int i = 0; d < l; i++) {
    int k = i % 2;
    while (cur[k] < v[k].size() && v[k][cur[k]].x2 < d) cur[k]++;
    if (cur[k] >= v[k].size() || v[k][cur[k]].x1 > d || f[k][cur[k]]) return 0;
    f[k][cur[k]] = true;
    res += v[k][cur[k]].cost;
    d += a;
  }
  return res;
}
long long Solve(long long hl, long long hr) {
  long long res = 0;
  for (int i = 1; i <= v[0].size(); i++) {
    res = max(res, max(calc(hl, hr, i, i - 1), calc(hl, hr, i, i)));
  }
  return res;
}
int main() {
  int hl, hr;
  int n;
  cin >> hl >> hr >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    Segment s;
    char c;
    cin >> s.cost >> c >> s.x1 >> s.x2;
    if (c == 'T') {
      v[1].push_back(s);
    } else {
      v[0].push_back(s);
    }
  }
  sort((v[0]).begin(), (v[0]).end());
  sort((v[1]).begin(), (v[1]).end());
  long long res = 0;
  res = max(res, Solve(hl, hr));
  swap(v[0], v[1]);
  res = max(res, Solve(h - hl, h - hr));
  swap(v[0], v[1]);
  cout << res << endl;
  return 0;
}
