#include <bits/stdc++.h>
using namespace std;
int scores[100];
int coors[100][3];
int board[2][100001];
bool done[100];
int n, hl, hr;
int testit(int d, double r, int ni) {
  for (int i = 0; i < n; i++) done[i] = false;
  int ans = 0;
  double x = 0;
  bool top = true;
  if (d == 0) {
    x = hl / r;
    top = false;
  } else {
    x = (100.0 - hl) / r;
    top = true;
  }
  if (board[top][(int)x] == -1) return -1;
  ans += scores[board[top][(int)x]];
  done[board[top][(int)x]] = true;
  for (int i = 2; i <= ni; i++) {
    x += 100.0 / r;
    top = !top;
    if (board[top][(int)x] == -1) return -1;
    if (done[board[top][(int)x]]) return -1;
    ans += scores[board[top][(int)x]];
    done[board[top][(int)x]] = true;
  }
  return ans;
}
int main() {
  cin >> hl >> hr >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  char c;
  int v, a, b;
  for (int i = 0; i <= 100000; i++) board[0][i] = -1;
  for (int i = 0; i <= 100000; i++) board[1][i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> v >> c >> a >> b;
    scores[i] = v;
    coors[i][0] = (c == 'T');
    coors[i][1] = a;
    coors[i][2] = b;
    if (b < a) swap(coors[i][2], coors[i][1]);
    for (int j = coors[i][1]; j < coors[i][2]; j++) board[coors[i][0]][j] = i;
  }
  int best = 0;
  for (int h = 1; h <= n; h += 2) {
    v = 100 * (h - 1) + hl + hr;
    double ang = (v / 100000.0);
    best = max(best, testit(0, ang, h));
    v = 100 * (h - 1) + 200 - hl - hr;
    ang = v / 100000.0;
    best = max(best, testit(1, ang, h));
  }
  for (int h = 2; h <= n; h += 2) {
    v = 100 * (h - 1) + hl + 100 - hr;
    double ang = v / 100000.0;
    best = max(best, testit(0, ang, h));
    v = 100 * (h - 1) + 100 - hl + hr;
    ang = v / 100000.0;
    best = max(best, testit(1, ang, h));
  }
  cout << best << endl;
}
