#include <bits/stdc++.h>
using namespace std;
int home[100], away[100];
int main() {
  string s1, s2;
  int n;
  cin >> s1 >> s2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    char team;
    int num;
    char card;
    cin >> t >> team >> num >> card;
    int* ptr;
    if (team == 'a')
      ptr = away;
    else
      ptr = home;
    if (card == 'y') {
      if (ptr[num] == 1) {
        string ts = (team == 'h') ? s1 : s2;
        cout << ts << " ";
        cout << num << ' ' << t << '\n';
        ptr[num] = -1;
      }
      if (ptr[num] == 0) ptr[num] = 1;
    } else if (card == 'r') {
      if (ptr[num] != -1) {
        ptr[num] = -1;
        string ts = (team == 'h') ? s1 : s2;
        cout << ts << " ";
        cout << num << ' ' << t << '\n';
      }
    }
  }
  return 0;
}
