#include <bits/stdc++.h>
using namespace std;
long long int ara[200][100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string home, away;
  cin >> home >> away;
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; ++i) {
    long long int time, playern;
    char ha, card;
    cin >> time >> ha >> playern >> card;
    if ((card == 'r' && ara[(long long int)ha][playern] < 2) ||
        ara[(long long int)ha][playern] == 1) {
      ha == 'h' ? cout << home << " " << playern << " " << time << '\n'
                : cout << away << " " << playern << " " << time << '\n';
      ara[(long long int)ha][playern] = 2;
    }
    ++ara[(long long int)ha][playern];
  }
}
