#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double esp = 1e-8;
const int maxn = 100 + 10;
const int maxy = 100000;
int sgn(const double &x) { return (x > esp) - (x < -esp); }
struct node {
  int a, b, id;
  node(int _a = 0, int _b = 0, int _id = 0) : a(_a), b(_b), id(_id) {}
  bool operator<(const node &x) const { return a < x.a; }
};
int hl, hr, n, value[maxn];
vector<int> top, flo;
vector<node> T, F;
void init() {
  top.clear();
  flo.clear();
  int now = 100;
  for (int i = 0; i < (n); ++i) {
    if (i % 2 == 0)
      top.push_back(now + 100 - hr);
    else
      top.push_back(now + hr);
    now += 100;
  }
  now = 0;
  for (int i = 0; i < (n); ++i) {
    if (i % 2 == 0)
      flo.push_back(now - hr);
    else
      flo.push_back(now - (100 - hr));
    now -= 100;
  }
}
double get_kb(double x1, double y1, double x2, double y2, double &k,
              double &b) {
  k = (y1 - y2) / (x1 - x2);
  b = -(y1 - y2) / (x1 - x2) * x1 + y1;
}
int inter(double k, double b, double y, vector<node> line) {
  double x = (y - b) / k;
  for (int i = 0; i < (((int)(line).size())); ++i) {
    if (sgn(line[i].a - x) <= 0 && sgn(x - line[i].b) <= 0) return line[i].id;
  }
  return -1;
}
int gao(vector<int> end, int w) {
  int vis[maxn];
  int ans = 0;
  for (int i = 0; i < (((int)(end).size())); ++i) {
    double k, b;
    int res = 0;
    get_kb(0, hl, maxy, end[i], k, b);
    memset(vis, 0, sizeof(vis));
    int now;
    if (w == 0)
      now = 100;
    else
      now = 0;
    for (int j = (0); j <= (i); ++j) {
      int h;
      if ((j + w) % 2 == 0) {
        h = inter(k, b, now, T);
      } else
        h = inter(k, b, now, F);
      if (h == -1 || vis[h] == 1) {
        res = 0;
        break;
      }
      res += value[h];
      vis[h] = 1;
      if (w == 0)
        now += 100;
      else
        now -= 100;
    }
    ans = max(ans, res);
  }
  return ans;
}
int main() {
  while (scanf("%d%d%d", &hl, &hr, &n) == 3) {
    init();
    F.clear();
    T.clear();
    for (int i = 0; i < (n); ++i) {
      char s[10];
      int a, b, v;
      scanf("%d%s%d%d", &v, s, &a, &b);
      if (s[0] == 'T')
        T.push_back(node(a, b, i));
      else
        F.push_back(node(a, b, i));
      value[i] = v;
    }
    sort(T.begin(), T.end());
    sort(F.begin(), F.end());
    int ans = 0;
    ans = gao(top, 0);
    ans = max(ans, gao(flo, 1));
    printf("%d\n", ans);
  }
  return 0;
}
