#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  string s[2];
  cin >> s[0] >> s[1];
  int t;
  cin >> t;
  int a[2][100] = {0};
  while (t--) {
    int min;
    string wh;
    int num;
    string get;
    cin >> min >> wh >> num >> get;
    int p = wh == "a" ? 1 : 0;
    if (get == "y") {
      a[p][num]++;
      if (a[p][num] == 2) {
        cout << s[p] << " " << num << " " << min << endl;
      }
    } else {
      if (a[p][num] < 2) {
        a[p][num] = 2;
        cout << s[p] << " " << num << " " << min << endl;
      }
    }
  }
  return 0;
}
