#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  swap(ceiling, floor);
  h1  = 100-h1;
  h2 = 100-h2;

  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  /*rep(studsar, 100) {
    int currP = 0;

    int katet = 100-h1;
    double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;
      //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos  << endl;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  printf("%d\n", maxP);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 100) {
    int currP = 0;

    int katet = h1;
    double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  rep(studsar, 100) {
    int currP = 0;

    int katet = h1;
    double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  printf("%d\n", maxP);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 100) {
    int currP = 0;

    int katet = h1;
    double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  rep(studsar, 100) {
    int currP = 0;

    int katet = 100-h1;
    double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      double pos = (katet*100000)/allt;
      //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos  << endl;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  }

  printf("%d\n", maxP);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop:;
  }

  swap(ceiling, floor);
  h1  = 100-h1;
  h2 = 100-h2;

  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop7;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop7;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop7:;
  }
  /*rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  /*rep(studsar, 100) {
    int currP = 0;

    int katet = 100-h1;
    long double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;
      //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos  << endl;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  printf("%d\n", maxP);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*(studsar-1);

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000);

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop:;
  }

  swap(ceiling, floor);
  h1  = 100-h1;
  h2 = 100-h2;

  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*(studsar-1);

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000);

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop7;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop7;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop7:;
  }
  /*rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  /*rep(studsar, 100) {
    int currP = 0;

    int katet = 100-h1;
    long double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;
      //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos  << endl;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  printf("%d\n", maxP);
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <limits>
#include <set>
#include <map>
#include <utility>
#include <cassert>
using namespace std;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<ui> vui;
typedef vector<int> vi;
typedef vector<bool> vbool;
typedef map<int, int> mii;
#define rep(i, n) for(ui i=0; i<n; ++i)
const ui INF = numeric_limits<ui>::max();
/*
  50 50 7
  10 F 1 80000
  20 T 1 80000
  30 T 81000 82000
  40 T 83000 84000
  50 T 85000 86000
  60 T 87000 88000
  70 F 81000 89000
*/

struct mirror {
  int start, stop, points;
  bool hit;
  mirror(int sta, int sto, int poi) : start(sta), stop(sto), points(poi), hit(false) {}
};

int main() {

  vector<mirror > ceiling;
  vector<mirror > floor;

  int h1, h2, m; scanf("%d %d %d", &h1, &h2, &m);
  rep(i, m) {
    int poi, fro, to;
    char what;
    scanf("%d %c %d %d", &poi, &what, &fro, &to);
    if (what == 'F') {
      floor.push_back(mirror(fro, to, poi));
    }
    else ceiling.push_back(mirror(fro, to, poi));
  }

  int maxP = 0;
  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000);

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop:;
  }

  swap(ceiling, floor);
  h1  = 100-h1;
  h2 = 100-h2;

  rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000);

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) goto stop7;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start*allt <= pos && pos <= m.stop*allt) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) goto stop7;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
  stop7:;
  }
  /*rep(studsar, 101) {
    int currP = 0;

    int katet = h1;
    long double allt;

    if (studsar%2)
      allt = h1+h2 + 100*(studsar-1);
    else
      allt = h1+(100-h2) + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = true;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;

      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit floor with " << m.points << " points" << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  /*rep(studsar, 100) {
    int currP = 0;

    int katet = 100-h1;
    long double allt;

    if (studsar%2)
      allt = (100-h1)+(100-h2) + 100*(studsar-1);
    else
      allt = (100-h1)+h2 + 100*studsar;

    for(mirror &m:floor) m.hit=false;
    for(mirror &m:ceiling) m.hit=false;

    bool golv = false;
    bool fail = false;
    rep(studs, studsar) {
      long double pos = (katet*100000)/allt;
      //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos  << endl;
      bool hit = false;
      if (golv) {
        for(mirror & m: floor) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if (m.hit) break;
            hit = true;
            m.hit = true;
            currP += m.points;
            break;
          }
        }
      }
      else {
        for(mirror & m: ceiling) {
          if (m.start <= pos && pos <= m.stop) {
            //cout << "studs = " << studs << " av " << studsar << ", pos = " << pos << " hit ceiling with " << m.points << " points " << endl;
            if(m.hit) break;
            hit = true;
            m.hit=true;
            currP += m.points;
            break;
          }
        }
      }
      if (!hit) {fail = true; break;}
      katet += 100; golv = !golv;
    }
    if(!fail)
      maxP = max(maxP, currP);
      }*/

  printf("%d\n", maxP);
  return 0;
}


// code_forces.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
const double eps = 1e-8;
const int W = 100000;
const int H = 100;
double hl, hr;
int n;
vector<pair<int, pair<double , double> > >  fl, ce;
bool vis[2][102];
bool between(double l, double r, double x)
{
    return x > l - eps && x < r + eps;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> hl >> hr >> n;
    for(int i = 0; i < n; ++i)
    {
        int score;
        double l, r;
        char ch[3];
        cin >> score >> ch >> l >> r;
        if(ch[0] == 'T') ce.push_back(mp(score, mp(l, r)));
        else fl.push_back(mp(score, mp(l, r)));
    }
    int mmax = 0;
    //cout << fl.size() << ' ' << ce.size() << endl;
    for(int i = 0; i < n; ++i)
    {
        double h = i * H + hl;
        if(i & 1) h = h + H - hr;
        else h += hr;
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for(int j = 0; j <= i; ++j)
        {
            double x = W / h * (hl + j * H);
        //  cout << i << ' ' << x << endl;
            bool flag = false;
            if(!(j & 1)) // floor
            {
                for(int k = 0; k < (int)fl.size(); ++k)
                {
                    if(!vis[0][k]  && between(fl[k].second.first, fl[k].second.second, x))
                    {
                        vis[0][k] = true;
                        flag = true;
                        cnt += fl[k].first;
                        break;
                    }
                }
            }
            else //ceil
            {
                for(int k = 0; k < (int)ce.size(); ++k)
                {
                    if(!vis[1][k]  && between(ce[k].second.first, ce[k].second.second, x))
                    {
                        vis[1][k] = true;
                        cnt += ce[k].first;
                        flag = true;
                        break;
                    }
                }
            }
            if(flag == false)
            {
                cnt = 0;
                break;
            }
        }
        mmax = max(cnt ,mmax);
    }
    hr = H - hr;
    hl = H - hl;
    for(int i = 0; i < n; ++i)
    {
        double h = i * H + hl;
        if(i & 1) h = h + H - hr;
        else h += hr;
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for(int j = 0; j <= i; ++j)
        {
            double x = W / h * (hl + j * H);
            bool flag = false;
            if(j & 1) // floor
            {
                for(int k = 0; k < (int)fl.size(); ++k)
                {
                    if(!vis[0][k]  && between(fl[k].second.first, fl[k].second.second, x))
                    {
                        vis[0][k] = true;
                        flag = true;
                        cnt += fl[k].first;
                        break;
                    }
                }
            }
            else //ceil
            {
                for(int k = 0; k < (int)ce.size(); ++k)
                {
                    if(!vis[1][k]  && between(ce[k].second.first, ce[k].second.second, x))
                    {
                        vis[1][k] = true;
                        cnt += ce[k].first;
                        flag = true;
                        break;
                    }
                }
            }
            if(flag == false)
            {
                cnt = 0;
                break;
            }
        }
        mmax = max(cnt ,mmax);
    }
    cout << mmax << endl;
    return 0;
}


