FANCY - FANCY NUMBERS


Girls usually give only missed calls to their boyfriends and they want them to call back. These boys are now busy with their engineering subjects and cannot remember all girl friends’ mobile number. Because of this, girls make it easy for them by having fancy mobile numbers. A fancy mobile number may contain many continuous digits in it.

For example 9994442200 is a fancy mobile number because the boy can remember simply as triple nine, triple four, double two and double zero. As they are engineering students they do think different. One of the engineering students can spell the above number as double nine, nine, four, double four, two, two, double zero.

The number 100 has only 2 possibilities as it can be spelt as either one, zero, zero (or) one, double zero.

Given a mobile number find the number of possibilities that the number can be remembered.

Input

The first line consists of an integer t denoting the number of test cases. Each test case consists of a mobile number of length <= 30 digits.

Output

For each test case output the number of possibilities the number can be remembered.

Constraints

1 <= t <= 100000

Example

Input:
3
100
12345
11112

Output:
2
1
8

WARNING: Huge data set! Make your I/O optimizations.


hide comments
tearing: 2021-08-02 16:04:51

I use "string", "cin" and "cout" in cpp14, but it get TLE #7, then I use "char s[N]", "qread" and "qwrite", it get AC.

Asokan R: 2019-10-30 11:00:21

Same code gives AC in cpp, but fails in java with NZEC error

pistachio: 2019-04-04 14:10:02

If you have Runtime Error NZEC in Java please take into account that test no 5, 6 or 7 is not terminated by '\n' thus you have to handel EOF.

anirudnits: 2018-02-10 11:13:21

Got NZEC in python 3.5 but same logic got AC in C++14!

up79: 2017-06-25 12:11:18

AC in one go with string and cin , cout :)

lucy_dragneel: 2017-06-06 00:20:02

use concept of [spoiler] and [spoiler] :)

Last edit: 2017-08-02 13:04:46
rohit9934: 2017-03-13 15:12:40

#math tag should be removed.its #ad-hoc .Learn how to manipulate numbers with strings.

kass_97: 2017-01-06 12:39:39

Took some time until I came up with an easy solution, you can ignore the warning though :p

Rakend Chauhan: 2016-12-22 01:54:35

can be solved with [spoiler].

Last edit: 2016-12-28 19:24:35
prasoonbatham: 2016-10-22 14:52:10

Simple logic. But there's something wrong with test case 7. Please fix it. Gives NZEC in java.


Added by:cegprakash
Date:2011-12-26
Time limit:0.802s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64