题目:
第一题
It is really amazing that the great historian Dr.K has recently found that about 10 Million years ago, in the area where is now called China, lived an ancient people. They may be considered as the first intelligent creature existed on the earth.
As Dr.K's investigation advance, he found unbelievably that they even developed some so-called mathematics during their evolvement. Dr.K spent his half life to understand this ancient people's counting system. Finally he got to know that:
1、They use only 7 digits to represent numbers, and numbers are as follow:
| -> 1
|| -> 2
||| -> 3
|||| -> 4
||||| -> 5
|||||| -> 6
||||||| -> 7
It is a pity that they have not developed "0" before these people disappeared.
2、If a number is greater than 7, they use digit place just as we do today. Between each two digit places, there is a ",".
eg:
|||||,|| -> 42 (5x8+2)
|||,||,|||| -> 212 (3*64+2*8+4)
In order to further his study, Dr.K wants to know what the sequences found from stones mean in today's counting system. He turns to you for help, and smart as you are, you should help this great historian,should not you?
Input
The first line of standard input contains an integer N, the number of test cases. N lines followed.
In each line a sequence is given, it is guaranteed that the length of the sequence will not exceed 1024 characters and the outcome number will not be greater than 1000000.
Output
For each case you are to output a line giving the number in today's decimal counting system.
Sample Input
3
|||||,||
|||,||,||||
||,|,|,|,||||
Sample Output
42
212
8780