// code_forces.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
const double eps = 1e-8;
const int W = 100000;
const int H = 100;
double hl, hr;
int n;
vector<pair<int, pair<double , double> > >  fl, ce;
bool vis[2][102];
bool between(double l, double r, double x)
{
    return x > l - eps && x < r + eps;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> hl >> hr >> n;
    for(int i = 0; i < n; ++i)
    {
        int score;
        double l, r;
        char ch[3];
        cin >> score >> ch >> l >> r;
        if(ch[0] == 'T') ce.push_back(mp(score, mp(l, r)));
        else fl.push_back(mp(score, mp(l, r)));
    }
    int mmax = 0;
    //cout << fl.size() << ' ' << ce.size() << endl;
    for(int i = 0; i < n; ++i)
    {
        double h = i * H + hl;
        if(i & 1) h = h + H - hr;
        else h += hr;
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for(int j = 0; j <= i; ++j)
        {
            double x = W / h * (hl + j * H);
        //  cout << i << ' ' << x << endl;
            bool flag = false;
            if(!(j & 1)) // floor
            {
                for(int k = 0; k < (int)fl.size(); ++k)
                {
                    if(!vis[0][k]  && between(fl[k].second.first, fl[k].second.second, x))
                    {
                        vis[0][k] = true;
                        flag = true;
                        cnt += fl[k].first;
                        break;
                    }
                }
            }
            else //ceil
            {
                for(int k = 0; k < (int)ce.size(); ++k)
                {
                    if(!vis[1][k]  && between(ce[k].second.first, ce[k].second.second, x))
                    {
                        vis[1][k] = true;
                        cnt += ce[k].first;
                        flag = true;
                        break;
                    }
                }
            }
            if(flag == false)
            {
                cnt = 0;
                break;
            }
        }
        mmax = max(cnt ,mmax);
    }
    hr = H - hr;
    hl = H - hl;
    for(int i = 0; i < n; ++i)
    {
        double h = i * H + hl;
        if(i & 1) h = h + H - hr;
        else h += hr;
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for(int j = 0; j <= i; ++j)
        {
            double x = W / h * (hl + j * H);
            bool flag = false;
            if(j & 1) // floor
            {
                for(int k = 0; k < (int)fl.size(); ++k)
                {
                    if(!vis[0][k]  && between(fl[k].second.first, fl[k].second.second, x))
                    {
                        vis[0][k] = true;
                        flag = true;
                        cnt += fl[k].first;
                        break;
                    }
                }
            }
            else //ceil
            {
                for(int k = 0; k < (int)ce.size(); ++k)
                {
                    if(!vis[1][k]  && between(ce[k].second.first, ce[k].second.second, x))
                    {
                        vis[1][k] = true;
                        cnt += ce[k].first;
                        flag = true;
                        break;
                    }
                }
            }
            if(flag == false)
            {
                cnt = 0;
                break;
            }
        }
        mmax = max(cnt ,mmax);
    }
    cout << mmax << endl;
    return 0;
}


#include <iostream>
#include <tuple>
#include <algorithm>
#include <cstring>
using namespace std;
typedef tuple<int, int, int, int> mirror;
int main() {
    int W = 100000, H = 100;
    double hl, hr; int n; cin >> hl >> hr >> n;
    mirror m[n];
    for (int i=0; i < n; i++) {
        int v, a, b; char c; cin >> v >> c >> a >> b;
        m[i] = make_tuple(a, b, (c == 'T') * H, v);
    }
    sort(m, m+n);
    int best = 0;
    for (int flip=0; flip < 2; flip++) {
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            if (y == 0) continue;
            double s = (y - hl) / b, t = (y - hl) / a;
            t = min(t, (y+2*H-hl) / b);

            double minbounce = (s*W + hl - hr) / H, maxbounce = (t*W + hl - hr) / H;
            //cout << "Trying mirror " << a << " " << b << " " << v << ": " << s << " " << t << " " << minbounce << " " << maxbounce << endl;
            for (int j = max(1, (int)minbounce); j <= maxbounce + 1; j++) {
                //cout << j << endl;
                double z = (hr - hl + int(j/2)*2*H + ((j&1) ? 2*(H-hr) : 0)) / W, x = (H-hl) / z;
                if (z < s || z > t) continue;
                bool used[n]; memset(used, 0, sizeof used); used[i] = true;
                int score = get<3>(m[i]);
                bool top = true;
                while(true) {
                  x += H / z; top = !top;
                  if (x >= W) break;

                  mirror* it = upper_bound(m, m+n, make_tuple(int(x)+1, 0, 0, 0));
                  if (it-m == n) it--;
                  bool found = false;
                  do {
                    if (get<0>(*it) > x || get<1>(*it) < x || top != (get<2>(*it) != 0) || used[it-m]) continue;
                    //cout << "it: " << it-m << endl;
                    //cout << x << " " << get<0>(*it) << " " << get<1>(*it) << " " << get<2>(*it) << endl;
                    found = true;
                    used[it-m] = true;
                    score += get<3>(*it);
                    break;
                  } while(it-- != m);
                  if (!found) {
                      score = 0;
                      break;
                  }
                }
                best = max(best, score);
            }
        }
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            m[i] = make_tuple(a, b, H-y, v);
        }
        sort(m, m+n);
        hl = H-hl;
        hr = H-hr;
    }
    cout << best << endl;
    return 0;
}


#include <iostream>
#include <tuple>
#include <algorithm>
#include <cstring>
using namespace std;
typedef tuple<int, int, int, int> mirror;
int main() {
    int W = 100000, H = 100;
    double hl, hr; int n; cin >> hl >> hr >> n;
    mirror m[n];
    for (int i=0; i < n; i++) {
        int v, a, b; char c; cin >> v >> c >> a >> b;
        m[i] = make_tuple(a, b, (c == 'T') * H, v);
    }
    sort(m, m+n);
    int best = 0;
    for (int flip=0; flip < 2; flip++) {
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            if (y == 0) continue;
            double s = (y - hl) / b, t = (y - hl) / a;
            t = min(t, (y+2*H-hl) / b);
            double minbounce = (s*W + hl - hr) / H, maxbounce = (t*W + hl - hr) / H;
            for (int j = max(1, (int)minbounce - 2); j <= maxbounce + 1; j++) {
                double z = (hr - hl + int(j/2)*2*H + (j&1 ? 2*(H-hr) : 0)) / W, x = (H-hl) / z;
                if (z < s || z > t) continue;
                bool used[n]; memset(used, 0, sizeof used); used[i] = true;
                int score = get<3>(m[i]);
                bool top = true;
                while(true) {
                  x += H / z; top = !top;
                  if (x >= W) break;

                  mirror* it = upper_bound(m, m+n, make_tuple(int(x), W+1, 0, 0));
                  if (it != m) it--;
                  if (it != m && top != (get<2>(*it) != 0)) it--;
                  if (get<0>(*it) > x || get<1>(*it) < x || top != (get<2>(*it) != 0) || used[it-m]) {
                      score = 0;
                      break;
                  }
                  used[it-m] = true;
                  score += get<3>(*it);
                }
                best = max(best, score);
            }
        }
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            m[i] = make_tuple(a, b, H-y, v);
        }
        sort(m, m+n);
        hl = H-hl;
        hr = H-hr;
    }
    cout << best << endl;
    return 0;
}


