#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 123;
const int MINN = 1e3 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
int a[100], b[100];
int main() {
  string x, y;
  cin >> x >> y;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t, num;
    char ie, card;
    cin >> t >> ie >> num >> card;
    if (ie == 'a') {
      a[num]++;
      if (a[num] > 2) {
        continue;
      }
      if (card == 'r') {
        a[num] += 2;
        cout << y << ' ' << num << ' ' << t << endl;
        continue;
      }
      if (a[num] == 2) {
        cout << y << ' ' << num << ' ' << t << endl;
        continue;
      }
    } else if (ie == 'h') {
      b[num]++;
      if (b[num] > 2) {
        continue;
      }
      if (card == 'r') {
        b[num] += 2;
        cout << x << ' ' << num << ' ' << t << endl;
        continue;
      }
      if (b[num] == 2) {
        cout << x << ' ' << num << ' ' << t << endl;
        continue;
      }
    }
  }
  return 0;
}
