#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, string> teamName;
  map<string, bool> isOut;
  cin >> teamName['h'] >> teamName['a'];
  map<char, map<int, int>> dict;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int minute, playerNumber;
    char team, card;
    cin >> minute >> team >> playerNumber >> card;
    bool shouldPrint = false;
    if (card == 'r') {
      shouldPrint = true;
    } else {
      dict[team][playerNumber]++;
      if (dict[team][playerNumber] == 2) shouldPrint = true;
    }
    string pp = teamName[team] + to_string(playerNumber);
    if (shouldPrint && !isOut[pp]) {
      isOut[pp] = true;
      cout << teamName[team] << " " << playerNumber << " " << minute << endl;
    }
  }
}
