ACPC11A - Arabic and English

Some computer programs have problems in displaying Arabic text, especially when mixed with English words in the same line, because Arabic is written from right to left and English is written from left to right. In this problem we will try to fix a text with some corrupted lines which consist of a mixture of Arabic and English words. For simplicity, all Arabic letters will be replaced with the symbol '#'.

Each line will contain at most one English word. For a line containing an English word, the program that will fix the text will swap the words before the English word with the words after the English word. The words before the English word will remain in the same order. The words after the English word will also remain in the same order. For example, if the line is "# #### ### abc ##", it will be fixed to become "## abc # #### ###".

Please note that a line that contains words only of the same language is not corrupt.

Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Next 2T lines contain the test cases, each on a pair of lines. The first line of each case contains a single integer N, the number of words in the line to fix (1 ≤ N ≤ 100). The second line contains N words, separated by single spaces, with no leading or trailing spaces, and each word will be at least 1 character and at most 10 characters long.

Each word will be either Arabic or English. Arabic words will consist of one to ten '#' letters, and English words will consist of one to ten English lower case letters.

Each line contains at most one English word.

Output

For each test case, output, on a single line, the fixed line of input text.

Example

Input:
3
5
# #### ### abc ##
4
## ### ## #####
4
## ##### # xyz

Output:
## abc # #### ###
## ### ## #####
xyz ## ##### #

Added by:mohamedwahba
Date:2011-12-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Arab Collegiate Programming Contest

hide comments
2014-10-06 22:16:04 Mitch Schwartz
31 bytes is possible in Perl.
2013-07-26 15:50:32 Mostafa 36a2
It's a good tutorial ,
and it's good to put it in SHORTEN i think :)
2013-07-01 18:23:07 pika_pika
the debugging code costed me 2 WA... so stupid not to detect... easy in python
2012-06-11 06:28:38 :D
I won't leave problems in classical, just because you will complain for every one of them. The rules to move to tutorial is simple:

1. The problem doesn't require an actual algorithm or is REALLY basic to work out.
2. Implementation requires only most basic of programming methods and the code itself is short.

Both conditions are met here.

I'm aware that there are still trivial problem in the classical section, but I try think carefully on every case. In addition, I'm leaving some of the very old problems.
2012-06-11 00:56:58 Ashhar Jawaid


Last edit: 2012-06-11 15:25:33
2012-05-08 15:40:34 !!AV!!
whats the problem with input in java...??
are there blank lines between inputs?
2012-02-24 02:24:42 Mitch Schwartz
@santosh kumar
Your concern was addressed by BOND in response to Summa. C strings are terminated by null character, '\0'. The problem statement is correct.
2012-02-23 18:26:25 (^_^)
Note: In this problem a word has more than 10 characters so take it 11 or more.
@WahbA change the problem statement which says that a word is of at most 10 characters it cost me many WA.

Last edit: 2012-02-23 18:27:17
2012-01-15 19:09:48 Atanu
Any corner cases???
I get perfect answer but wa in spoj !!!!! :(
if a sentence has english words it can be only 1 word right?

Last edit: 2012-01-15 19:10:17
2012-01-15 06:22:54 Ranker
@ himanshu..problem clearly says there can be atmost one word in the string.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.