#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
struct mirror {
  int score;
  double left, right;
};
inline bool operator<(const mirror &x, const mirror &y) {
  return x.left < y.left;
}
int n, res;
double hl, hr;
vector<mirror> mir[2];
void calc(double x, double step, int cur, int k) {
  int tres = 0, cnt[2] = {};
  double dist = x;
  for (int i = 1; i <= k + 1; ++i) {
    if (cnt[cur] >= (int)mir[cur].size()) return;
    while (cnt[cur] + 1 < (int)mir[cur].size() &&
           dist > mir[cur][cnt[cur]].right)
      ++cnt[cur];
    if (dist < mir[cur][cnt[cur]].left || dist > mir[cur][cnt[cur]].right)
      return;
    tres += mir[cur][cnt[cur]].score;
    ++cnt[cur];
    cur ^= 1;
    dist += step;
  }
  res = max(res, tres);
}
void solve(int first, int last, int k) {
  if (first == 1 && last == 1) {
    double x = 1e5 / (hr / hl + (100.0 * k) / hl + 1.0);
    double step = 100.0 * x / hl;
    calc(x, step, 0, k);
  } else if (first == 1 && last == 2) {
    double x = 1e5 / ((100.0 - hr) / hl + (100.0 * k) / hl + 1.0);
    double step = 100.0 * x / hl;
    calc(x, step, 0, k);
  } else if (first == 2 && last == 1) {
    double x = 1e5 / (hr / (100.0 - hl) + (100.0 * k) / (100.0 - hl) + 1.0);
    double step = 100.0 * x / (100.0 - hl);
    calc(x, step, 1, k);
  } else if (first == 2 && last == 2) {
    double x =
        1e5 / ((100.0 - hr) / (100.0 - hl) + (100.0 * k) / (100.0 - hl) + 1.0);
    double step = 100.0 * x / (100.0 - hl);
    calc(x, step, 1, k);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> hl >> hr >> n;
  for (int i = 1; i <= n; ++i) {
    int s, a, b;
    char t;
    cin >> s >> t >> a >> b;
    if (t == 'F')
      mir[0].push_back((mirror){s, (double)a, (double)b});
    else
      mir[1].push_back((mirror){s, (double)a, (double)b});
  }
  for (int i = 0; i < 2; ++i) sort(mir[i].begin(), mir[i].end());
  for (int k = 0; k <= n; ++k) {
    if (k % 2 == 0) {
      solve(1, 1, k);
      solve(2, 2, k);
    } else {
      solve(1, 2, k);
      solve(2, 1, k);
    }
  }
  cout << res;
  return 0;
}
