import java.io.*;
import java.util.*;

public class doall {
	static TestWriter t = new TestWriter();
	static Random r = new Random(566);
	static int[] p = new int[]{2, 3, 5, 7, 11, 19, 71, 157, 239, 677};
	static boolean simplified;
	static boolean brackets;

	static private void t(String s) {
		if (simplified)
			s = s.replaceAll("[\\[\\]]", "");
		t.t(s);
	}
	
	public static void main(String[] args) throws IOException {
		Properties prop = new Properties();
		prop.load(new FileReader("..\\problem.properties"));
		simplified = "true".equals(prop.getProperty("simplified"));
		brackets = false;
		t("((669:604).(586:(27:[(534.534)])))");
		t("1");
		t("9999");
		t("(1.1)");
		t("(5:66)");
		t("(8.2048.[4])");
		t("(3:[9]:27)");
		t("((566:[30]).1.239)");
		t("(2.22.(2222.[2]))");
		t("((1024:[2048]).([4096]:8192))");
		t("([7].(15:(260.[(1:1)])).7)");
		t("((1:7:49:343:2401).(1:11:121:1331))");
		t("((1728:144:12:1).[(6:5:4:3:2:1)].(1849:43:1))");
		t("((1:[1]).(1:1:1:[1]:1:1).([1]:1:1:1))");
		t("((3.1415):[([2].7182)]:(1000.[1].10.100):(2.1.2.8.5.1.6))");
		t("(([(5:6)].(4:[3])):(2.1.[(7.[([8].505)])].9))");
		t("([1024].32)");
		t("(8.[8192])");
		t("((1:3:9):[(1:4:16:64)]:(1:5:25:125:625))");
		t("([((1.2.3.4).(1.[2].3).(1.2.[3]))]:((1.2.3).(1.[2]).([1].2).(1.2.3)))");
		t("(123.[(234.[(345.[(456.[566])])])])");
		t("((1:(3.3.3):(5.5.5.5.5)).((2:2):(4:4:4:4):(6:6:6:6:6:6)))");
		t("((1:(3.3.3):(5.5.5.5.5)).((2.2):(4.4.4.4):(6.6.6.6.6.6)))");
		t("((4.16.64.256.[1024]):[(1:2:3:4:5:6)]:(7.8.9.10))");
		t(pureRandom(3, 4, 1, ' '));
		t(pureRandom(4, 4, 0, ' '));
		t(pureRandom(5, 3, 0.5, ' '));
		t(pureRandom(6, 2, 0.5, ' '));
		t(maxNesting(6));
		t(maxNesting(7));
		t(pureRandom(5, 2, 1, '.'));
		t(pureRandom(6, 6, 0.8, '.'));
		t(chain3(7, 0.6));
		t(chain3(11, 0.9));
		t(chain2());
		t(square1(3));
		t(square1(7));
		t(chain4(new int[]{2, 3, 5}));
		t(square2());
		t(square(new int[]{3, 4, 5}, new int[]{2, 5, 7}, ' '));
		t(square(new int[]{3, 4, 5}, new int[]{4, 5, 7}, ' '));
		t(square(new int[]{11, 13}, new int[]{11, 13}, ' '));
		t(square(new int[]{4, 33}, new int[]{4, 33}, ' '));
		t(square(new int[]{1}, new int[]{3, 4, 5, 7, 13}, ':'));
		t(square(new int[]{1}, new int[]{3, 4, 41, 7}, '.'));
		t(square(new int[]{2, 3}, new int[]{4, 5, 6}, '.'));
		t(square(new int[]{2, 3}, new int[]{4, 5, 6, 13}, '.'));
		t(square(new int[]{3, 3}, new int[]{4, 5, 6, 13}, '.'));
		t(square(new int[]{3, 3, 6}, new int[]{4, 4}, '.'));
		brackets = true;
		t(square(new int[]{4, 5}, new int[]{4, 5}, '.'));
		t(square(new int[]{2, 3, 4}, new int[]{5, 6}, '.'));
		t(square(new int[]{4, 6}, new int[]{5, 6, 7}, '.'));
		t(square(new int[]{2, 3, 4}, new int[]{2, 3, 4}, ':'));
		if (!simplified) {
			t(square(new int[]{11, 13}, new int[]{7, 11, 13}, ':'));
			t(square(new int[]{3, 3}, new int[]{4, 5, 6, 13}, '.'));
			t(square(new int[]{3, 3, 6}, new int[]{4, 4}, '.'));
		}
	}
	
