import java.io.*;

public class Solution4
{
    public static void main (String[] args) throws IOException, FileNotFoundException
    {
	BufferedReader reader = new BufferedReader (new FileReader ("DATA4.txt"));
	PrintWriter writer = new PrintWriter (new FileWriter ("OUT4.txt"));

	String input[] = new String [5];

	for (int a = 0 ; a <= 4 ; a++)
	{
	    input [a] = reader.readLine ();


	}
	char[] open = new char [256];
	char test;
	int numOpen = 0;
	boolean balanced = true;
	for (int counter = 0 ; counter < 5 ; counter++)
	{
	    balanced = true;
	    for (int i = 0 ; i < input [counter].length () ; i++)

		{
		    test = input [counter].charAt (i);
		    if (test == '[' || test == '{' || test == '(')
		    {
			open [numOpen] = test;
			numOpen++;
		    }

		    else if (test == ']' || test == '}' || test == ')')
		    {
			if (numOpen == 0)
			{
			    balanced = false;
			}
			else if (reverse (open [numOpen-1], test))

			    {
				numOpen--;
			    }
			else
			{
			    balanced = false;
			}

		    }

		}
	    if (balanced == true)
	    {
		writer.println ("balanced");
	    }
	    else
	    {
		writer.println ("not balanced");

	    }
	}
	reader.close ();
	writer.close ();
    }


    static boolean reverse (char c, char d)
    {
	if (c == '(' && d == ')')
	    return true;
	if (c == '{' && d == '}')
	    return true;
	if (c == '[' && d == ']')
	    return true;
	return false;
    }
}




