AlgoUniversity
  • Go Back
Discussion
Decode Ways :

Author

Ayush Gangwani

Difficulty Level : Easy

Submissions : 272

Asked In : TCS

Marks :10

: 4 | : 0

Given a string $$$S$$$ containing only digits, find the number of ways to decode it as per the rules explained below.

To decode an encoded message, all the digits must be grouped and then mapped into letters using the following mapping:

  • "1" -> 'A'
  • "2" -> 'B'

    ...

  • "26" -> 'Z'

For example, $$$\tt{"11106"}$$$ can be mapped into:

  • $$$\tt{"AAJF"}$$$ with the grouping (1-1-10-6)
  • $$$\tt{"KJF"}$$$ with the grouping (11-10-6)
Note that the grouping (1-11-06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".

Input

The first line of input contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$ — the number of testcases. The description of $$$t$$$ testcases follows.

The first and only line of each test case contains a string $$$S$$$ $$$(1 \le |S| \le 10^5)$$$ containing digits.

It is guaranteed that the sum of $$$|S|$$$ over all testcases does not exceed $$$10^5$$$.

Output

For each testcase, print a single integer — the number of ways to decode the given string. As the answer can be rather large, print it modulo $$$10^9 + 7$$$.

Example

Input
4
421
101
12
226
Output
2
1
2
3

Note

In sample test case 1, we can decode the given string as either "DU" or "DBA".

In sample test case 2, we can decode the given string only as "JA".

In sample test case 3, we can decode the given string as either "L" or "AB".

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.