#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
vector<pair<pair<long long, long long>, int>> TOP;
vector<pair<pair<long long, long long>, int>> BOT;
struct pt {
  long long x, y;
  pt(long long ax, long long ay) : x(ax), y(ay) {}
};
inline long long area(pt a, pt b, pt c) {
  long long res = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
  return res;
}
inline bool intersect_1(int a, int b, int c, int d) {
  if (a > b) swap(a, b);
  if (c > d) swap(c, d);
  return max(a, c) <= min(b, d);
}
bool intersectx(pt a, pt b, pt c, pt d) {
  return intersect_1(a.x, b.x, c.x, d.x) && intersect_1(a.y, b.y, c.y, d.y) &&
         area(a, b, c) * area(a, b, d) <= 0 &&
         area(c, d, a) * area(c, d, b) <= 0;
}
bool intersect(pair<long long, long long> a, pair<long long, long long> b,
               pair<long long, long long> c, pair<long long, long long> d) {
  return intersectx(pt(a.first, a.second), pt(b.first, b.second),
                    pt(c.first, c.second), pt(d.first, d.second));
}
bool is_in_top(double val) {
  int L = 0, R = int((TOP).size()) - 1;
  while (abs(L - R) > 1) {
    int v = (L + R) / 2;
    if (TOP[v].first.first > val)
      R = v;
    else
      L = v;
  }
  while (L < int((TOP).size()) - 1 && TOP[L].first.first <= val) L++;
  L--;
  return (TOP[L].first.first >= val && TOP[L].first.second <= val);
}
bool is_in_bot(double val) {
  int L = 0, R = int((BOT).size()) - 1;
  while (abs(L - R) > 1) {
    int v = (L + R) / 2;
    if (BOT[v].first.first > val)
      R = v;
    else
      L = v;
  }
  while (L < int((BOT).size()) - 1 && BOT[L].first.first <= val) L++;
  L--;
  return (BOT[L].first.first >= val && BOT[L].first.second <= val);
}
int h1, h2;
vector<pair<pair<long long, long long>, int>> seg[2];
int solveUp() {
  int N = int((TOP).size()) + int((BOT).size());
  N *= 4;
  int res = 0;
  for (int i = (0); i < (N); ++i) {
    vector<bool> used_seg[2];
    used_seg[0].resize(int((seg[0]).size()), false);
    used_seg[1].resize(int((seg[1]).size()), false);
    int Tres = 0;
    bool ok = true;
    pair<long long, long long> start = make_pair(0, h1);
    pair<long long, long long> finish =
        make_pair(100000, i * 100 + (i % 2 == 0 ? h2 : 100 - h2));
    for (int j = (0); j < (i); ++j) {
      bool inter = false;
      for (int k = (0); k < (int((seg[j % 2]).size())); ++k) {
        pair<long long, long long> A =
            make_pair(seg[j % 2][k].first.first, (j + 1) * 100);
        pair<long long, long long> B =
            make_pair(seg[j % 2][k].first.second, (j + 1) * 100);
        if (intersect(A, B, start, finish)) {
          inter = true;
          if (used_seg[j % 2][k]) {
            ok = false;
            break;
          }
          Tres += seg[j % 2][k].second;
          used_seg[j % 2][k] = true;
          break;
        }
      }
      if (!inter) ok = false;
    }
    if (ok) res = max(res, Tres);
  }
  return res;
}
int main() {
  int n;
  cin >> h1 >> h2 >> n;
  for (int i = (0); i < (n); ++i) {
    int score, L, R;
    char TYPE;
    cin >> score >> TYPE >> L >> R;
    if (TYPE == 'T')
      TOP.push_back(make_pair(make_pair(L, R), score));
    else
      BOT.push_back(make_pair(make_pair(L, R), score));
  }
  sort((TOP).begin(), (TOP).end());
  sort((BOT).begin(), (BOT).end());
  seg[0] = TOP;
  seg[1] = BOT;
  int res = solveUp();
  swap(seg[1], seg[0]);
  h1 = 100 - h1;
  h2 = 100 - h2;
  res = max(res, solveUp());
  cout << res << endl;
  return 0;
}
