cswork / OAOpen practice workspace

IBMOA #55

Chairs Requirement

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

Given several simulations of employees coming and going, find the minimum number of chairs that must be bought for each simulation. Initially there are no chairs; an employee always uses an empty chair first, and a chair is bought only when there is no empty one. C means a new employee enters, R means an employee temporarily goes to the meeting room, U means an employee returns from the meeting room, and L means an employee leaves permanently. This site's addition: every simulation is a valid event sequence; when R/L is executed at least one employee is in the room, and when U is executed at least one employee is in the meeting room. Employee identities are not distinguished; only the headcount states above must be respected.

Input

The first line contains n; each of the next n lines gives one simulation string containing only C, R, U and L. 1≤n≤100, 1≤length of each string≤10000.

Output

Output n space-separated integers in input order, each being the minimum number of chairs that must be bought for that simulation.

Example 1

Input:

1
C

Output:

1

Example 2

Input:

1
CCCRLCC

Output:

3

Example 3

Input:

1
CCRRCRUU

Output:

2

Editorial

Loading solution…