#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
const int M = 300;
int v[110], l[110], r[110], second[110], n;
long long vec(pair<long long, long long> a, pair<long long, long long> b,
              pair<long long, long long> c) {
  return (b.first - a.first) * (c.second - a.second) -
         (b.second - a.second) * (c.first - a.first);
}
int sign(long long first) { return first < 0 ? -1 : first == 0 ? 0 : +1; }
bool intersect_1d(long long a, long long b, long long c, long long d) {
  if (a > b) swap(a, b);
  if (c > d) swap(c, d);
  return max(a, c) <= min(b, d);
}
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 intersect_1d(a.first, b.first, c.first, d.first) &&
         intersect_1d(a.second, b.second, c.second, d.second) &&
         sign(vec(a, b, c)) * sign(vec(a, b, d)) <= 0 &&
         sign(vec(c, d, a)) * sign(vec(c, d, b)) <= 0;
}
bool cross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  return intersect(
      pair<long long, long long>(x1, y1), pair<long long, long long>(x2, y2),
      pair<long long, long long>(x3, y3), pair<long long, long long>(x4, y4));
}
int solve1(int x1, int y1, int x2, int y2, int eq) {
  int res = 0;
  for (int i = 0; i < (int)(n); i++) {
    int cnt = 0;
    for (int yy = second[i]; yy >= y2; yy -= 200) {
      if (cross(x1, y1, x2, y2, l[i], yy, r[i], yy)) {
        cnt++;
        if (cnt > 1) return -INF;
      }
    }
    if (cnt) {
      res += v[i];
      eq--;
    }
  }
  if (eq != 0) return -INF;
  return res;
}
int solve2(int x1, int y1, int x2, int y2, int eq) {
  int res = 0;
  for (int i = 0; i < (int)(n); i++) {
    int cnt = 0;
    for (int yy = second[i]; yy <= y2; yy += 200) {
      if (cross(x1, y1, x2, y2, l[i], yy, r[i], yy)) {
        cnt++;
        if (cnt > 1) return -INF;
      }
    }
    if (cnt) {
      res += v[i];
      eq--;
    }
  }
  if (eq != 0) return -INF;
  return res;
}
int main() {
  int h1, h2;
  cin >> h1 >> h2;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    char tp[10];
    scanf("%d%s%d%d", &v[i], tp, &l[i], &r[i]);
    if (tp[0] == 'F') {
      second[i] = 0;
    } else {
      second[i] = 100;
    }
  }
  int res = 0;
  for (int i = -M; i <= +M; i++) {
    double first = 0, second = h1;
    double ang = atan2(i * 100 + h2, 1E5);
    int y2 = i * 100 + h2;
    if (i % 2 != 0) {
      y2 = i * 100 + 100 - h2;
    }
    int sum = 0;
    if (i < 0) {
      sum = solve1(0, h1, 100000, y2, -i);
    } else {
      sum = solve2(0, h1, 100000, y2, +i);
    }
    res = max(res, sum);
  }
  cout << res << endl;
  return 0;
}