#include <iostream>
#include <tuple>
#include <algorithm>
#include <cstring>
using namespace std;
typedef tuple<int, int, int, int> mirror;
int main() {
    int W = 100000, H = 100;
    double hl, hr; int n; cin >> hl >> hr >> n;
    mirror m[n];
    for (int i=0; i < n; i++) {
        int v, a, b; char c; cin >> v >> c >> a >> b;
        m[i] = make_tuple(a, b, (c == 'T') * H, v);
    }
    sort(m, m+n);
    int best = 0;
    for (int flip=0; flip < 2; flip++) {
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            if (y == 0) continue;
            double s = (y - hl) / b, t = (y - hl) / a;
            t = min(t, (y+2*H-hl) / b);
            double minbounce = (s*W + hl - hr) / H, maxbounce = (t*W + hl - hr) / H;
            //cout << "Trying mirror " << a << " " << b << " " << v << ": " << s << " " << t << " " << minbounce << " " << maxbounce << endl;
            for (int j = max(1, (int)minbounce - 2); j <= maxbounce + 2; j++) {
                //cout << j << endl;
                double z = (hr - hl + int(j/2)*2*H + ((j&1) ? 2*(H-hr) : 0)) / W, x = (H-hl) / z;
                if (z < s || z > t) continue;
                bool used[n]; memset(used, 0, sizeof used); used[i] = true;
                int score = get<3>(m[i]);
                bool top = true;
                while(true) {
                  x += H / z; top = !top;
                  if (x >= W) break;

                  mirror* it = upper_bound(m, m+n, make_tuple(int(x)+2, 0, 0, 0));
                  if (it-m == n) it--;
                  bool found = false;
                  for (; it != m; it--) {
                    if (get<0>(*it) > x || get<1>(*it) < x || top != (get<2>(*it) != 0)) continue;
                    if (used[it-m]) break;
                    found = true;
                    used[it-m] = true;
                    score += get<3>(*it);
                    //cout << "it: " << it-m << endl;
                    //cout << x << " " << get<0>(*it) << " " << get<1>(*it) << " " << get<2>(*it) << endl;
                    break;
                  }
                  if (!found) {
                      score = 0;
                      break;
                  }
                }
                best = max(best, score);
            }
        }
        for (int i=0; i < n; i++) {
            int a, b, y, v; std::tie(a, b, y, v) = m[i];
            m[i] = make_tuple(a, b, H-y, v);
        }
        sort(m, m+n);
        hl = H-hl;
        hr = H-hr;
    }
    cout << best << endl;
    return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
using namespace rel_ops;

typedef pair<int,int> PII;
typedef long long LL;
const int INF = 1000000007;

typedef double NUM;
const NUM EPS = 1e-10, MAGIC = 2.71828e18;

inline NUM sqr(NUM a){return a*a;}
inline NUM cmp(NUM a, NUM b){
    return fabs(a-b)>=EPS+fabs(a)*EPS?a-b:0;
}

struct VEC{NUM x,y;} NOVEC = {MAGIC,MAGIC};
struct RAY{VEC u,v;} NORAY = {NOVEC,NOVEC};
struct CIR{VEC u; NUM r;} NOCIR = {NOVEC,MAGIC};

inline NUM sqr(const VEC& a){return sqr(a.x)+sqr(a.y);}
inline double abs(const VEC& a){return sqrt(sqr(a));}
inline NUM cmp(const VEC& a, const VEC& b){
    NUM at=cmp(a.x,b.x);
    return !at?cmp(a.y,b.y):at;
}

inline VEC operator +(const VEC& a, const VEC& b)
    {return (VEC){a.x+b.x,a.y+b.y};}
inline VEC operator -(const VEC& a, const VEC& b)
    {return (VEC){a.x-b.x,a.y-b.y};}
inline NUM operator *(const VEC& a, const VEC& b)
    {return a.x*b.y-a.y*b.x;}
inline NUM operator %(const VEC& a, const VEC& b)
    {return a.x*b.x+a.y*b.y;}
inline VEC operator -(const VEC& a){return (VEC){-a.x,-a.y};}
inline VEC operator ~(const VEC& a){return (VEC){-a.y,+a.x};}
inline VEC operator *(NUM u, const VEC& a){return (VEC){u*a.x,u*a.y};}
inline VEC operator *(const VEC& a, NUM u){return (VEC){a.x*u,a.y*u};}
inline VEC operator /(const VEC& a, NUM u){return (VEC){a.x/u,a.y/u};}
inline VEC operator /(const VEC& a, const VEC& b){return a%b/sqr(b)*b;}
inline bool operator ==(const VEC& a, const VEC& b){return !cmp(a,b);}
inline bool operator <(const VEC& a, const VEC& b){return cmp(a,b)<0;}

NUM cmp_side(const VEC& a, const VEC& b){return cmp(a.x*b.y,+a.y*b.x);}
NUM cmp_axis(const VEC& a, const VEC& b){return cmp(a.x*b.x,-a.y*b.y);}

VEC resize(const VEC& a, NUM u){return u/abs(a)*a;}
VEC rotate(const VEC& a, NUM u)
    {return (VEC){cos(u)*a.x-sin(u)*a.y,sin(u)*a.x+cos(u)*a.y};}

VEC intersect(const RAY& a, const RAY& b){
    VEC s=a.u-a.v,t=b.u-b.v;
    NUM at=cmp_side(s,t);
    if(!at) return NOVEC;
    return a.u+(b.u-a.u)*t/at*s;
}

int relation(const VEC& p, const RAY& l){
    if(cmp_side(p-l.u,p-l.v)) return 0;
    return cmp_axis(p-l.u,p-l.v)>0?1:2;
}

char s[105];
int pt[105],a[105],b[105];

