#include <iostream>
using namespace std;
//Точно равенство на времето

int main() {
    int M, S, K, N;
    cin >> M >> S >> K >> N;

    int total = M * 60 + S;
    int currentTime = 0;
    int player = K;

    for (int i = 0; i < N; i++) {
        int W;
        char Z;
        cin >> W >> Z;

        // само равенство
        if (currentTime + W == total) {
            cout << player << endl;
            return 0;
        }

        currentTime += W;

        if (Z == 'T') {
            player++;
            if (player == 9) player = 1;
        }
    }

    return 0;
}
