#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
int main() {
  map<int, int> p;
  map<int, int> f;
  string a, b;
  cin >> a >> b;
  int n;
  cin >> n;
  while (n--) {
    int t, m;
    char x, y;
    cin >> t >> x >> m >> y;
    if (f[m * x] == 0) {
      if (y == 'y') {
        if (p[m * x] == 1) {
          if (x == 'h')
            cout << a << " ";
          else
            cout << b << " ";
          cout << m << " " << t << endl;
          f[m * x] = 1;
        } else
          p[m * x]++;
      } else {
        if (x == 'h')
          cout << a << " ";
        else
          cout << b << " ";
        cout << m << " " << t << endl;
        f[m * x] = 1;
      }
    }
  }
}
