#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> cnt;
map<pair<int, int>, int> visited;
int main() {
  int n;
  int a, b;
  char c, d;
  string t1, t2;
  cin >> t1 >> t2;
  cin >> n;
  while (n--) {
    cin >> a >> c >> b >> d;
    if (d == 'r') {
      if (c == 'h')
        cnt[make_pair(b, 0)] += 2;
      else
        cnt[make_pair(b, 1)] += 2;
    } else {
      if (c == 'h')
        cnt[make_pair(b, 0)]++;
      else
        cnt[make_pair(b, 1)]++;
    }
    if (cnt[make_pair(b, 0)] >= 2 && c == 'h' && !visited[make_pair(b, 0)]) {
      cout << t1 << " ";
      cout << b << " " << a;
      cout << endl;
      visited[make_pair(b, 0)] = 1;
    } else if (cnt[make_pair(b, 1)] >= 2 && c == 'a' &&
               !visited[make_pair(b, 1)]) {
      cout << t2 << " ";
      cout << b << " " << a;
      visited[make_pair(b, 1)] = 1;
      cout << endl;
    }
  }
  return 0;
}
