You are given a natural number. Repeatedly sum its digits until the smallest possible two-digit number remains. Then multiply the digits of the remaining two-digit number and return it.
Example 1:
Input: n = 19
Output: 0 
Explanation: 1+9 = 1+0 = 1 and 1 came from 10 
thus 1*0 = 0.
Example 2:
Input: n = 129
Output: 2
Explanation: 1+2+9 = 1+2 = 3 and 3 came from 12
thus 1*2 = 2.
Your Task:  
You don't need to read input or print anything. Complete the function repeatedSumMul() which takes n as the input parameter and returns the product of the digits of the value before the single digit.
Expected Time Complexity: O(logn)
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=2^{32}

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3

class Solution:

    def repeatedSumMul (self, n):

        # code here 

Solutions:
class Solution:

	def repeatedSumMul(self, n):
		l = []
		l.append(n)
		while len(str(n)) > 1:
			summ = 0
			for i in str(n):
				summ += int(i)
			l.append(summ)
			n = summ
		val = 1
		for i in str(l[-2]):
			val *= int(i)
		return val


class Solution:

	def sumdig(self, n):
		s = 0
		while n:
			s += n % 10
			n //= 10
		return s

	def repeatedSumMul(self, n):
		if 0 < n < 10:
			return n
		else:
			s = self.sumdig(n)
			while self.sumdig(s) > 9:
				s = self.sumdig(s)
			j = s % 10
			s //= 10
			j *= s % 10
			return j


class Solution:

	def repeatedSumMul(self, n):

		def helper(x):
			m = str(x)
			if len(m) <= 1:
				return m
			ans = 0
			for i in m:
				ans += int(i)
			return ans
		x = [n]
		while len(str(n)) > 1:
			n = helper(n)
			x.append(n)
		a = str(x[-2])
		if len(a) > 2:
			return 0
		return int(a[0]) * int(a[1])


class Solution:

	def repeatedSumMul(self, N):
		from functools import reduce
		prod = 0
		while N > 9:
			add = reduce(lambda x, y: int(x) + int(y), list(str(N)))
			prod = reduce(lambda x, y: int(x) * int(y), list(str(N)))
			N = add
		return prod


class Solution:

	def repeatedSumMul(self, N):
		from functools import reduce
		M = 0
		while N > 9:
			A = reduce(lambda x, y: int(x) + int(y), list(str(N)))
			M = reduce(lambda x, y: int(x) * int(y), list(str(N)))
			N = A
		return M


class Solution:

	def repeatedSumMul(self, n):
		while n >= 10:
			q = n
			q = str(q)
			s = 0
			for i in q:
				s += int(i)
			n = s
		p = 1
		for i in q:
			p = p * int(i)
		return p


class Solution:

	def sumdig(self, n):
		s = 0
		while n:
			s += n % 10
			n //= 10
		return s

	def repeatedSumMul(self, n):
		if 0 < n < 10:
			return n
		else:
			s = self.sumdig(n)
			while self.sumdig(s) > 9:
				s = self.sumdig(s)
			j = s % 10
			s //= 10
			j *= s % 10
			return j
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		ob = Solution()
		print(ob.repeatedSumMul(n))