## 2nd Balkan Olympiad in Informatics

Thessaloniki, Greece, 1-6 October 1994

## Day 1 - Problem 3 (35 points)

Recycling glass requires that the glass be separated by color into one of three
categories: brown, green, and clear glass. You are given three recycling bins, each
containing a specified number of brown, green and clear bottles. In order to be recycled,
the bottles will need to be moved so that each bin contains unicolored bottles. The
problem is to minimize the number of bottle movements assuming that the bin capacity is
infinite.

The first line of the input is a single integer denoting the number of successive lines.
Each successive line consists of 9 integers separated by space. The first three integers
on a line represent the number of brown, green and clear bottles respectively in the bin
#1, the second three integers represent the number of brown, green and clear bottles
respectively in the bin #2, whereas the third three integers represent the number of
brown, green and clear bottles respectively in the bin #3.

For each line of input there will be one line of output containing:

- a string consisting of three characters: B, G, and C (standing for the three colors),
representing the content of three numbered bins, and
- an integer denoting the minimum number of bottle movements. If more than one order of B,
G, and C yields the minimum number of movements, then you should give the first string in
alphabetical order.