//05.10.2008 - 16:22:47
//12.09.2008 - 22:10:03
import java.lang.*;
import java.math.BigInteger;
import java.io.*;
import java.util.*;
import java.awt.geom.*;

public class Solution implements Runnable {
    public static BufferedReader br;
	public static PrintWriter out;
	public static StringTokenizer stk;
	public static boolean isStream = true;

	public static void main(String[] args) throws IOException {
		if (isStream) {
			br = new BufferedReader(new InputStreamReader(System.in));
		} else {
			br = new BufferedReader(new FileReader("in.txt"));
		}
		out = new PrintWriter(System.out);
		new Thread(new Solution()).start();
	}

	public void loadLine() {
		try {
			stk = new StringTokenizer(br.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String nextLine() {
		try {
			return br.readLine();

		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

	public String nextWord() {
		while (stk == null || !stk.hasMoreTokens())
			loadLine();
		return stk.nextToken();
	}

	public Integer nextInt() {
		while (stk == null || !stk.hasMoreTokens())
			loadLine();
		return Integer.parseInt(stk.nextToken());
	}

	public Long nextLong() {
		while (stk == null || !stk.hasMoreTokens())
			loadLine();
		return Long.valueOf(stk.nextToken());
	}

	public Double nextDouble() {
		while (stk == null || !stk.hasMoreTokens())
			loadLine();
		String s = stk.nextToken();
		if (s.charAt(0) == '.')
			s = '.' + s;
		return Double.valueOf(s);
	}

	public Float nextFloat() {
		while (stk == null || !stk.hasMoreTokens())
			loadLine();
		return Float.valueOf(stk.nextToken());
	}
	
	String get(int a) {
		StringBuilder sb = new  StringBuilder();
		if (a %2 == 0) {
			for (int i = 0; i < a/2; i++) {
				sb.append(" --");
			}
		} else {
			sb.append(" ---"); a-=3;
			for (int i = 0; i < a/2; i++) {
				sb.append(" --");
			}
		}
		return sb.toString() + " ";
	}
	
	public void run() {
		int n = nextInt();
		for (int j = 0; j < n; j++) {
			String s = nextLine();
			s = s.replaceAll("[ ]+", " ");
			s = s.replaceAll(" -", "-");
			s = s.replaceAll("- ", "-");
			s = s.replaceAll(" \"", "\"");
			s = s.replaceAll("\" ", "\"");
			int cnt = 0;
			StringBuilder ans = new StringBuilder();
			for (int i = 0; i < s.length(); i++) {
				if (s.charAt(i) == '-') {
					cnt++;
				} else {
					if (cnt == 1) {
						if (s.charAt(i) == '"' || s.charAt(i-2) == '"') {
							ans = new StringBuilder("error");
							break;
						} else {
							ans.append('-');
						}
					} else
					if (cnt == 2) {
						ans.append(" -- ");
					} else 
					if (cnt >= 3) ans.append(get(cnt));
					cnt = 0;
					ans.append(s.charAt(i));
				}
			}
			out.println(ans.toString());
		}
		out.flush();
	}
}
