#include <bits/stdc++.h>
using namespace std;
struct Player {
  int minute, card, result, number;
  string team_name;
  Player() {
    minute = 0;
    card = 0;
    result = 0;
    team_name = "";
    number = 0;
  }
  bool operator<(const Player& PP) const { return result < PP.result; }
};
map<int, Player> mp;
int main() {
  string home, away;
  int n;
  cin >> home >> away >> n;
  vector<Player> VP;
  for (int i = 0; i < n; ++i) {
    int t, m;
    string team, card;
    cin >> t >> team >> m >> card;
    int hash = 100 + m;
    if (team == "a") {
      hash += 100;
    }
    if (mp.find(hash) == mp.end()) {
      if (card == "r") {
        Player P;
        P.result = t;
        P.card = 2;
        P.team_name = team == "a" ? away : home;
        P.number = m;
        mp[hash] = P;
      } else {
        Player P;
        P.card = 1;
        P.team_name = team == "a" ? away : home;
        P.number = m;
        mp[hash] = P;
      }
    } else {
      Player P = mp[hash];
      if (card == "r") {
        if (P.result == 0) P.result = t;
        P.card = 2;
      } else {
        if (P.card == 0) {
          P.card = 1;
        } else {
          P.card = 2;
          if (P.result == 0) P.result = t;
        }
      }
      mp[hash] = P;
    }
  }
  for (map<int, Player>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (it->second.card == 2) VP.push_back(it->second);
  }
  sort(VP.begin(), VP.end());
  for (int i = 0; i < VP.size(); ++i) {
    cout << VP[i].team_name << " " << VP[i].number << " " << VP[i].result
         << "\n";
  }
  return 0;
}
