#include <bits/stdc++.h>
using namespace std;
char A[2][55];
int vis[2][105];
int N;
int main() {
  scanf("%s %s", A[0], A[1]);
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    char card[5], k[5];
    int t, pnum;
    scanf("%d %s %d %s", &t, k, &pnum, card);
    if (vis[k[0] == 'a'][pnum] == 1 ||
        (vis[k[0] == 'a'][pnum] == 0 && card[0] == 'r')) {
      printf("%s %d %d\n", A[k[0] == 'a'], pnum, t);
      vis[k[0] == 'a'][pnum] = 2;
    } else if (vis[k[0] == 'a'][pnum] == 0)
      vis[k[0] == 'a'][pnum] = 1;
  }
}
