#include <bits/stdc++.h>
using namespace std;
int met1[1111], met2[1111], x, y;
char h, u;
int main() {
  string s, s1;
  cin >> s >> s1;
  int n;
  cin >> n;
  memset(met1, 0, sizeof(met1));
  memset(met2, 0, sizeof(met2));
  for (int i = 1; i <= n; ++i) {
    cin >> x >> h >> y >> u;
    if (h == 'h') {
      if (met1[y] == 1 || (u == 'r' && met1[y] < 2)) {
        cout << s << ' ' << y << ' ' << x << endl;
        met1[y] = 2;
      } else
        met1[y]++;
    } else {
      if (met2[y] == 1 || (u == 'r' && met2[y] < 2)) {
        cout << s1 << ' ' << y << ' ' << x << endl;
        met2[y] = 2;
      } else
        met2[y]++;
    }
  }
  return 0;
}
