// Arup Guha
// 10/22/2014
// Solution to 1994 UCF High School Contest Problem: Bank

// Note: The judge solution crashes on my machine and no output file was posted, just the input.
//       Thus, I am not sure if this solution is correct. It runs just fine on the judge input and
//       produces valid output. Eyeballing the cases, I see no obvious errors, but tracing all of
//       the cases accurately by hand would be extremely annoying. My general method of solution is
//       certainly valid, but there are so many details in the problem that I might have messed
//       something up.

/*** Edited on 7/15/2026 - I used this solution to find a bug in my other solution, and then
                           realized that this solution had a bug too. Now, both of my solutions
						   agree, so I have some confidence that both are correct. Each fix I
						   made makes logical sense. In this one, I allow the queue size to grow
						   greater than 5, which should not be allowed. I added a fix that removes
						   an item in the queue if adding a valid customer pushes the queue size 
						   to 6. This occurs when the time the customer gets in line is before
						   an operation finishes but that customer is willing to wait in line.
						   Fix is on line 82.
	
***/

import java.util.*;

public class bank {

	// Constants from problem description.
	final public static String[] TRANSACTIONS = {"DEPOSIT","WITHDRAW","CASHIERS_CHECK","LOAN",
												"ACCOUNT_BALANCE","ATM_CARD","OPEN_ACCOUNT"};
	final public static int[] TIMES = {5,7,10,50,2,20,30};

	public static void main(String[] args) {

		// I want this to be a constant, but don't know how to do it, so it's a variable.
		// Builds look up table of wait times for each transaction.
		customer.waitTimes = new HashMap<String,Integer>();
		for (int i=0; i<TRANSACTIONS.length; i++)
			customer.waitTimes.put(TRANSACTIONS[i], TIMES[i]);

		Scanner stdin = new Scanner(System.in);

		// Process each case.
		while (stdin.hasNext()) {

			// Heading
			System.out.println("CUSTOMER        TRANSACTION/COMPLETED        IN       OUT");
			System.out.println("----------------------------------------------------------");

			// Priority Queue keeping track of who is being served.
			PriorityQueue<customer> pq = new PriorityQueue<customer>();
			int curTime = 0;

			// Go through each customer.
			int n = stdin.nextInt();
			for (int loop = 0; loop<n; loop++) {

				// Just read in the data.
				String name = stdin.next();
				int nextArrive = stdin.nextInt();
				curTime += nextArrive;
				int willWait = stdin.nextInt();
				String trans = stdin.next();
				String amt = "";
				if (trans.equals("WITHDRAW") || trans.equals("LOAN"))
					amt = stdin.next();

				// Process the priority queue - remove all customers who are currently done.
				while (pq.size() > 0 && pq.peek().timeOut < curTime)
					pq.poll();

				// When queue is free.
				int qOpen = pq.size() < 5 ? curTime : pq.peek().timeOut;

				// Form customer and print out result.
				customer next = new customer(name, trans, amt, curTime, curTime+willWait, qOpen-curTime);
				System.out.println(next);

				// Add to queue if they did their transaction.
				if (next.completed.equals("YES")) {
					pq.offer(next);
					if (pq.size() == 6) pq.poll(); /*** Added on 7/15/2026 ***/
				}
			}

			// Separation between cases.
			System.out.println("\n");
		}
	}
}

class customer implements Comparable<customer> {

 	final public static int[] WIDTH = {16,29,10};
	final public static double EPSILON = 1e-9;
 	public static HashMap<String,Integer> waitTimes;

	public String name;
	public String transaction;
	public String amount;
	public int timeIn;
	public int timeOut;
	public String completed;

	public customer(String n, String t, String amt, int startT, int endT, int queueT) {
		name = n;
		transaction = t;
		amount = amt;

		// Set times in and out.
		if (queueT > endT-startT) {
			timeIn = startT;
			timeOut = endT;
			completed = "NO";
		}
		else {
			timeIn = startT;
			timeOut = startT+queueT+transTime();
			completed = "YES";
		}
	}

	public int transTime() {
		return waitTimes.get(transaction) + (int)(getAmountTime()+EPSILON);
	}

	// Returns numeric version of amount.
	public double getAmountTime() {
		if (amount.length() == 0) return 0;
		if (transaction.equals("WITHDRAW")) return Math.ceil(Double.parseDouble(amount.substring(1))/100);
		return 3*Math.ceil(Double.parseDouble(amount.substring(1))/100);
	}

	// For priority queue - we just care when you get out of line.
	public int compareTo(customer other) {
		return this.timeOut - other.timeOut;
	}

	// This might be the most annoying toString method I've ever written.
	public String toString() {

		// Adds the customer and transaction.
		String ans = name+spaces(WIDTH[0]-name.length())+transaction;

		// Now, add an amount, if we need to.
		int padding = WIDTH[1]-transaction.length()-amount.length()-completed.length()-1;
		if (amount.length() > 0) {
			ans = ans + " "+amount;
			padding--;
		}

		// This is the rest of the transaction with spaces at the end.

		ans = ans + "/" + completed + spaces(padding);

		// Finally, time in and time out.
		String tmp = ""+timeIn;
		ans = ans + tmp + spaces(WIDTH[2]-tmp.length()) + timeOut;
		return ans;
	}

	// Returns a String with k spaces.
	public static String spaces(int k) {
		char[] arr = new char[k];
		Arrays.fill(arr, ' ');
		return new String(arr);
	}
}