	public static void shuffle(int[] a) {
		for (int i = a.length - 1; i > 0; i--) {
			int j = r.nextInt(i + 1);
			int t = a[i]; a[i] = a[j]; a[j] = t;
		}
	}

	private static char randomDelimeter() {
		return r.nextBoolean() ? ':' : '.';
	}
	
	private static String randomGlyph(int maxlen) {
		int m = 1;
		while (maxlen --> 0)
			m *= 10;
		return Integer.toString(r.nextInt(m - 1) + 1);
	}
	
	private static String randomGlyph() {
		return randomGlyph(r.nextInt(4) + 1);
	}
	
	private static String pureRandom(int depth, int maxkids, double probSquareBrackets, char delim) {
		if (depth == 1)
			return randomGlyph();
		int kids = r.nextInt(maxkids - 1) + 2;
		char del = (delim == ' ') ? randomDelimeter() : delim;
		int sq = -1;
		if (r.nextDouble() < probSquareBrackets) {
			sq = r.nextInt(kids);
		}
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		for (int i = 0; i < kids; i++) {
			if (i == sq)
				sb.append("[");
			sb.append(pureRandom(depth - 1, kids, probSquareBrackets, delim));
			if (i == sq)
				sb.append("]");
			if (i < kids - 1)
				sb.append(del);
		}
		sb.append(")");
		return sb.toString();
	}
	
	private static String maxNesting(int depth) {
		if (depth == 1)
			return randomGlyph(1);
		return "(" + maxNesting(depth - 1) + randomDelimeter() + maxNesting(depth - 1) + ")";
	}
	
	private static String longChain(int length, char delim) {
		StringBuilder sb = new StringBuilder();
		if (length > 1)
			sb.append("(");
		for (int i = 0; i < length; i++) {
			if (brackets && i == 1 && length > 1)
				sb.append("[");
			sb.append(randomGlyph(1));
			if (brackets && i == 1 && length > 1)
				sb.append("]");
			if (i < length - 1)
				sb.append(delim);
		}
		if (length > 1)
			sb.append(")");
		return sb.toString();
	}
	
	private static String longChain2(int length, char delim, int hei) {
		StringBuilder sb = new StringBuilder();
		if (length > 1)
			sb.append("(");
		int vert = r.nextInt(length);
		for (int i = 0; i < length; i++) {
			if (brackets && i == 1 && length > 1)
				sb.append("[");
			if (i == vert) {
				sb.append(longChain(hei, (char) (delim ^ '.' ^ ':')));
			} else {
				sb.append(randomGlyph(1));
			}
			if (brackets && i == 1 && length > 1)
				sb.append("]");
			if (i < length - 1)
				sb.append(delim);
		}
		if (length > 1)
			sb.append(")");
		return sb.toString();
	}
	
	private static CharSequence chain1(int p, char delim) {
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		int dbl = -1;
		if (p > 2) {
			p--;
			dbl = r.nextInt(p);
		}
		for (int i = 0; i < p; i++) {
			if (i == dbl)
				sb.append("[");
			sb.append(randomGlyph());
			if (i == dbl)
				sb.append("]");
			if (i < p - 1)
				sb.append(delim);
		}
		sb.append(")");
		return sb.toString();
	}

	private static String chain2() {
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		for (int i = 0; i < 4; i++) {
			sb.append(chain1(p[i], ':'));
			if (i < 4 - 1)
				sb.append('.');
		}
		sb.append(")");
		return sb.toString();
	}