int main(){
    int st,ed,at,n,ans=0;
    scanf("%d%d%d",&st,&ed,&n);
    set<pair<NUM,int>> up,dn;
    for(int i=0;i<n;i++){
        scanf("%d%s%d%d",pt+i,s+i,a+i,b+i);
        if(s[i]=='T') up.insert({b[i],i});
        if(s[i]=='F') dn.insert({b[i],i});
    }
    for(int t,e=1;e<220;e++){
        at=(e%2?-ed:ed)-e/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=0;t<e;t++){
            RAY u={{0,-100.*t},{100000,-100.*t}};
            VEC p=intersect(l,u);
            //printf("hit %.2f %.2f\n",p.x,p.y);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao1;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==dn.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao1:;
    }
    //printf("ans = %d\n",ans);
    for(int t,e=1;e<220;e++){
        at=(e%2?-ed:ed)+(e+1)/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=1;t<=e;t++){
            RAY u={{0,+100.*t},{100000,+100.*t}};
            VEC p=intersect(l,u);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao2;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==dn.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao2:;
    }
    printf("%d\n",ans);
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
using namespace rel_ops;

typedef pair<int,int> PII;
typedef long long LL;
const int INF = 1000000007;

typedef double NUM;
const NUM EPS = 1e-10, MAGIC = 2.71828e18;

inline NUM sqr(NUM a){return a*a;}
inline NUM cmp(NUM a, NUM b){
    return fabs(a-b)>=EPS+fabs(a)*EPS?a-b:0;
}

struct VEC{NUM x,y;} NOVEC = {MAGIC,MAGIC};
struct RAY{VEC u,v;} NORAY = {NOVEC,NOVEC};
struct CIR{VEC u; NUM r;} NOCIR = {NOVEC,MAGIC};

inline NUM sqr(const VEC& a){return sqr(a.x)+sqr(a.y);}
inline double abs(const VEC& a){return sqrt(sqr(a));}
inline NUM cmp(const VEC& a, const VEC& b){
    NUM at=cmp(a.x,b.x);
    return !at?cmp(a.y,b.y):at;
}

inline VEC operator +(const VEC& a, const VEC& b)
    {return (VEC){a.x+b.x,a.y+b.y};}
inline VEC operator -(const VEC& a, const VEC& b)
    {return (VEC){a.x-b.x,a.y-b.y};}
inline NUM operator *(const VEC& a, const VEC& b)
    {return a.x*b.y-a.y*b.x;}
inline NUM operator %(const VEC& a, const VEC& b)
    {return a.x*b.x+a.y*b.y;}
inline VEC operator -(const VEC& a){return (VEC){-a.x,-a.y};}
inline VEC operator ~(const VEC& a){return (VEC){-a.y,+a.x};}
inline VEC operator *(NUM u, const VEC& a){return (VEC){u*a.x,u*a.y};}
inline VEC operator *(const VEC& a, NUM u){return (VEC){a.x*u,a.y*u};}
inline VEC operator /(const VEC& a, NUM u){return (VEC){a.x/u,a.y/u};}
inline VEC operator /(const VEC& a, const VEC& b){return a%b/sqr(b)*b;}
inline bool operator ==(const VEC& a, const VEC& b){return !cmp(a,b);}
inline bool operator <(const VEC& a, const VEC& b){return cmp(a,b)<0;}

NUM cmp_side(const VEC& a, const VEC& b){return cmp(a.x*b.y,+a.y*b.x);}
NUM cmp_axis(const VEC& a, const VEC& b){return cmp(a.x*b.x,-a.y*b.y);}

VEC resize(const VEC& a, NUM u){return u/abs(a)*a;}
VEC rotate(const VEC& a, NUM u)
    {return (VEC){cos(u)*a.x-sin(u)*a.y,sin(u)*a.x+cos(u)*a.y};}

VEC intersect(const RAY& a, const RAY& b){
    VEC s=a.u-a.v,t=b.u-b.v;
    NUM at=cmp_side(s,t);
    if(!at) return NOVEC;
    return a.u+(b.u-a.u)*t/at*s;
}

int relation(const VEC& p, const RAY& l){
    if(cmp_side(p-l.u,p-l.v)) return 0;
    return cmp_axis(p-l.u,p-l.v)>0?1:2;
}

char s[105];
int pt[105],a[105],b[105];

int main(){
    int st,ed,at,n,ans=0;
    scanf("%d%d%d",&st,&ed,&n);
    set<pair<NUM,int>> up,dn;
    for(int i=0;i<n;i++){
        scanf("%d%s%d%d",pt+i,s+i,a+i,b+i);
        if(s[i]=='T') up.insert({b[i],i});
        if(s[i]=='F') dn.insert({b[i],i});
    }
    for(int t,e=1;e<420;e++){
        at=(e%2?-ed:ed)-e/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=0;t<e;t++){
            RAY u={{0,-100.*t},{100000,-100.*t}};
            VEC p=intersect(l,u);
            //printf("hit %.2f %.2f\n",p.x,p.y);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao1;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) goto gao1;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==up.end()) goto gao1;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao1:;
    }
    //printf("ans = %d\n",ans);
    for(int t,e=1;e<420;e++){
        at=(e%2?-ed:ed)+(e+1)/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=1;t<=e;t++){
            RAY u={{0,+100.*t},{100000,+100.*t}};
            VEC p=intersect(l,u);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao2;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) goto gao2;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==up.end()) goto gao2;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao2:;
    }
    printf("%d\n",ans);
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
using namespace rel_ops;

typedef pair<int,int> PII;
typedef long long LL;
const int INF = 1000000007;

typedef double NUM;
const NUM EPS = 1e-10, MAGIC = 2.71828e18;

inline NUM sqr(NUM a){return a*a;}
inline NUM cmp(NUM a, NUM b){
    return fabs(a-b)>=EPS+fabs(a)*EPS?a-b:0;
}

struct VEC{NUM x,y;} NOVEC = {MAGIC,MAGIC};
struct RAY{VEC u,v;} NORAY = {NOVEC,NOVEC};
struct CIR{VEC u; NUM r;} NOCIR = {NOVEC,MAGIC};

inline NUM sqr(const VEC& a){return sqr(a.x)+sqr(a.y);}
inline double abs(const VEC& a){return sqrt(sqr(a));}
inline NUM cmp(const VEC& a, const VEC& b){
    NUM at=cmp(a.x,b.x);
    return !at?cmp(a.y,b.y):at;
}

inline VEC operator +(const VEC& a, const VEC& b)
    {return (VEC){a.x+b.x,a.y+b.y};}
inline VEC operator -(const VEC& a, const VEC& b)
    {return (VEC){a.x-b.x,a.y-b.y};}
inline NUM operator *(const VEC& a, const VEC& b)
    {return a.x*b.y-a.y*b.x;}
inline NUM operator %(const VEC& a, const VEC& b)
    {return a.x*b.x+a.y*b.y;}
inline VEC operator -(const VEC& a){return (VEC){-a.x,-a.y};}
inline VEC operator ~(const VEC& a){return (VEC){-a.y,+a.x};}
inline VEC operator *(NUM u, const VEC& a){return (VEC){u*a.x,u*a.y};}
inline VEC operator *(const VEC& a, NUM u){return (VEC){a.x*u,a.y*u};}
inline VEC operator /(const VEC& a, NUM u){return (VEC){a.x/u,a.y/u};}
inline VEC operator /(const VEC& a, const VEC& b){return a%b/sqr(b)*b;}
inline bool operator ==(const VEC& a, const VEC& b){return !cmp(a,b);}
inline bool operator <(const VEC& a, const VEC& b){return cmp(a,b)<0;}

NUM cmp_side(const VEC& a, const VEC& b){return cmp(a.x*b.y,+a.y*b.x);}
NUM cmp_axis(const VEC& a, const VEC& b){return cmp(a.x*b.x,-a.y*b.y);}

VEC resize(const VEC& a, NUM u){return u/abs(a)*a;}
VEC rotate(const VEC& a, NUM u)
    {return (VEC){cos(u)*a.x-sin(u)*a.y,sin(u)*a.x+cos(u)*a.y};}

VEC intersect(const RAY& a, const RAY& b){
    VEC s=a.u-a.v,t=b.u-b.v;
    NUM at=cmp_side(s,t);
    if(!at) return NOVEC;
    return a.u+(b.u-a.u)*t/at*s;
}

int relation(const VEC& p, const RAY& l){
    if(cmp_side(p-l.u,p-l.v)) return 0;
    return cmp_axis(p-l.u,p-l.v)>0?1:2;
}

char s[105];
int pt[105],a[105],b[105];

