#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
inline int gcd(int a, int b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? ((a - b) ? gcd(a % b, b) : a) : a;
}
void solve() {
  string home, guest;
  int num, t;
  char c, h;
  cin >> home >> guest;
  int n;
  cin >> n;
  map<int, char> players;
  for (int i = 0; i < n; i++) {
    cin >> t >> h >> num >> c;
    if (h == 'a') num = -num;
    if (players[num] == 'r') continue;
    if ((players[num] != 'y' && players[num] != 'r' && c == 'r') ||
        players[num] == 'y') {
      players[num] = 'r';
      if (num > 0)
        cout << home << " " << num << " " << t << endl;
      else
        cout << guest << " " << -num << " " << t << endl;
    } else
      players[num] = 'y';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
