#include <bits/stdc++.h>
const long long INF = (1LL << 61);
using namespace std;
string hh, aa;
map<int, int> a, h;
int main() {
  int n, time, m;
  char ha, type;
  cin >> hh >> aa >> n;
  for (int i = 0; i < n; i++) {
    cin >> time >> ha >> m >> type;
    if (ha == 'h') {
      if (type == 'y')
        h[m]++;
      else
        h[m] += 2;
      if (h[m] > 1 && h[m] < 5) {
        cout << hh << " " << m << " " << time << endl;
        h[m] = 5;
      }
    } else {
      if (type == 'y')
        a[m]++;
      else
        a[m] += 2;
      if (a[m] > 1 && a[m] < 5) {
        cout << aa << " " << m << " " << time << endl;
        a[m] = 5;
      }
    }
  }
}
