#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, l;
char T[100000 + 10], F[100000 + 10];
int c[100 + 10];
int hl, hr;
int gao(int hl, int hr, char* t, char* f);
int main() {
  cin >> hl >> hr >> n;
  memset(T, -1, sizeof(T)), memset(F, -1, sizeof(F));
  for (int i = 0; i < (n); ++i) {
    char s[2];
    int a, b;
    scanf("%d%s%d%d", &c[i], s, &a, &b);
    char* p = (*s == 'T' ? T : F);
    for (int j = (a); j <= (b - 1); ++j) p[j] = i;
  }
  cout << max(gao(hl, hr, T, F), gao(100 - hl, 100 - hr, F, T));
  return 0;
}
int gao(int hl, int hr, char* t, char* f) {
  int y2;
  int ans = 0;
  for (int k = 1; k <= 100; ++k) {
    y2 = (k % 2 ? 100 - hr : hr) + k * 100;
    bool B[100] = {};
    int sum = 0;
    for (int i = 1; i <= k; ++i) {
      int y = i * 100;
      int x = 100000 * (y - hl) / (y2 - hl);
      char* p = (i % 2 ? t : f);
      if (p[x] == -1 || B[p[x]]) {
        sum = -1;
        break;
      } else {
        B[p[x]] = true;
        sum += c[p[x]];
      }
    }
    ans = max(sum, ans);
  }
  return ans;
}
