#include <bits/stdc++.h>
using namespace std;
char t[2][25];
int ha[2][100] = {0};
bool done[2][100] = {0};
int temp, minn, n;
char team[2], card[2];
int main() {
  cin >> t[0] >> t[1];
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &minn);
    cin >> team;
    scanf("%d", &temp);
    cin >> card;
    team[0] = (team[0] == 'h' ? (0) : (1));
    if (card[0] == 'r' && !done[team[0]][temp]) {
      printf("%s %d %d\n", t[team[0]], temp, minn);
      done[team[0]][temp] = 1;
    } else {
      ha[team[0]][temp]++;
      if (ha[team[0]][temp] == 2 && !done[team[0]][temp]) {
        printf("%s %d %d\n", t[team[0]], temp, minn);
        done[team[0]][temp] = 1;
      }
    }
  }
  return 0;
}
