#include <bits/stdc++.h>
using namespace std;
int main() {
  string ss1, ss2;
  cin >> ss1 >> ss2;
  long long n;
  cin >> n;
  map<long long, long long> count1, count2;
  map<long long, long long> time1, time2;
  for (__typeof(n) i = 0; i < n; i++) {
    long long t, nn;
    string s, s2;
    cin >> t >> s >> nn >> s2;
    if (s == "h") {
      if (count1[nn] >= 2) continue;
      if (s2 == "y") {
        count1[nn]++;
        if (count1[nn] == 2) {
          cout << ss1 << " " << nn << " " << t << endl;
        }
      } else {
        count1[nn] = 2;
        cout << ss1 << " " << nn << " " << t << endl;
      }
    }
    if (s == "a") {
      if (count2[nn] >= 2) continue;
      if (s2 == "y") {
        count2[nn]++;
        if (count2[nn] == 2) {
          cout << ss2 << " " << nn << " " << t << endl;
        }
      } else {
        count2[nn] = 2;
        cout << ss2 << " " << nn << " " << t << endl;
      }
    }
  }
  return 0;
}
