#include <bits/stdc++.h>
using namespace std;
int chh;
const int N = 105;
int n, hl, hr;
int pa[N], pb[N], pv[N], vis[N];
char pc[N];
int main() {
  int i, j, k, ans, tmp, x, y, m, t, res, sx, flag;
  while (~scanf("%d %d %d", &hl, &hr, &n)) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &pv[i]);
      pc[i] = getchar();
      while (pc[i] != 'T' && pc[i] != 'F') pc[i] = getchar();
      scanf("%d %d", &pa[i], &pb[i]);
    }
    m = 10000000, ans = 0;
    for (k = 1; k <= n; k++) {
      if (k & 1)
        t = (k + 1) * 100 - hl - hr;
      else
        t = 100 * k - hl + hr;
      sx = 100000 * (100 - hl);
      flag = 0, res = 0;
      fill(vis + 1, vis + n + 1, 0);
      for (i = 1; i <= k; i++) {
        for (j = 1; j <= n; j++) {
          if (vis[j]) continue;
          if (sx < pa[j] * t || sx > pb[j] * t) continue;
          if ((flag == 0 && pc[j] == 'T') || (flag == 1 && pc[j] == 'F')) {
            vis[j] = 1, res += pv[j];
            break;
          }
        }
        if (j == n + 1) break;
        sx += m, flag ^= 1;
      }
      if (i == k + 1) ans = max(ans, res);
    }
    for (k = 1; k <= n; k++) {
      if (k & 1)
        t = (k - 1) * 100 + hl + hr;
      else
        t = 100 * k + hl - hr;
      sx = 100000 * hl;
      flag = 1, res = 0;
      fill(vis + 1, vis + n + 1, 0);
      for (i = 1; i <= k; i++) {
        for (j = 1; j <= n; j++) {
          if (vis[j]) continue;
          if (sx < pa[j] * t || sx > pb[j] * t) continue;
          if ((flag == 0 && pc[j] == 'T') || (flag == 1 && pc[j] == 'F')) {
            vis[j] = 1, res += pv[j];
            break;
          }
        }
        if (j == n + 1) break;
        sx += m, flag ^= 1;
      }
      if (i == k + 1) ans = max(ans, res);
    }
    printf("%d\n", ans);
  }
  return 0;
}
