#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (b) {
    long long t = b;
    b = a % b;
    a = t;
  }
  return a;
}
struct Frac {
  long long p, q;
  Frac(long long _p, long long _q) {
    long long g = gcd(_p, _q);
    p = _p / g;
    q = _q / g;
  }
  Frac operator*(int x) const { return Frac(p * x, q); }
  Frac operator/(int x) const { return Frac(p, q * x); }
  Frac operator+(int x) const { return Frac(p + x * q, q); }
  Frac operator+(const Frac& other) const {
    return Frac(p * other.q + other.p * q, q * other.q);
  }
  bool operator<=(const Frac& other) const {
    return p * other.q <= other.p * q;
  }
};
Frac getX(int hl, int hr, int l) {
  return Frac(100000 * 100, 100 * (l - 1) + hr + hl);
}
int hl, hr, n, v[100], a[100], b[100];
bool top[100];
pair<int, int> getScore(bool toTop, Frac x) {
  for (int i = 0; i < n; ++i) {
    if (top[i] == toTop) {
      Frac fa(a[i], 1), fb(b[i], 1);
      if (fa <= x && x <= fb) return make_pair(v[i], i);
    }
  }
  return make_pair(0, 0);
}
int solve(int l, bool toTop) {
  int mhl = (toTop ? 100 - hl : hl);
  int mhr = (toTop ? 100 - hr : hr);
  if (l % 2 == 0) mhr = 100 - mhr;
  Frac x = getX(mhl, mhr, l);
  Frac xl = x * mhl / 100;
  Frac xr = x * mhr / 100;
  int ret = 0;
  bool scored[n];
  fill(scored, scored + n, false);
  for (int i = 0; i < l; ++i) {
    pair<int, int> score = getScore(toTop, xl);
    if (score.first && !scored[score.second]) {
      ret += score.first;
      scored[score.second] = true;
    } else
      return 0;
    xl = xl + x;
    toTop = !toTop;
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &hl, &hr, &n);
  for (int i = 0; i < n; ++i) {
    char c;
    scanf("%d %c %d %d", &v[i], &c, &a[i], &b[i]);
    top[i] = (c == 'T');
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, max(solve(i + 1, true), solve(i + 1, false)));
  }
  printf("%d\n", ans);
  return 0;
}
