#include <bits/stdc++.h>
using namespace std;
const int N = 123;
int hl, hr;
int n;
int award[N], a[N], b[N];
bool type[N];
bool mark[N];
int ans;
void compute(int t) {
  int unstable_ans = 0;
  double alpha = (((t & 1) ? (hr - 100) : (-hr)) + hl + 100 * t) * .00001;
  fill(mark, mark + n, false);
  for (int i = 0, j; i < t; ++i) {
    double meetp = (i * 100 + hl) / alpha;
    for (j = 0; j < n; ++j)
      if (type[j] == (i + 1) % 2 && meetp >= a[j] && meetp <= b[j]) {
        if (mark[j]) return;
        mark[j] = true;
        unstable_ans += award[j];
        break;
      }
    if (j == n) return;
  }
  ans = max(ans, unstable_ans);
}
int main() {
  cin >> hl >> hr >> n;
  for (int i = 0; i < n; ++i) {
    char tp;
    cin >> award[i] >> tp >> a[i] >> b[i];
    type[i] = (tp == 'F');
  }
  for (int i = 1; i <= n; ++i) compute(i);
  hl = 100 - hl, hr = 100 - hr;
  for (int i = 0; i < n; ++i) type[i] = !type[i];
  for (int i = 1; i <= n; ++i) compute(i);
  cout << ans << endl;
  return 0;
}
