#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-5;
struct mirror {
  int s, t, co;
  bool type;
} m[110];
int hl, hr, CC, n;
char str[110];
bool vis[110];
void init() {
  scanf("%d%d%d", &hl, &hr, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%s%d%d", &m[i].co, str, &m[i].s, &m[i].t);
    if (str[0] == 'F')
      m[i].type = false;
    else
      m[i].type = true;
  }
}
void calc(int t, bool f) {
  int sco = 0;
  memset(vis, 0, sizeof(vis));
  hl = 100 - hl, hr = 100 - hr;
  int len = ((t & 1) ? ((t + 1) * 100 - hr) : t * 100 + hr) - hl;
  for (int l = 1; l <= t; l++) {
    bool flag = false;
    for (int i = 1; i <= n; i++)
      if ((f == m[i].type) == (l & 1)) {
        double h = 100000.0 * (double)(l * 100 - hl) / (double)len;
        if (((double)m[i].s) - EPS < h && h < ((double)m[i].t) + EPS) {
          if (vis[i]) return;
          vis[i] = true;
          sco += m[i].co;
          flag = true;
        }
      }
    if (!flag) return;
  }
  CC = max(CC, sco);
}
void solve() {
  hl = 100 - hl, hr = 100 - hr;
  for (int i = 1; i <= n; i++) calc(i, 1), calc(i, 0);
  cout << CC << endl;
}
int main() {
  init();
  solve();
  return 0;
}
