#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 50;
char c[maxn];
int mark[maxn], a[maxn], b[maxn], v[maxn], pos[maxn];
int n, hl, hr, p = 0;
void input() {
  cin >> hl >> hr >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i] >> c[i] >> a[i] >> b[i];
    if (c[i] == 'T') pos[i] = 1;
  }
}
int main() {
  input();
  int q = hr;
  for (int i = 0; i < n + 2; i++) {
    if (i % 2 == 1)
      q += 2 * hr;
    else
      q += 2 * (100 - hr);
    int pp = 0, qq = 0;
    for (int j = 100; j < q; j += 100) {
      int f = 0;
      int t = (j / 100) % 2;
      double d = (double(j - hl) / double(q - hl)) * 100000.0;
      for (int k = 0; k < n; k++)
        if (d >= a[k] && d <= b[k] && t == pos[k] && mark[k] != i + 1) {
          mark[k] = i + 1;
          pp += v[k];
          f = 1;
        }
      if (f == 0) qq = 1;
    }
    if (qq == 0) p = max(p, pp);
  }
  hl = 100 - hl;
  hr = 100 - hr;
  for (int i = 0; i < n; i++) pos[i] = 1 - pos[i];
  q = hr;
  for (int i = 0; i < n + 2; i++) {
    if (i % 2 == 1)
      q += 2 * hr;
    else
      q += 2 * (100 - hr);
    int pp = 0, qq = 0;
    for (int j = 100; j < q; j += 100) {
      int f = 0;
      int t = (j / 100) % 2;
      double d = (double(j - hl) / double(q - hl)) * 100000.0;
      for (int k = 0; k < n; k++)
        if (d >= a[k] && d <= b[k] && t == pos[k] && mark[k] != i + 1) {
          mark[k] = i + 1;
          pp += v[k];
          f = 1;
        }
      if (f == 0) qq = 1;
    }
    if (qq == 0) p = max(p, pp);
  }
  cout << p << endl;
  return 0;
}
