#include <bits/stdc++.h>
using namespace std;
string s1, s2, team, color;
int n, minute, number, t1[100], t1__[100], t2[100], t2__[100];
int main() {
  cin >> s1 >> s2 >> n;
  for (int i = 1; i <= n; i++) {
    cin >> minute >> team >> number >> color;
    if (color == "r") {
      if (team == "h" && t1__[number] == 0) {
        cout << s1 << " ";
        t1__[number] = 1;
        cout << number << " " << minute << endl;
      } else if (team == "a" && t2__[number] == 0) {
        cout << s2 << " ";
        t2__[number] = 1;
        cout << number << " " << minute << endl;
      }
    } else {
      if (team == "h") {
        t1[number]++;
        if (t1[number] == 2 && t1__[number] == 0) {
          t1__[number] = 1;
          cout << s1 << " " << number << " " << minute << endl;
        }
      }
      if (team == "a") {
        t2[number]++;
        if (t2[number] == 2 && t2__[number] == 0) {
          t2__[number] = 1;
          cout << s2 << " " << number << " " << minute << endl;
        }
      }
    }
  }
}
