#include <bits/stdc++.h>
using namespace std;
map<char, string> mp1;
map<pair<char, int>, int> mp;
int main() {
  cin >> mp1['h'] >> mp1['a'];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t, m;
    char ch1, ch2;
    cin >> t >> ch1 >> m >> ch2;
    if (ch2 == 'r') {
      if (mp[make_pair(ch1, m)] < 2) {
        mp[make_pair(ch1, m)] = 2;
        cout << mp1[ch1] << " " << m << " " << t << endl;
      }
    } else {
      mp[make_pair(ch1, m)]++;
      if (mp[make_pair(ch1, m)] == 2) {
        cout << mp1[ch1] << " " << m << " " << t << endl;
      }
    }
  }
  return 0;
}
