import ru.ifmo.validate.*;

public class Validate implements Validator {
	static final int MAX_N = 50000;
	static final int MAX_H = 20;
	static final int MIN_L = 1 + 1 + 2;
	static final int MAX_L = 20 + 2 + 139; // Problem with length. Less on
											// one.

	@Override
	public void validate(ValidatingScanner in) throws Exception {
		int n = in.nextInt(1, MAX_N);
		in.eoln();
		for (int i = 0; i < n; i++) {
			String tweet = in.nextLine(MIN_L, MAX_L);
			int space = tweet.indexOf(' ');

			if (space == tweet.length() - 1) {
				throw new AssertionError("BAD_BAD_BAD");
			}

			if (tweet.charAt(0) != '@') {
				throw new AssertionError("The line doesn't start with @.");
			}

			if (space == -1) {
				throw new AssertionError("There's no space in line.");
			}

			if (tweet.charAt(space - 1) != ':') {
				throw new AssertionError("Handle contains color.");
			}

			int handle = space - 1;

			if (handle <= 0) {
				throw new AssertionError("Handle length is zero.");
			}

			if (handle > MAX_H) {
				throw new AssertionError("Handle length is bigger, than "
						+ MAX_H + ".");
			}

			for (int j = 0; j < tweet.length(); j++) {
				if (32 > tweet.charAt(j) || tweet.charAt(j) > 126) {
					throw new AssertionError(
							String.format(
									"The %d-th character of the line isn't in the range.",
									j));
				}
			}
			in.eoln();
		}
	}
}
