#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
const int INF = (int)1e9;
const long double EPS = (long double)1e-11;
map<pair<string, int>, int> mp1;
int main() {
  string s, s1;
  cin >> s >> s1;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t, num;
    char c, k;
    pair<string, int> g;
    cin >> t >> c >> num >> k;
    if (c == 'h') {
      g.first = s;
      g.second = num;
      if (k == 'y') mp1[g] += 1;
      if (k == 'r') mp1[g] += 2;
      if (mp1[g] >= 2) {
        cout << s << ' ' << num << ' ' << t << endl;
        mp1[g] = -INF;
      }
    }
    if (c == 'a') {
      g.first = s1;
      g.second = num;
      if (k == 'y') mp1[g] += 1;
      if (k == 'r') mp1[g] += 2;
      if (mp1[g] >= 2) {
        cout << s1 << ' ' << num << ' ' << t << endl;
        mp1[g] = -INF;
      }
    }
  }
  return 0;
}
