#include <bits/stdc++.h>
using namespace std;
string team1, team2;
string aorh, yorr;
int v1[100];
bool used1[100];
int v2[100];
bool used2[100];
int main() {
  int n, time, player;
  cin >> team1 >> team2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> time >> aorh >> player >> yorr;
    if (aorh == "a") {
      v2[player]++;
      if (yorr == "r") v2[player]++;
      if ((v2[player] > 1) && (used2[player] == false)) {
        cout << team2 << " " << player << " " << time << endl;
        used2[player] = true;
      }
    } else {
      v1[player]++;
      if (yorr == "r") v1[player]++;
      if ((v1[player] > 1) && (used1[player] == false)) {
        cout << team1 << " " << player << " " << time << endl;
        used1[player] = true;
      }
    }
  }
  return 0;
}
