#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int md = 1000000007;
int a[3][N], b[N], c[N], p[N];
int i, j, n, m, ans, x, y, t;
vector<int> v[26];
string s1, s2;
void out(int k, int t, int x) {
  if (k == 1)
    cout << s1;
  else
    cout << s2;
  cout << ' ' << x << ' ' << t << endl;
  return;
}
int main() {
  cin >> s1 >> s2 >> n;
  while (n--) {
    char c, cc;
    cin >> t >> c >> x >> cc;
    if (c == 'h')
      y = 1;
    else
      y = 2;
    if (cc == 'r') {
      if (a[y][x] < 2) out(y, t, x);
      a[y][x] += 2;
      continue;
    }
    a[y][x]++;
    if (a[y][x] == 2) out(y, t, x);
  }
}
