#include <bits/stdc++.h>
using namespace std;
bool intersects(int hl, int hr, int a, int b, int y) {
  long long ux = 100000;
  long long uy = hr - hl;
  long long ax = a;
  long long ay = y - hl;
  long long bx = b;
  long long by = y - hl;
  long long pa = ux * ay - uy * ax;
  long long pb = ux * by - uy * bx;
  return (pa <= 0 && pb >= 0) || (pa >= 0 && pb <= 0);
}
int main() {
  int hl, hr, n;
  scanf("%d%d%d", &hl, &hr, &n);
  vector<int> V(n), A(n), B(n), H, D;
  for (int i = 0; i < (int)(n); ++i) {
    char c;
    scanf("%d %c%d%d", &V[i], &c, &A[i], &B[i]);
    if (c == 'F') {
      D.push_back(i);
    } else {
      H.push_back(i);
    }
  }
  int res = 0;
  for (int q = (int)(-n); q <= (int)(n); ++q) {
    int h = q * 100 + ((q % 2) ? 100 - hr : hr);
    vector<bool> U(n, false);
    int score = 0;
    bool okok = true;
    for (int w = (int)(1); w <= (int)(q); ++w) {
      const vector<int>& M = (w % 2) ? H : D;
      bool ok = false;
      for (__typeof((M).begin()) i = (M).begin(); i != (M).end(); ++i)
        if (intersects(hl, h, A[*i], B[*i], w * 100)) {
          if (U[*i]) break;
          U[*i] = true;
          score += V[*i];
          ok = true;
          break;
        }
      if (!ok) {
        okok = false;
        break;
      }
    }
    for (int w = (int)(0); w >= (int)(q + 1); --w) {
      const vector<int>& M = (w % 2) ? H : D;
      bool ok = false;
      for (__typeof((M).begin()) i = (M).begin(); i != (M).end(); ++i)
        if (intersects(hl, h, A[*i], B[*i], w * 100)) {
          if (U[*i]) break;
          U[*i] = true;
          score += V[*i];
          ok = true;
          break;
        }
      if (!ok) {
        okok = false;
        break;
      }
    }
    if (okok) res = max(res, score);
  }
  printf("%d\n", res);
}
