Given a string S containing digits from 2 to 9 inclusive. Your task is to find all possible letter combinations that the number could represent.
A mapping from Digits to Letters (just like in Nokia 1100) is shown below. Note that 1 does not map to any letter.

The first line of input contains an integer ‘T’ denoting the number of test cases.
Then the 'T' test cases follow.
The first and only line of each test case contains string S.
Output Format
For each test case, the list containing all the combinations of letters will be printed.
The output of each test case is printed in a separate line.
Note
You don’t have to print anything, it has already been taken care of. Just implement the function.
The output strings can be returned in any order.
1 <= T <= 10
1 <= |S| <= 10
2 <= S[i] <=9
Where |S| is the length of string 'S" and 'S[i]' represents the element of the string S.
Time Limit: 1 sec
1
23
ad ae af bd be bf cd ce cf
The letters corresponding to 2 are ‘a’, ‘b’, ‘c’ and corresponding to 3 are ‘d’, ‘e’, ‘f’. All the possible letter combinations for “23” will be "ad","ae","af","bd","be","bf","cd","ce","cf".
1
2
a b c
The letters corresponding to 2 are ‘a’, ‘b’, ‘c’.
Find all possible combinations using backtracking.
The idea is to find all possible combinations of letters using backtracking.
Backtracking is an algorithm to find all possible solutions by exploring all potential candidates. If the current solution does not turn out to be a solution or is not possibly the last solution, this algorithm backtracks and makes some changes on the previous steps.
Algorithm:
a. Iterate over the letters mapping the next available digit.
b. Append the current letter to the current combination and proceed to check the next digits.
O(3^N * 4^M), where N is the number of digits in the string S that maps to 3 letters and M is the number of digits in the string S that maps to 4 letters.
Numbers {2, 3, 4, 5, 6, 8} map to 3 letters and numbers {7, 9} map to 4 letters. Generating combinations of a string of length L takes K^L time, where K is the number of letters that each digit maps to. Thus, the final time complexity will be O(3^N * 4^M).
O(3^N * 4^M), where N is the number of digits in the string S that maps to 3 letters and M is the number of digits in the string S that maps to 4 letters.
Since we are storing all the possible combinations, thus the final space complexity is O(3^N * 4^M).