#include <bits/stdc++.h>
using namespace std;
map<pair<int, char>, int> table;
int main() {
  string home, away;
  int n, x, y, i;
  char card, team;
  cin >> home >> away;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> team >> y >> card;
    if (card == 'y') table[make_pair(y, team)]++;
    if (card == 'r') {
      if (table[make_pair(y, team)] < 2)
        table[make_pair(y, team)] = 2;
      else
        continue;
    }
    if (table[make_pair(y, team)] == 2) {
      if (team == 'a')
        cout << away << " ";
      else
        cout << home << " ";
      cout << y << " " << x << endl;
    }
  }
  return 0;
}
