#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <sstream>
#include <algorithm>
int main() {
int numMessages;
std::cin >> numMessages;
std::cin.ignore(); // To ignore the newline after the number input
std::vector<std::string> messages(numMessages);
for (int i = 0; i < numMessages; i++) {
std::getline(std::cin, messages[i]);
}
std::vector<std::string> waitTime;
int currentTime = 0;
std::unordered_map<int, int> queue;
for (int i = 0; i < numMessages; i++) {
std::istringstream iss(messages[i]);
std::string command;
int magnitude;
iss >> command >> magnitude;
if (command == "W") {
currentTime += (magnitude - 1);
} else if (command == "R") {
queue[magnitude] = currentTime;
currentTime++;
} else if (command == "S") {
bool found = false;
for (const auto& pair : queue) {
if (pair.first == magnitude) {
waitTime.push_back(std::to_string(pair.first) + " " +
std::to_string(currentTime - pair.second));
queue.erase(pair.first);
found = true;
break;
}
}
if (!found) {
waitTime.push_back(std::to_string(magnitude) + " -9");
}
currentTime++;
}
}
if (!queue.empty()) {
for (const auto& pair : queue) {
waitTime.push_back(std::to_string(pair.first) + " " + std::to_string(-
1));
}
}
for (size_t i = 0; i < waitTime.size(); i++) {
for (size_t x = 0; x < waitTime.size(); x++) {
if (i != x) {
std::istringstream one(waitTime[i]);
std::istringstream two(waitTime[x]);
int key1, key2, val1, val2;
one >> key1 >> val1;
two >> key2 >> val2;
if (key1 == key2) {
waitTime[x] = std::to_string(key1) + " " + std::to_string(val1
+ val2);
waitTime.erase(waitTime.begin() + i);
i--; // Adjust index after removal
break;
}
}
}
}
std::sort(waitTime.begin(), waitTime.end());
std::vector<std::string> printed;
for (const auto& output : waitTime) {
if (std::find(printed.begin(), printed.end(), output) == printed.end()) {
std::cout << output << std::endl;
printed.push_back(output);
}
}
return 0;
}