#include <bits/stdc++.h>
using namespace std;
string s[2];
int N;
int card[100][2];
int main() {
  cin >> s[0] >> s[1] >> N;
  for (int i = 0; i < N; i++) {
    int t, num, idx;
    char team, type;
    cin >> t >> team >> num >> type;
    idx = (team == 'h') ? 0 : 1;
    if (card[num][idx] == -1) continue;
    if (type == 'y')
      card[num][idx]++;
    else
      card[num][idx] += 2;
    if (card[num][idx] >= 2) {
      cout << s[idx] << " " << num << " " << t << "\n";
      card[num][idx] = -1;
    }
  }
}
