#include <bits/stdc++.h>
using namespace std;
char arr[21];
char brr[21];
int player1[100];
int player2[100];
int main() {
  char z;
  cin >> arr;
  cin >> brr;
  memset(player1, 0, sizeof(player1));
  memset(player2, 0, sizeof(player2));
  int n, t, d, i, f, m;
  char p, s;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> t >> p >> d >> s;
    if (p == 'a') {
      if (player1[d] == 0 && s == 'y') {
        f = t;
        player1[d]++;
      } else if (s = 'r' && player1[d] < 2) {
        cout << brr << " " << d << " " << t << '\n';
        player1[d] = 5;
      } else if (player1[d] == 1 && s == 'y') {
        if (t < f) t = f;
        cout << brr << " " << d << " " << t << '\n';
        player1[d] = 5;
      }
    } else {
      if (player2[d] == 0 && s == 'y') {
        m = t;
        player2[d]++;
      } else if (s = 'r' && player2[d] < 2) {
        cout << arr << " " << d << " " << t << '\n';
        player2[d] = 5;
      } else if (player2[d] == 1 && s == 'y') {
        if (m > t) t = m;
        cout << arr << " " << d << " " << t << '\n';
        player2[d] = 5;
      }
    }
  }
  return 0;
}
