#include <bits/stdc++.h>
using namespace std;
class Mirror {
 public:
  int value;
  int start, end;
  int flag;
};
Mirror m[100];
bool used[100];
int max(int a, int b) { return (a > b) ? a : b; }
int up(int h1, int h2, int N) {
  int result = 0;
  double beta;
  for (int i = 1; i <= N; i++) {
    if (i % 2 == 0)
      beta = (double)(100 - h1 + h2 + (i - 1) * 100) / (double)100000;
    else
      beta = (double)(100 - h1 + 100 - h2 + (i - 1) * 100) / (double)100000;
    memset(used, 0, sizeof(used));
    int sum = 0;
    for (int j = 0; j < i; j++) {
      double pos = (double)(100 - h1 + 100 * j) / beta;
      bool find = false;
      for (int k = 0; k < N; k++) {
        if (used[k]) continue;
        if (m[k].flag == 0) {
          if (j % 2 == 0) continue;
        } else {
          if (j % 2 == 1) continue;
        }
        if (m[k].start <= pos && m[k].end >= pos) {
          sum += m[k].value;
          used[k] = true;
          find = true;
          break;
        }
      }
      if (!find) {
        sum = 0;
        break;
      }
    }
    result = max(result, sum);
  }
  return result;
}
int down(int h1, int h2, int N) {
  int result = 0;
  double beta;
  for (int i = 1; i <= N; i++) {
    if (i % 2 == 1)
      beta = (double)(h1 + h2 + (i - 1) * 100) / (double)100000;
    else
      beta = (double)(h1 + 100 - h2 + (i - 1) * 100) / (double)100000;
    memset(used, 0, sizeof(used));
    int sum = 0;
    for (int j = 0; j < i; j++) {
      double pos = (double)(h1 + 100 * j) / beta;
      bool find = false;
      for (int k = 0; k < N; k++) {
        if (used[k]) continue;
        if (m[k].flag == 1) {
          if (j % 2 == 0) continue;
        } else {
          if (j % 2 == 1) continue;
        }
        if (m[k].start <= pos && m[k].end >= pos) {
          sum += m[k].value;
          used[k] = true;
          find = true;
          break;
        }
      }
      if (!find) {
        sum = 0;
        break;
      }
    }
    result = max(result, sum);
  }
  return result;
}
int main() {
  int N;
  int h1, h2;
  char str[5];
  while (3 == scanf("%d%d%d", &h1, &h2, &N)) {
    for (int i = 0; i < N; i++) {
      scanf("%d", &m[i].value);
      scanf("%s", str);
      if (str[0] == 'T')
        m[i].flag = 1;
      else
        m[i].flag = 0;
      scanf("%d%d", &m[i].start, &m[i].end);
    }
    int result = 0;
    result = max(result, up(h1, h2, N));
    result = max(result, down(h1, h2, N));
    printf("%d\n", result);
  }
  return 0;
}
