#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[5][101];
int a, b, c, n, m[3][100], v[3][100];
string s[5], q, z;
int main() {
  cin >> s[1] >> s[2];
  cin >> a;
  for (int i = 1; i <= a; ++i) {
    cin >> b >> q >> c >> z;
    if (q == "h")
      n = 1;
    else
      n = 2;
    if (z == "y" && m[n][c] < 2)
      d[n][b].first = m[n][c] + 1, m[n][c]++, d[n][b].second = c;
    else if (d[n][b].first == 0)
      d[n][b].first = 2, d[n][b].second = c;
  }
  for (int j = 1; j <= 99; ++j) {
    for (int i = 1; i <= 2; ++i) {
      if (d[i][j].first > 1 && v[i][d[i][j].second] == 0)
        cout << s[i] << " " << d[i][j].second << " " << j << endl,
            v[i][d[i][j].second]++;
    }
  }
  return 0;
}
