#include <bits/stdc++.h>
using namespace std;
const int MaxN = 105;
const double Eps = 1e-6;
pair<double, double> RealP[MaxN], VirtualP[MaxN];
double H, W, YS, YE, SegmentsY[MaxN];
int NS, Value[MaxN], Sol;
pair<double, double> Segments[MaxN];
inline pair<double, double> Symmetrical(pair<double, double> P, double Y) {
  P.second = 2 * Y - P.second;
  return P;
}
inline void GetEquation(pair<double, double> P1, pair<double, double> P2,
                        double &m, double &n) {
  m = (P2.second - P1.second) / (P2.first - P1.first);
  n = P1.second - m * P1.first;
}
void BuildP(int N, int d) {
  RealP[1] = make_pair(0, YS);
  VirtualP[N] = Symmetrical(make_pair(W, YE), (d ? 0 : H));
  for (int i = N - 1; i > 1; --i, d ^= 1)
    VirtualP[i] = Symmetrical(VirtualP[i + 1], (d ^ 1 ? 0 : H));
  for (int i = 2; i <= N; ++i) {
    pair<double, double> P1 = RealP[i - 1], P2 = VirtualP[i];
    RealP[i].second = (P2.second < -Eps ? 0.0 : H);
    double m, n;
    GetEquation(P1, P2, m, n);
    RealP[i].first = (RealP[i].second - n) / m;
  }
}
int Solve(int N, int d) {
  BuildP(N, d);
  int Shot[MaxN];
  memset(Shot, 0, sizeof(Shot));
  for (int i = 2; i <= N; ++i) {
    bool Valid = false;
    for (int j = 1; j <= NS; ++j) {
      if (abs(RealP[i].second - SegmentsY[j]) < Eps &&
          Segments[j].first - Eps < RealP[i].first &&
          RealP[i].first < Segments[j].second + Eps) {
        ++Shot[j], Valid = true;
      }
    }
    if (!Valid) return 0;
  }
  int CSol = 0;
  for (int i = 1; i <= NS; ++i) CSol += (Shot[i] ? Value[i] : 0);
  for (int i = 1; i <= NS; ++i)
    if (Shot[i] > 1) CSol = 0;
  return CSol;
}
void Read() {
  W = 100000, H = 100;
  scanf("%lf %lf %d", &YS, &YE, &NS);
  for (int i = 1; i <= NS; ++i) {
    char Type;
    scanf("%d %c %lf %lf", &Value[i], &Type, &Segments[i].first,
          &Segments[i].second);
    SegmentsY[i] = Type == 'F' ? 0 : H;
  }
}
void Print() { printf("%d\n", Sol); }
int main() {
  Read();
  for (int i = 2; i <= NS + 1; ++i)
    Sol = max(Sol, max(Solve(i, 0), Solve(i, 1)));
  Print();
  return 0;
}
