#include <bits/stdc++.h>
using namespace std;
string s[3];
int a[200][200];
int n;
int main() {
  char card, team;
  int tm, player;
  cin >> s[0] >> s[1];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tm >> team >> player >> card;
    if (card == 'y')
      a[team][player]++;
    else
      a[team][player] += 2;
    if (a[team][player] >= 2) {
      if (team == 'a')
        cout << s[1];
      else
        cout << s[0];
      cout << " " << player << " " << tm << endl;
      a[team][player] -= 9000;
    }
  }
}
