#include <bits/stdc++.h>
using namespace std;
int a[105], b[105];
int main() {
  string str, str1;
  int n, x[105], y[105], i;
  char ch[105], ch1[105];
  cin >> str >> str1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x[i] >> ch[i] >> y[i] >> ch1[i];
  }
  for (i = 1; i <= n; i++) {
    if (ch[i] == 'h') {
      if (ch1[i] == 'y') {
        a[y[i]]++;
      } else
        a[y[i]] += 2;
      if (a[y[i]] >= 2) {
        cout << str << " " << y[i] << " " << x[i] << endl;
        a[y[i]] = -1000;
      }
    } else {
      if (ch1[i] == 'y') {
        b[y[i]]++;
      } else
        b[y[i]] += 2;
      if (b[y[i]] >= 2) {
        cout << str1 << " " << y[i] << " " << x[i] << endl;
        b[y[i]] = -1000;
      }
    }
  }
  return 0;
}
