#include <bits/stdc++.h>
using namespace std;
struct node {};
const int mod = 1000000007;
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
template <class T>
inline T Mod(T n, T m) {
  return (n % m + m) % m;
}
template <class T>
T my_pow(T n, T p) {
  if (p == 0) return 1;
  T x = my_pow(n, p / 2);
  x = (x * x);
  if (p & 1) x = (x * n);
  return x;
}
template <class T>
T big_mod(T n, T p, T m) {
  if (p == 0) return (T)1;
  T x = big_mod(n, p / 2, m);
  x = (x * x) % m;
  if (p & 1) x = (x * n) % m;
  return x;
}
template <class T>
T multiplication(T n, T p, T m) {
  if (p == 0) return (T)0;
  T x = multiplication(n, p / 2, m);
  x = (x + x) % m;
  if (p & 1) x = (x + n) % m;
  return x;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
map<string, long long> MPS;
map<long long, long long> MP, MPP, MPPP, MPPPP;
pair<long long, long long> P[100100];
long long a, b, n, m, res = 0, c = 0, t = 0, ans = 0, cc = 0, f = 0, ff = 0,
                      cnt = 0;
long long ar[5555555] = {0};
long long mn = (1e15), mx = -(1e15);
long long ar1[1001000] = {0};
long long fjakjfkas;
vector<long long> vv, vvv;
vector<string> v;
string s, ss, ch[100010];
int main() {
  ios_base::sync_with_stdio(false);
  long long akfjasfasf;
  string s1, s2;
  cin >> s1 >> s2;
  cin >> n;
  long long c = 0, cc = 0;
  for (__typeof(n) i = 0; i < (n); i++) {
    cin >> a >> s >> b >> ss;
    if (ss == "r" and s == "h" and MPPP[b] != 1) {
      MPPP[b] = 1;
      v.push_back(s1);
      vv.push_back(b);
      vvv.push_back(a);
    }
    if (ss == "r" and s == "a" and MPPPP[b] != 1) {
      MPPPP[b] = 1;
      v.push_back(s2);
      vv.push_back(b);
      vvv.push_back(a);
    }
    if (s == "h" and ss == "y" and MPPP[b] != 1) {
      c++;
      MPP[b]++;
      if (MPP[b] == 2) {
        MPPP[b] = 1;
        v.push_back(s1);
        vv.push_back(b);
        vvv.push_back(a);
        c = 0;
      }
    }
    if (s == "a" and ss == "y" and MPPP[b] != -1) {
      cc++;
      MP[b]++;
      if (MP[b] == 2) {
        MPPP[b] = 1;
        v.push_back(s2);
        vv.push_back(b);
        vvv.push_back(a);
        cc = 0;
      }
    }
  }
  if (v.size() > 0) {
    for (__typeof(v.size()) i = 0; i < (v.size()); i++) {
      cout << v[i] << " " << vv[i] << " " << vvv[i] << endl;
    }
  }
  return 0;
}