int main(){
    int st,ed,at,n,ans=0;
    scanf("%d%d%d",&st,&ed,&n);
    set<pair<NUM,int>> up,dn;
    for(int i=0;i<n;i++){
        scanf("%d%s%d%d",pt+i,s+i,a+i,b+i);
        if(s[i]=='T') up.insert({b[i],i});
        if(s[i]=='F') dn.insert({b[i],i});
    }
    for(int t,e=1;e<20;e++){
        at=(e%2?-ed:ed)-e/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=0;t<e;t++){
            RAY u={{0,-100.*t},{100000,-100.*t}};
            VEC p=intersect(l,u);
            //printf("hit %.2f %.2f\n",p.x,p.y);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao1;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==dn.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao1;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao1:;
    }
    //printf("ans = %d\n",ans);
    for(int t,e=1;e<20;e++){
        at=(e%2?-ed:ed)+(e+1)/2*200;
        //printf("at = %d\n",at);
        RAY l={{0,st*1.},{100000,at*1.}};
        int ret=0,cnt[105]={};
        for(t=1;t<=e;t++){
            RAY u={{0,+100.*t},{100000,+100.*t}};
            VEC p=intersect(l,u);
            if(relation(p,u)!=2 || relation(p,l)!=2) goto gao2;
            if(t%2){ // up
                auto i=up.lower_bound({p.x-EPS,0});
                if(i==up.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }else{   // dn
                auto i=dn.lower_bound({p.x-EPS,0});
                if(i==dn.end()) continue;
                int x=i->second;
                if(a[x]>p.x+EPS || ++cnt[x]>=2) goto gao2;
            }
        }
        for(int i=0;i<n;i++) if(cnt[i]) ret+=pt[i];
        ans=max(ans,ret);
        gao2:;
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, v.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;
const ld EPS = 1e-5;
struct Segment
{
    ld a, b;
    int v;
};
int n;
bool operator<(const Segment& a, const Segment& b)
{
    return a.a < b.a;
}

int collect(const vector<Segment>& s, ld x, ld l)
{
    int ret = 0;
    forv(i, s) {
        ld a = s[i].a;
        ld b = s[i].b;
        if (x + EPS < a) return -1;
        if (x > b + EPS) continue;
        ret += s[i].v;
        x += l;
        if (x < b + EPS) return -1;
    }
    if (x < 100000.0 + EPS) return -1;
    return ret;
}

int subsolve(const vector<Segment>& f, const vector<Segment>& t, ld h1, ld h2)
{
    int ret = 0;
    ld A = 1.0 - (h1 + h2) / 200;
    ld B = (h2 - h1) / 200;
    for (int k = 1; k <= 105; ++k) {
        if (k > A + EPS) {
            ld l = 100000.0 / (k - A);
            ld x = l * h1 / 200;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
        if (k > B + EPS) {
            ld l = 100000.0 / (k - B);
            ld x = l * h1 / 200.0;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
    }
    return ret;
}

void solve()
{
    vector<Segment> f, t;
    ld h1, h2; cin >> h1 >> h2;
    cin >> n;
    forn(i, n) {
        Segment s;
        cin >> s.v;
        char c; cin >> c;
        cin >> s.a >> s.b;
        if (c == 'T') t.pb(s);
        else f.pb(s);
    }
    sort(all(t));
    sort(all(f));
    int ans = subsolve(f, t, h1, h2);
    ans = max(ans, subsolve(t, f, 100 - h1, 100 - h2));
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, v.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;
const ld EPS = 1e-5;
struct Segment
{
    ld a, b;
    int v;
};
int n;
bool operator<(const Segment& a, const Segment& b)
{
    return a.a < b.a;
}

int collect(const vector<Segment>& s, ld x, ld l)
{
    int ret = 0;
    forv(i, s) {
        ld a = s[i].a;
        ld b = s[i].b;
        if (x + EPS < a) return -1;
        if (x > b + EPS) continue;
        ret += s[i].v;
        x += l;
        if (x < b + EPS) return -1;
    }
    return ret;
}

int subsolve(const vector<Segment>& f, const vector<Segment>& t, ld h1, ld h2)
{
    int ret = 0;
    ld A = 1.0 - (h1 + h2) / 200;
    ld B = (h2 - h1) / 200;
    for (int k = 1; k <= 105; ++k) {
        if (k > A + EPS) {
            ld l = 100000.0 / (k - A);
            ld x = l * h1 / 200;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
        if (k > B + EPS) {
            ld l = 100000.0 / (k - B);
            ld x = l * h1 / 200.0;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
    }
    return ret;
}

void solve()
{
    vector<Segment> f, t;
    ld h1, h2; cin >> h1 >> h2;
    cin >> n;
    forn(i, n) {
        Segment s;
        cin >> s.v;
        char c; cin >> c;
        cin >> s.a >> s.b;
        if (c == 'T') t.pb(s);
        else f.pb(s);
    }
    sort(all(t));
    sort(all(f));
    int ans = subsolve(f, t, h1, h2);
    ans = max(ans, subsolve(t, f, 100 - h1, 100 - h2));
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, v.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;
const ld EPS = 1e-8;
struct Segment
{
    ld a, b;
    int v;
};
int n;
bool operator<(const Segment& a, const Segment& b)
{
    return a.a < b.a;
}

int collect(const vector<Segment>& s, ld x, ld l)
{
    int ret = 0;
    forv(i, s) {
        ld a = s[i].a;
        ld b = s[i].b;
        if (x + EPS < a) return -1;
        if (x > b + EPS) continue;
        ret += s[i].v;
        x += l;
        if (x < b + EPS) return -1;
    }
    return ret;
}

int subsolve(const vector<Segment>& f, const vector<Segment>& t, ld h1, ld h2)
{
    int ret = 0;
    ld A = 1.0 - (h1 + h2) / 200;
    ld B = (h2 - h1) / 200;
    for (int k = 1; k <= 105; ++k) {
        if (k > A + EPS) {
            ld l = 100000.0 / (k - A);
            ld x = l * h1 / 200;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
        if (k > B + EPS) {
            ld l = 100000.0 / (k - B);
            ld x = l * h1 / 200.0;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
    }
    return ret;
}

void solve()
{
    vector<Segment> f, t;
    ld h1, h2; cin >> h1 >> h2;
    cin >> n;
    forn(i, n) {
        Segment s;
        cin >> s.v;
        char c; cin >> c;
        cin >> s.a >> s.b;
        if (c == 'T') t.pb(s);
        else f.pb(s);
    }
    sort(all(t));
    sort(all(f));
    int ans = subsolve(f, t, h1, h2);
    ans = max(ans, subsolve(t, f, 100 - h1, 100 - h2));
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <cassert>
#include <numeric>
using namespace std;

#define REQUIRE(cond, message) \
    do { \
        if (!(cond)) { \
            std::cerr << message << std::endl; \
            assert(false); \
        } \
    } while (false)

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define forv(i, v) forn(i, v.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<string> vs;
typedef long double ld;
const ld EPS = 1e-8;
struct Segment
{
    ld a, b;
    int v;
};
int n;
bool operator<(const Segment& a, const Segment& b)
{
    return a.a < b.a;
}

int collect(const vector<Segment>& s, ld x, ld l)
{
    int ret = 0;
    forv(i, s) {
        ld a = s[i].a;
        ld b = s[i].b;
        if (x + EPS < a) return -1;
        if (x > b + EPS) continue;
        ret += s[i].v;
        x += l;
    }
    return ret;
}

int subsolve(const vector<Segment>& f, const vector<Segment>& t, ld h1, ld h2)
{
    int ret = 0;
    ld A = 1.0 - (h1 + h2) / 200;
    ld B = (h2 - h1) / 200;
    for (int k = 1; k <= 105; ++k) {
        if (k > A + EPS) {
            ld l = 100000.0 / (k - A);
            ld x = l * h1 / 200;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
        if (k > B + EPS) {
            ld l = 100000.0 / (k - B);
            ld x = l * h1 / 200.0;
            int a = collect(f, x, l);
            int b = collect(t, x + l / 2, l);
            if (a >= 0 && b >= 0) {
                ret = max(ret, a + b);
            }
        }
    }
    return ret;
}

void solve()
{
    vector<Segment> f, t;
    ld h1, h2; cin >> h1 >> h2;
    cin >> n;
    forn(i, n) {
        Segment s;
        cin >> s.v;
        char c; cin >> c;
        cin >> s.a >> s.b;
        if (c == 'T') t.pb(s);
        else f.pb(s);
    }
    int ans = subsolve(f, t, h1, h2);
    ans = max(ans, subsolve(t, f, 100 - h1, 100 - h2));
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;

int H = 100, W = 100000;
int hl, hr;
vector <pair <pair <int, int>, int> > top, bottom;

int func(int HL, int HR, int a, int b){
    int D = HR - HL;
    int low = HL + (int)(((ll)D * a + 99999) / 100000);
    int high = HL + (int)((ll)D * b / 100000);
    if(low % 200 != 0) low = low - low % 200 + 200;
    if(high % 200 != 0) high -= high % 200;
    if(low > high) return 0;
    return (high - low) / 200 + 1;
}

int func(int HL, int HR, int bound){
    int ans=0,cnt=0,i;

    REP(i,top.size()){
        int a = top[i].first.first, b = top[i].first.second, c = top[i].second;
        int tmp = func(HL+100, HR+100, a, b);
        if(tmp >= 2) return 0;
        if(tmp == 1) ans += c;
        cnt += tmp;
    }

    REP(i,bottom.size()){
        int a = bottom[i].first.first, b = bottom[i].first.second, c = bottom[i].second;
        int tmp = func(HL, HR, a, b);
        if(tmp >= 2) return 0;
        if(tmp == 1) ans += c;
        cnt += tmp;
    }

    if(cnt != bound) return 0;

    return ans;
}

int func(void){
    int ans = 0;
    int i;

    int HL = hl, HR;
    REP(i,100010){
        HR = hr + 2*H * (i+1);
        ans = max(ans, func(HL, HR, 2*i+2));
    }
    REP(i,100010){
        HR = 200 - hr + 2*H * i;
        ans = max(ans, func(HL, HR, 2*i+1));
    }

    return ans;
}

int main(void){
    int N,i;

    cin >> hl >> hr >> N;
    REP(i,N){
        int score, L, R;
        string type;
        cin >> score >> type >> L >> R;
        if(type == "T"){
            top.push_back(make_pair(make_pair(L,R),score));
        } else {
            bottom.push_back(make_pair(make_pair(L,R),score));
        }
    }

    int ans1 = func();
    swap(top, bottom);
    hl = 100 - hl; hr = 100 - hr;
    int ans2 = func();
    cout << max(ans1, ans2) << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define fill(a, b) memset(a, b, sizeof(a))

using namespace std;

#define N 100
#define M 100000
#define eps 1e-9

int i,j,k,m,n,l,hl,hr;
int T[M+10], F[M+10];
int a[N+10];
bool v[N+10];

int gao(int hl, int hr, int *F, int *T){
	int ret=0;
	for (int i=1; i<=n; ++i){
		int tmp=0, cnt=0;
		fill(v, 0);
		rep(j, i){
			int *p= (j%2==0?F:T);
			int y=(hl+j*100)*100000/(100*(i-1)+hl+(i%2?hr:100-hr));
			bool flag=false;
			if (y*(100*(i-1)+hl+(i%2?hr:100-hr))==100000*(hl+j*100)){
				k=p[y-1];
				if (k && !v[k]){
					v[k]=true;
					tmp+=a[k];
					cnt++;
				}
			}
			int k=p[y];
			if ((k && !v[k]) || flag){
				v[k]=true;
				tmp+=a[k];
				cnt++;
			}
		}
		if (cnt==i)
			ret=max(ret, tmp);
	}
	return ret;
}

int main(){
	while (cin>>hl>>hr>>n){
		fill(T, 0), fill(F, 0);
		repf(i, 1, n){
			char s[2];
			int x,y;
			scanf("%d%s%d%d", a+i, s, &x, &y);
			int *p= (s[0]=='T'?T:F);
			repf(j, x, y-1) p[j]=i;
		}
		cout<<max(gao(hl, hr, F, T), gao(100-hl, 100-hr, T, F))<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define repf(i, a, b) for (int i=(a); i<=(b); ++i)
#define repd(i, a, b) for (int i=(a); i>=(b); --i)
#define fill(a, b) memset(a, b, sizeof(a))

using namespace std;

#define N 100
#define M 100000
#define eps 1e-9

int i,j,k,m,n,l,hl,hr;
int T[M+10], F[M+10];
int a[N+10];
bool v[N+10];

int gao(int hl, int hr, int *F, int *T){
    int ret=0;
    for (int i=1; i<=n; ++i){
        int tmp=0;
        fill(v, 0);
        rep(j, i){
            int *p= (j%2==0?F:T);
            int y=(hl+j*100)*100000/(100*(i-1)+hl+(i%2?hr:100-hr));
            bool flag=false;
            if (y*(100*(i-1)+hl+(i%2?hr:100-hr))==100000*(hl+j*100)){
                k=p[y-1];
                if (k && !v[k]){
                    v[k]=true;
                    tmp+=a[k];
                }
            }
            else{
                int k=p[y];
                if ((k && !v[k]) || flag){
                    v[k]=true;
                    tmp+=a[k];
                }
                else{
                    tmp=-1; break;
                }
            }
        }
        ret=max(ret, tmp);
    }
    return ret;
}

int main(){
    while (cin>>hl>>hr>>n){
        fill(T, 0), fill(F, 0);
        repf(i, 1, n){
            char s[2];
            int x,y;
            scanf("%d%s%d%d", a+i, s, &x, &y);
            int *p= (s[0]=='T'?T:F);
            repf(j, x, y-1) p[j]=i;
        }
        cout<<max(gao(hl, hr, F, T), gao(100-hl, 100-hr, T, F))<<endl;
    }
    return 0;
}


// .... .... .... !

#include <iostream>
#include <iomanip>
#include <fstream>

#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>

#include <cstdio>
#include <cstring>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fer(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define rof(i, n, x) for (int i = (int)(n), _x = (int)(x); i-- > _x; )
#define fch(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define sz(x) (int((x).size()))
#define X first
#define Y second
#define A first.first
#define B first.second
#define V second

typedef long long ll;
typedef pair <int, int> pii;

////////////////////////////////////////////////////////////////////////////////

int n, h, h2;
vector <pair <pii, int> > m[2];

pii get (int j, int e)
{
	int xx = (100 * j - h) * (long long)100000 / (e - h);
	int yy = ((100 * j - h) * (long long)100000 - 1) / (e - h) + 1;
	return pii (xx, yy);
}

int main()
{
//	ifstream cin ("mir.in");
//	ofstream cout ("mir.txt");
	ios::sync_with_stdio (false);
//	int ttt;
//for (cin >> ttt; ttt--; ) {
//	m[0].clear(); m[1].clear();

	cin >> h >> h2 >> n;
	rep (i, n)
	{
		int v, a, b;
		char c;
		cin >> v >> c >> a >> b;
		if (c == 'T') m[1].push_back (make_pair (pii (a, b), v));
		else m[0].push_back (make_pair (make_pair (a, b), v));
	}

	sort (m[0].begin(), m[0].end());
	sort (m[1].begin(), m[1].end());

//	cerr << "\n##\n";
//	fch (it, m[0]) cerr << (it->A) << ' ' << (it->B) << ' ' << (it->V) << "\n"; cerr << endl;
//	fch (it, m[1]) cerr << (it->A) << ' ' << (it->B) << ' ' << (it->V) << "\n"; cerr << endl;

	int ans = 0;
	fer (i, 1, 500)
	{
		int sum = 0;
		int e = i * 100 + ((i % 2 == 0) ? h2 : 100 - h2);
		fer (j, 1, i+1)
		{
			pii t = get (j, e);
			auto& v = m[j%2];
			auto p = upper_bound (v.begin(), v.end(), make_pair (pii (t.X, 0), 0));
			if (p == v.begin()) { sum = -1; break; }
			p--;
			if (p->B >= t.Y)
			{
				if (j+2 <= i && p->B >= get(j+2, e).Y) { sum = -1; break; }
				sum += p->V;
			}
			else
				{ sum = -1; break; }
		}
//		if (sum != -1) cerr << " $$$$ " << i << ' ' << e << ' ' << sum << endl;
		ans = max (ans, sum);
	}

	swap (m[0], m[1]); h = 100 - h, h2 = 100 - h2;
	fer (i, 1, 1000)
	{
		int sum = 0;
		int e = i * 100 + ((i % 2 == 0) ? h2 : 100 - h2);
		fer (j, 1, i+1)
		{
			pii t = get (j, e);
			auto& v = m[j%2];
			auto p = upper_bound (v.begin(), v.end(), make_pair (pii (t.X, 0), 0));
			if (p == v.begin()) { sum = -1; break; }
			p--;
//			if (i == 5) cerr << " ^^^^ " << t.X << ' ' << t.Y << ' ' << (p->V) << endl;
			if (p->B >= t.Y)
			{
				if (j+2 <= i && p->B >= get(j+2, e).Y) { sum = -1; break; }
				sum += p->V;
			}
			else
				{ sum = -1; break; }
		}
//		if (sum != -1) cerr << " $$$$ " << i << ' ' << e << ' ' << sum << endl;
		ans = max (ans, sum);
	}

	cout << ans << endl;

//}
	{ int _; cin >> _; }
	return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <stack>
#include <list>
using namespace std;
typedef long long li;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define NAME ""
void solve();

int main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    clock_t start = clock();
#else
#endif

    solve();

#ifdef DEBUG
    cout << "\n\n\n\nTime:" << ((clock() - start) / 1.0 / CLOCKS_PER_SEC);
#endif
}
int d[1000];
int s[1000];
typedef set<pair<pi, int>> setp;
setp t, b;

setp* other(setp* x){
    return (x == &t) ? &b : &t;
}

namespace std{
    template<>
    struct hash<setp::iterator>{
        size_t operator()(setp::iterator t) const {
            return t->first.first * 10000 + t->first.second * 100 + t->second;
        }
    };
}

void solve() {
    int l,r,n;
    cin >> l >> r >>n;

    for(int i = 0 ; i < n ; ++i){
        int v,ll,rr;
        char a;
        cin>>v>>a>>ll>>rr;
        pair<pi, int> z = mp(mp(ll, rr), v);
        if(a == 'T')
            t.insert(z);
        else
            b.insert(z);
    }
    int ans = 0;
    for(int cnt = 1; cnt <=n; ++cnt){
        unordered_set<setp::iterator> v;
        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr - cnt * 100;

        int h = l - realFinish;
        setp* cur = &b;
        int sum = 0;
        bool ok = true;

        for(int i = 0; i < cnt; ++i){

            int curH = l + i * 100;

            double s = curH * 100000/ (double)h;
            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            v.insert(it);
            sum += it->second;
            cur = other(cur);
        }
        if(ok && v.size() == cnt){
            ans = max(ans, sum);
        }
    }

    for(int cnt = 1; cnt <=n; ++cnt){
        unordered_set<setp::iterator> v;
        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr + cnt * 100;

        int h = realFinish - l;
        setp* cur = &t;
        int sum = 0;
        bool ok = true;

        for(int i = 0; i < cnt; ++i){

            int curH = 100 - l + i * 100;

            double s = curH * 100000/ (double)h;
            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            v.insert(it);
            sum += it->second;
            cur = other(cur);
        }
        if(ok && v.size() == cnt){
            ans = max(ans, sum);
        }
    }

    cout << ans;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <stack>
#include <list>
using namespace std;
typedef long long li;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define NAME ""
void solve();

int main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    clock_t start = clock();
#else
#endif

    solve();

#ifdef DEBUG
    cout << "\n\n\n\nTime:" << ((clock() - start) / 1.0 / CLOCKS_PER_SEC);
#endif
}
int d[1000];
int s[1000];
typedef set<pair<pi, int>> setp;
setp t, b;

setp* other(setp* x){
    return (x == &t) ? &b : &t;
}

void solve() {
    int l,r,n;
    cin >> l >> r >>n;

    for(int i = 0 ; i < n ; ++i){
        int v,ll,rr;
        char a;
        cin>>v>>a>>ll>>rr;
        pair<pi, int> z = mp(mp(ll, rr), v);
        if(a == 'T')
            t.insert(z);
        else
            b.insert(z);
    }
    int ans = 0;
    for(int cnt = 1; cnt <=n; ++cnt){
        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr - cnt * 100;

        int h = l - realFinish;
        setp* cur = &b;
        int sum = 0;
        bool ok = true;

        for(int i = 0; i < cnt; ++i){

            int curH = l + i * 100;

            double s = curH * 100000/ (double)h;
            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            sum += it->second;
            cur = other(cur);
        }
        if(ok){
                ans = max(ans, sum);
        }
    }

    for(int cnt = 1; cnt <=n; ++cnt){

        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr + cnt * 100;

        int h = l - realFinish;
        setp* cur = &t;
        int sum = 0;
        bool ok = true;
        for(int i = 0; i < cnt; ++i){

            int curH = i * 100 + 100 - l;

            int s = (curH * 100000/ (double)h);

            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            sum += it->second;
            cur = other(cur);
        }
        if(ok){
                ans = max(ans, sum);
        }
    }

    cout << ans;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <stack>
#include <list>
using namespace std;
typedef long long li;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define NAME ""
void solve();

int main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    clock_t start = clock();
#else
#endif

    solve();

#ifdef DEBUG
    cout << "\n\n\n\nTime:" << ((clock() - start) / 1.0 / CLOCKS_PER_SEC);
#endif
}
int d[1000];
int s[1000];
typedef set<pair<pi, int>> setp;
setp t, b;

setp* other(setp* x){
    return (x == &t) ? &b : &t;
}

void solve() {
    int l,r,n;
    cin >> l >> r >>n;

    for(int i = 0 ; i < n ; ++i){
        int v,ll,rr;
        char a;
        cin>>v>>a>>ll>>rr;
        pair<pi, int> z = mp(mp(ll, rr), v);
        if(a == 'T')
            t.insert(z);
        else
            b.insert(z);
    }
    int ans = 0;
    for(int cnt = 1; cnt <=n; ++cnt){
        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr - cnt * 100;

        int h = l - realFinish;
        setp* cur = &b;
        int sum = 0;
        bool ok = true;

        for(int i = 0; i < cnt; ++i){

            int curH = l + i * 100;

            double s = curH * 100000/ (double)h;
            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            sum += it->second;
            cur = other(cur);
        }
        if(ok){
                ans = max(ans, sum);
        }
    }

    for(int cnt = 1; cnt <=n; ++cnt){

        int pr = r;
        if(cnt % 2 == 1)
            pr = 100 - pr;
        int realFinish = pr + cnt * 100;

        int h = realFinish - l;
        setp* cur = &t;
        int sum = 0;
        bool ok = true;
        for(int i = 0; i < cnt; ++i){

            int curH = i * 100 + 100 - l;

            int s = (curH * 100000/ (double)h);

            setp::iterator it = cur->upper_bound(mp(mp(s, 10000000), 10000000));

            if(it == cur->begin()){
                ok = false;
                break;
            }

            --it;

            if(it->first.second < s){
                ok = false;
                break;
            }
            sum += it->second;
            cur = other(cur);
        }
        if(ok){
                ans = max(ans, sum);
        }
    }

    cout << ans;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define DB(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long LL;

const int MAXN = 109;
const int MAXW = 100000;

int n, hL, hR;

struct Segment
{
  Segment(int a = 0, int b = 0, int pnts = 0): a(a), b(b), pnts(pnts)
  {
  }
  int a, b;
  int pnts;

  bool operator() (const Segment& s1, const Segment& s2)
  {
    return s1.a < s2.a;
  }
};

vector<Segment> side[2];

bool inside(double x, Segment s)
{
  return (s.a <= x && x <= s.b);
}

int main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#ifdef _DEBUG
#endif
  scanf("%d%d%d", &hL, &hR, &n);
  REP(i, n)
  {
    int v, a, b;
    char c;
    scanf("%d %c %d %d", &v, &c, &a, &b);
    if (c == 'F')
      side[0].push_back(Segment(a, b, v));
    else
      side[1].push_back(Segment(a, b, v));
  }
  REP(i, 2)
  {
    sort(side[i].begin(), side[i].end(), Segment());
  }

  int best = 0;
  for (int i = -MAXW; i <= MAXW; ++i)
  //for (int i = -1; i <= -1; ++i)
  {
    if (i == 0)
      continue;
    double x = 0;
    double y = hL;
    double fx = MAXW;
    double fy = 100 * i + hR;
    if (i % 2)
    {
      fy = fy - hR + 100 - hR;
    }
    //cerr << x << " " << y << endl;
    //cerr << fx << " " << fy << endl;

    double dx = fx - x;
    double dy = fy - y;
    dx = (dx / fabs(dy));

    //DB(dx);
    //DB(dy);

    int pnt[2];
    pnt[0] = pnt[1] = 0;
    int curSide = 1;
    int prevSide[2];
    prevSide[0] = prevSide[1] = -1;
    bool bad = false;

    if (i < 0)
    {
      curSide = 0;
      x += dx * hL;
    }
    else
    {
      curSide = 1;
      x += dx * (100 - hL);
    }
    //DB(x);

    int score = 0;

    while (x < fx)
    {
      while (pnt[curSide] < side[curSide].size() && !inside(x, side[curSide][pnt[curSide]]))
      {
        pnt[curSide]++;
      }
      if (pnt[curSide] == side[curSide].size())
      {
        bad = true;
        break;
      }
      else
      {
        if (!inside(x, side[curSide][pnt[curSide]]))
        {
          bad = true;
          break;
        }
        else
        {
          if (pnt[curSide] == prevSide[curSide])
          {
            bad = true;
            break;
          }
          /*DB(side[curSide][pnt[curSide]].a);
          DB(side[curSide][pnt[curSide]].b);
          DB(x);
          DB(side[curSide].size());*/
          score += side[curSide][pnt[curSide]].pnts;
          x += dx * 100;
          prevSide[curSide] = pnt[curSide];
          curSide = 1 - curSide;
        }
      }
    }
    if (!bad)
    {
      best = max(best, score);
    }
  }
  printf("%d\n", best);
  return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int l1,l2,r1,r2,n;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);

		if(l1==l2)printf("%d %d\n",l1,l2+1);
		else printf("%d %d\n",l1,l2);
	}
}
//	   --sss--
//   ---


#include<iostream>
#include<cstdio>
using namespace std;
int l1,l2,r1,r2,n;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int minl=min(l1,l2),maxr=max(r1,r2);
		for(int a=minl,b=maxr;a<=maxr,b>=minl;a++,b--)
		{
			if(l1<=a&&a<=r1&&l2<=b&&b<=r2&&a!=b)
			{
				printf("%d %d\n",a,b);
				break;
			}
		}
	}
    return 0;

} //asfgbrg


#include<iostream>
#include<cstdio>
using namespace std;
int l1,l2,r1,r2,n;
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		if(r1<=l2){printf("%d %d\n",l1,l2);}
		else if(r1>=l2){printf("%d %d\n",l1,r2);}
		else if(r1>=r2&&l1<=l2){printf("%d %d\n",l2,r2);}
		else printf("%d %d\n",l1,r1);
	}
}
//----
//    age


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
for(long long i=1;i<=t;i++)
{
    int l1,r1,l2,r2;
    cin>>l1>>r1>>l2>>r2;
    cout<<l1<<endl;
    if(l1!=l2)
    {
        cout<<l2<<endl;
    }
    else
    {
        cout<<r2<<endl;
    }
}
   return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
for(long long i=1;i<=t;i++)
{
    int l1,r1,l2,r2;
    cin>>l1>>r1>>l2>>r2;
    if(l1+r1 == l2+r2)
    {
        cout<<(l1+r1)/2<<" "<<((l2+r2)/2)+1<<endl;
        return 0;
    }

        cout<<(l1+r1)/2<<" "<<(l2+r2)/2<<endl;

}
   return 0;
}


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
for(long long i=1;i<=t;i++)
{
    int l1,r1,l2,r2;
    cin>>l1>>r1>>l2>>r2;
    if(l1+r1 == l2+r2)
    {
        cout<<(l1+r1)/2<<" "<<((l2+r2)/2)+1<<endl;
        continue;
    }

        cout<<(l1+r1)/2<<" "<<(l2+r2)/2<<endl;

}
   return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int l1,r1,l2,r2;
		cin >> l1 >> r1 >> l2 >> r2;
		if( l1 > l2 ) {
			swap( l1, l2 );
			swap( r1, r2 );
		}
		cout << min( l1, r1 ) <<  " " << max( l2, r2 ) << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int l1,r1,l2,r2;
		cin >> l1 >> r1 >> l2 >> r2;
		cout << l1 <<  " " << r2 << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int l1,r1,l2,r2;
		cin >> l1 >> r1 >> l2 >> r2;
		cout << min( l1, r1 ) <<  " " << max( l2, r2 ) << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int a[ 4 ];
		cin >> a[ 0 ] >> a[ 1 ] >> a[ 2 ] >> a [ 3 ];
		sort( a, a + 4 );
		cout << a[ 1 ] << " " << ( ( a[ 2 ] == a[ 1 ] ) ? a[ 3 ] : a[ 2 ] ) << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int a[ 4 ];
		cin >> a[ 0 ] >> a[ 1 ] >> a[ 2 ] >> a [ 3 ];
		sort( a, a + 4 );
		cout << a[ 1 ] << " " << ( a[ 2 ] == a[ 1 ] ) ? a[ 3 ] : a[ 2 ] << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int a[ 4 ];
		cin >> a[ 0 ] >> a[ 1 ] >> a[ 2 ] >> a [ 3 ];
		sort( a, a + 4 );
		cout << a[ 1 ] << " " << a[ 2 ] << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		int a[ 4 ];
		cin >> a[ 0 ] >> a[ 1 ] >> a[ 2 ] >> a [ 3 ];
		cout << a[ 0 ] << " ";

		for( int i = a[ 2 ]; i <= a[ 3 ]; i++ ) {
			if( i != a[ 0 ] ) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        cout<<min(r1,r2)<<" "<<min(l1,l2)<<endl;
    }

}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        if(min(l1,r1)!=max(l2,r2))
            cout<<min(l1,r1)<<" "<<max(l2,r2)<<" \n";
        else if(max(l1,r1)!=min(l2,r2)){
            cout<<max(l1,r1)<<" "<<min(l2,r2)<<" \n";
        }
    }
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        cout<<max(r1,r2)<<" "<<max(l1,l2)<<endl;
    }

}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        cout<<min(l1,r1)<<" "<<max(l2,r2);
    }

}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        int a,b;
        if(l1!=l2){
            cout<<l1<<" "<<l2;
        }
        else{
            if(r2>l2){
                cout<<l1<<" "<<l2+1;
            }
            else if(r1>l1){
                cout<<l1+1<<" "<<l2;
            }
        }
    }

}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        cout<<max(r1,r2)<<" "<<min(l1,l2)<<endl;
    }

}


//in the name of god
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    int r1,l1,r2,l2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>r1>>l1>>r2>>l2;
        cout<<min(l1,r1)<<" "<<max(l2,r2)<<" ";
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define si(n) scanf("%d",&n)
#define dsi(n) int n; scanf("%d",&n)
#define si2(a,b) scanf("%d%d",&a,&b)
#define dsi2(a,b) int a,b; scanf("%d%d",&a,&b)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define lldout(n) printf("%lld\n",n)
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 2234506;
//int arr[MAX_N];

int main(){
    int TC;
    si(TC);
    while(TC--){
        dsi2(l1,r1);
        dsi2(l2,r2);
        if(l1>=r2){
            swap(l1,l2);
            swap(r1,r2);
        }
        printf("%d %d\n",l1,r2);
    }
	return 0;
}