#include <bits/stdc++.h>
using namespace std;
void fr() {
  freopen("test_input.txt", "r", stdin);
  freopen("a.out", "w", stdout);
}
const int N = 5e5 + 5;
const int MAX = 5e6 + 123;
const int INF = 2e9;
const int mod = 1e9 + 7;
const double pi = 3.1415926536;
double eps = 1e-10;
bool used1[N], used2[N];
void solve() {
  int n;
  string s1, s2;
  map<int, int> cnt1, cnt2;
  map<int, pair<int, int> > ans;
  cin >> s1 >> s2;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t, m;
    char p, c;
    cin >> t >> p >> m >> c;
    if (p == 'h') {
      if (c == 'y')
        cnt1[m]++;
      else
        cnt1[m] += 2;
      if (cnt1[m] >= 2 and !used1[m]) {
        ans[t] = make_pair(0, m);
        used1[m] = 1;
      }
    } else {
      if (c == 'y')
        cnt2[m]++;
      else
        cnt2[m] += 2;
      if (cnt2[m] >= 2 and !used2[m]) {
        ans[t] = make_pair(1, m);
        used2[m] = 1;
      }
    }
  }
  for (int i = 1; i <= 90; i++) {
    if (ans[i] != make_pair(0, 0)) {
      if (ans[i].first == 0)
        cout << s1 << " ";
      else
        cout << s2 << " ";
      cout << ans[i].second << " " << i << endl;
    }
  }
}
int t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
