#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const long long MOD = 1e9 + 7;
long long n_bits(long long n) {
  long long x = __builtin_popcount(n);
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    map<int, int> a, h;
    string home, away;
    int m, n, test;
    char team, card;
    cin >> home >> away;
    cin >> test;
    while (test--) {
      cin >> m >> team;
      if (team == 'a') {
        cin >> n >> card;
        if (card == 'y')
          a[n] += 1;
        else
          a[n] += 2;
        if (a[n] >= 2) {
          cout << away << " " << n << " " << m << endl;
          a[n] = -10002;
        }
      } else {
        cin >> n >> card;
        if (card == 'y')
          h[n] += 1;
        else
          h[n] += 2;
        if (h[n] >= 2) {
          cout << home << " " << n << " " << m << endl;
          h[n] = -10002;
        }
      }
    }
    return 0;
  }
}
