#include <bits/stdc++.h>
using namespace std;
int main() {
  string name[2];
  cin >> name[0];
  cin >> name[1];
  set<int> yo[2];
  set<int> red[2];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int time;
    char k;
    int t;
    char c;
    cin >> time >> k >> t >> c;
    int num = 0;
    if (k == 'a') num = 1;
    if (red[num].count(t) != 0) continue;
    if (c == 'r') {
      red[num].insert(t);
      cout << name[num] << " " << t << " " << time << endl;
      continue;
    }
    if (yo[num].count(t) != 0) {
      red[num].insert(t);
      cout << name[num] << " " << t << " " << time << endl;
      continue;
    }
    yo[num].insert(t);
  }
  return 0;
}
