#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int h1, h2, n, ans;
int l[105], r[105], w[105];
bool vis[105], typ[105];
void swap() {
  for (int i = 1; i <= n; i++) typ[i] ^= 1;
  h1 = 100 - h1;
  h2 = 100 - h2;
}
void solve(int T) {
  memset(vis, 0, sizeof(vis));
  int x = 100000, y = (T - 1) * 100 + h1;
  if (T & 1)
    y += h2;
  else
    y += 100 - h2;
  int tot = 0, f = 1;
  double t = (double)x / y, nx = 0;
  for (int i = 1; i <= T; i++) {
    if (i == 1)
      nx += t * h1;
    else
      nx += 100 * t;
    bool flag = 0;
    for (int j = 1; j <= n; j++)
      if (typ[j] == f && l[j] <= nx && nx <= r[j]) {
        if (vis[j]) return;
        vis[j] = 1;
        tot += w[j];
        flag = 1;
        break;
      }
    f ^= 1;
    if (!flag) return;
  }
  ans = max(ans, tot);
}
int main() {
  h1 = read();
  h2 = read();
  n = read();
  char c[2];
  for (int i = 1; i <= n; i++) {
    w[i] = read();
    scanf("%s", c + 1);
    l[i] = read();
    r[i] = read();
    typ[i] = (c[1] == 'F');
  }
  for (int i = 1; i <= n; i++) solve(i);
  swap();
  for (int i = 1; i <= n; i++) solve(i);
  printf("%d\n", ans);
  return 0;
}
