#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
template <typename T>
inline T Abs(T x) {
  return (x >= 0) ? x : -x;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
string toStr(T x) {
  stringstream st;
  st << x;
  string s;
  st >> s;
  return s;
}
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 110;
int n, v[MAXN], l[MAXN], r[MAXN], h1, h2;
string c[MAXN];
long long up(long long a, long long b) { return (a + b - 1) / b; }
long long down(long long a, long long b) { return a / b; }
int howMany(long long l, long long r, long long d) {
  l -= d;
  r -= d;
  while (l < 0) {
    l += 200;
    r += 200;
  }
  long long next = ((l + 199) / 200) * 200;
  if (next > r) return 0;
  if (next + 200 <= r) return 2;
  return 1;
}
int main() {
  cin >> h1 >> h2 >> n;
  for (int i = 0; i < (int)(n); i++) cin >> v[i] >> c[i] >> l[i] >> r[i];
  int ans = 0;
  for (int step = 0; step < (int)(2); step++) {
    for (int T = 0; T < (int)(2 * 100 * 1000); T++) {
      int hh = T * 100;
      if (T % 2 == 0)
        hh += h2;
      else
        hh += 100 - h2;
      long long A = hh - h1;
      long long B = -100000;
      long long C = -h1 * B;
      int cur = 0, cnt = 0;
      bool ok = true;
      for (int i = 0; i < (int)(n); i++) {
        long long YYYYYYYYYYYY1 = up(-A * l[i] - C, B);
        long long y2 = down(-A * r[i] - C, B);
        int num = howMany(YYYYYYYYYYYY1, y2, (c[i] == "F") ? 0 : 100);
        if (num > 1) {
          ok = false;
          break;
        }
        if (num == 1) {
          cur += v[i];
          cnt++;
        }
      }
      if (ok && cnt == T) ans = max(ans, cur);
    }
    h1 = 100 - h1;
    h2 = 100 - h2;
    for (int i = 0; i < (int)(n); i++) c[i] = (c[i] == "T") ? "F" : "T";
  }
  cout << ans << endl;
  return 0;
}
