#include <bits/stdc++.h>
using namespace std;
void input() { freopen("in.txt", "r", stdin); }
int main() {
  char t1[50];
  char t2[50];
  cin >> t1 >> t2;
  int t;
  cin >> t;
  int g[2][200];
  memset(g, 0, sizeof g);
  while (t--) {
    int time, player;
    char country, card;
    cin >> time >> country >> player >> card;
    if (country == 'a') {
      if (card == 'r') {
        g[1][player] += 2;
      } else {
        g[1][player] += 1;
      }
    } else {
      if (card == 'r') {
        g[0][player] += 2;
      } else {
        g[0][player] += 1;
      }
    }
    if (g[0][player] >= 2) {
      cout << t1 << ' ' << player << ' ' << time << endl;
      g[0][player] = -3000;
    } else if (g[1][player] >= 2) {
      cout << t2 << ' ' << player << ' ' << time << endl;
      g[1][player] = -3000;
    }
  }
}