	private static String chain3(int size, double probSquareBrackets) {
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		for (int i = 0; i < size; i++) {
			sb.append(pureRandom(2, 4, probSquareBrackets, ' '));
			if (i < size - 1)
				sb.append('.');
		}
		sb.append(")");
		return sb.toString();
	}
	
	private static String square1(int p) {
		char delim = randomDelimeter();
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		int dbl = -1, pp = p;
		if (p > 2) {
			p--;
			dbl = r.nextInt(p);
		}
		for (int i = 0; i < p; i++) {
			if (i == dbl)
				sb.append("[");
			sb.append(chain1(pp, (char) (delim ^ '.' ^ ':')));
			if (i == dbl)
				sb.append("]");
			if (i < p - 1)
				sb.append(delim);
		}
		sb.append(")");
		return sb.toString();
	}
	
	private static String chain4(int[] x) {
		StringBuilder sb = new StringBuilder();
		for (int s : x) {
			if (sb.length() == 0)
				sb.append("(");
			else
				sb.append(".");
			sb.append(square1(s));
		}
		sb.append(")");
		return sb.toString();
	}
	
	private static String square2() {
		StringBuilder sb = new StringBuilder();
		sb.append("(");
		sb.append(chain4(new int[]{2, 3, 4}));
		sb.append(":");
		sb.append(chain4(new int[]{5, 3, 2}));
		sb.append(")");
		return sb.toString();
	}

	private static String square(int[] xs, int[] ys, char delim) {
		StringBuilder sb = new StringBuilder();
		delim = (delim == ' ') ? randomDelimeter() : delim;
		if (xs.length > 1)
			sb.append("(");
		boolean first = true;
		for (int x : xs) {
			if (!first)
				sb.append(delim);
			if (brackets && first && xs.length > 1)
				sb.append("[");
			shuffle(ys);
			sb.append(chain5(ys, x, (char) (delim ^ '.' ^ ':')));
			if (brackets && first && xs.length > 1)
				sb.append("]");
			first = false;
		}
		if (xs.length > 1)
			sb.append(")");
		return sb.toString();
	}

	private static String chain5(int[] xs, int y, char delim) {
		StringBuilder sb = new StringBuilder();
		if (xs.length > 1)
			sb.append("(");
		int vert = r.nextInt(xs.length);
		for (int i = 0; i < xs.length; i++) {
			if (brackets && i == 1 && xs.length > 1)
				sb.append("[");
			if (i == vert) {
				sb.append(longChain2(xs[i], delim, y));
			} else {
				sb.append(longChain(xs[i], delim));
			}
			if (brackets && i == 1 && xs.length > 1)
				sb.append("]");
			if (i < xs.length - 1)
				sb.append(delim);
		}
		if (xs.length > 1)
			sb.append(")");
		return sb.toString();
	}
}

class TestWriter {
	public int curTest = 1;
	public PrintWriter out;

	public void open() {
		try {
			out = new PrintWriter("" + curTest / 10 + curTest % 10);
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public void close() {
		out.close();
		curTest++;
	}

	public void t(String s) {
		open();
		out.println(s);
		close();
	}

	public void t(String[] s) {
		open();
		for (String ss : s)
			out.println(ss);
		close();
	}

	public void tn(String[] s) {
		open();
		out.println(s.length);
		for (String ss : s)
			out.println(ss);
		close();
	}

	public void t(Object[] s) {
		open();
		for (Object ss : s)
			out.println(ss);
		close();
	}

	public void tn(Object[] s) {
		open();
		out.println(s.length);
		for (Object ss : s)
			out.println(ss);
		close();
	}

	public void t(int s) {
		open();
		out.println(s);
		close();
	}

	public void tl(int s1, int s2) {
		open();
		out.println(s1 + " " + s2);
		close();
	}

	public void t(int[] s) {
		open();
		for (int ss : s)
			out.println(ss);
		close();
	}

	public void tn(int[] s) {
		open();
		out.println(s.length);
		for (int ss : s)
			out.println(ss);
		close();
	}
}
