#include <bits/stdc++.h>
using namespace std;
int team[2][101];
int main() {
  string t[2];
  cin >> t[0] >> t[1];
  int n;
  cin >> n;
  memset(team, 0, sizeof(team));
  int mut, player;
  string ha, ry;
  bool tm;
  while (n--) {
    cin >> mut >> ha >> player >> ry;
    if (ha[0] == 'h')
      tm = 0;
    else
      tm = 1;
    if (ry[0] == 'y')
      team[tm][player]++;
    else
      team[tm][player] += 2;
    if (team[tm][player] >= 2) {
      cout << t[tm] << " " << player << " " << mut << endl;
      team[tm][player] = -200;
    }
  }
  return 0;
}
