#include <bits/stdc++.h>
using namespace std;
int main() {
  string team1, team2;
  while (cin >> team1 >> team2) {
    int n;
    cin >> n;
    int moment1[100], moment2[100];
    memset(moment1, -1, sizeof(moment1));
    memset(moment2, -1, sizeof(moment2));
    int time, number;
    string team, card;
    for (int i = 0; i < n; i++) {
      cin >> time >> team >> number >> card;
      if (team == "h") {
        if (card == "y") {
          if (moment1[number] == -1)
            moment1[number] = 0;
          else
            moment1[number] = moment1[number] > 0 ? moment1[number] : time;
        } else {
          moment1[number] = moment1[number] > 0 ? moment1[number] : time;
        }
      } else {
        if (card == "y") {
          if (moment2[number] == -1)
            moment2[number] = 0;
          else
            moment2[number] = moment2[number] > 0 ? moment2[number] : time;
        } else {
          moment2[number] = moment2[number] > 0 ? moment2[number] : time;
        }
      }
    }
    vector<pair<int, pair<int, string> > > data;
    for (int i = 0; i < 100; i++) {
      if (moment1[i] > 0) {
        data.push_back(make_pair(moment1[i], make_pair(i, team1)));
      }
      if (moment2[i] > 0) {
        data.push_back(make_pair(moment2[i], make_pair(i, team2)));
      }
    }
    sort(data.begin(), data.end());
    for (int i = 0; i < data.size(); i++) {
      cout << data[i].second.second << " " << data[i].second.first << " "
           << data[i].first << endl;
    }
  }
  return 0;
}
