#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const int output_precision = 15;
const long double pi = acos(-1);
const bool debug = true;
vector<pair<pair<int, int>, int> > ans;
typedef struct in {
  int min;
  int team;
  int num;
  char type;
} info_t;
int cmp(const info_t &a, const info_t &b) { return a.min < b.min; }
const int M = 105;
info_t info[M];
int red[M][M];
int ye[M][M];
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(output_precision);
  cout << fixed;
  cout.tie(0);
  string s[2];
  int n, m, t, x;
  char c;
  cin >> s[0] >> s[1];
  cin >> n;
  for (int(i) = 0, j1234 = n; (i) < j1234; (i)++) {
    cin >> info[i].min >> c >> info[i].num >> info[i].type;
    info[i].team = (c == 'h' ? 0 : 1);
  }
  sort(info, info + n, cmp);
  for (int(i) = 0, j1234 = n; (i) < j1234; (i)++) {
    m = info[i].min;
    t = info[i].team;
    x = info[i].num;
    c = info[i].type;
    if (red[t][x]) continue;
    if (c == 'y') {
      ye[t][x]++;
      if (ye[t][x] == 2) {
        red[t][x] = m;
        ans.push_back(make_pair(make_pair(t, x), m));
      }
    } else {
      red[t][x] = m;
      ans.push_back(make_pair(make_pair(t, x), m));
    }
  }
  for (int(i) = 0, j1234 = ans.size(); (i) < j1234; (i)++) {
    t = ans[i].first.first;
    x = ans[i].first.second;
    m = ans[i].second;
    cout << s[t] << " " << x << " " << m << '\n';
  }
}
