#include <bits/stdc++.h>
using namespace std;
string a, b;
int n, t, k, ka[100], kb[100];
char c, team;
bool useda[100], usedb[100];
int main() {
  cin >> a >> b;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t >> team >> k >> c;
    if (c == 'r') {
      if (team == 'h' && !useda[k]) {
        cout << a << ' ' << k << ' ' << t << endl;
        useda[k] = true;
      } else if (team == 'a' && !usedb[k]) {
        usedb[k] = true;
        cout << b << ' ' << k << ' ' << t << endl;
      }
    } else {
      if (team == 'h') {
        ka[k]++;
        if (ka[k] == 2 && !useda[k]) {
          cout << a << ' ' << k << ' ' << t << endl;
          useda[k] = true;
        }
      } else if (team == 'a') {
        kb[k]++;
        if (kb[k] == 2 && !usedb[k]) {
          usedb[k] = true;
          cout << b << ' ' << k << ' ' << t << endl;
        }
      }
    }
  }
}
