Given an integer N, recursively sum digits of N until we get a single digit.  The process can be described below
If N < 10    
    digSum(N) = N
Else         
    digSum(N) = Sum(digSum(N))
 
Example 1:
Input:
N = 1234
Output:
1
Explanation:
The sum of 1+2+3+4 = 10, 
digSum(x) == 10 Hence 
ans will be 1+0 = 1
 
 
Example 2:
Input:
N = 9999
Output:
9
Explanation:
Check it yourself.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function repeatedSumOfDigits() which takes an integer N and returns the repeated sum of digits of N.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
 
Constraints: 
1 ≤ N ≤ 1000000

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3
class Solution:
    def repeatedSumOfDigits (self,N):
        # code here 

Solutions:
class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		while N >= 10:
			summ = 0
			while N > 0:
				rem = N % 10
				summ += rem
				N = N // 10
			N = summ
		return summ


class Solution:

	def repeatedSumOfDigits(self, N):
		s = str(N)
		while len(s) > 1:
			p = [int(x) for x in s]
			p = sum(p)
			s = str(p)
		return s


class Solution:

	def repeatedSumOfDigits(self, N):
		s = 0
		while N != 0 or s > 9:
			if N == 0:
				N = s
				s = 0
			a = N % 10
			s += a
			N = N // 10
		return s


class Solution:

	def repeatedSumOfDigits(self, N):
		if N % 9 == 0:
			return 9
		else:
			return N % 9


class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		elif N % 9 == 0:
			return '9'
		else:
			return N % 9


class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		else:
			sum = 0
			while N > 0:
				d = N % 10
				sum = sum + d
				N = N // 10
			return self.repeatedSumOfDigits(sum)


class Solution:

	def repeatedSumOfDigits(self, N):
		sum = 0
		while N > 0 or sum > 9:
			if N == 0:
				N = sum
				sum = 0
			sum += N % 10
			N //= 10
		return sum


class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		return self.repeatedSumOfDigits(self.repeatedSumOfDigits(N // 10) + N % 10)


class Solution:

	def repeatedSumOfDigits(self, n):
		sum = 0
		r = 0
		while n > 0 or sum > 9:
			if n == 0:
				n = sum
				sum = 0
			r = n % 10
			sum = sum + r
			n = n // 10
		return sum


class Solution:

	def repeatedSumOfDigits(self, N):
		n = list(str(N))
		while len(n) != 1 and n:
			n = list(str(sum([int(x) for x in n])))
		return n[0]


class Solution:

	def repeatedSumOfDigits(self, N: int) -> int:
		if N < 10:
			return N
		else:
			return self.repeatedSumOfDigits(self.sum_of_digits(N))

	@staticmethod
	def sum_of_digits(num: int) -> int:
		if not num:
			return 0
		else:
			return num % 10 + Solution.sum_of_digits(num // 10)


class Solution:

	def repeatedSumOfDigits(self, N):
		summ = 0
		while N != 0:
			digit = N % 10
			N = N // 10
			summ += digit
		if summ < 10:
			return summ
		else:
			return self.repeatedSumOfDigits(summ)


class Solution:
	ans = 0

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		else:
			s = list(str(N))
			for i in range(len(s)):
				s[i] = int(s[i])
			self.ans = sum(s)
			self.repeatedSumOfDigits(self.ans)
		return self.ans


class Solution:

	def repeatedSumOfDigits(self, n):
		while n:
			s = 0
			while n:
				s += n % 10
				n //= 10
			if s >= 1 and s <= 9:
				return s
			n = s


class Solution:

	def repeatedSumOfDigits(self, N):

		def h(x):
			if len(str(x)) <= 1:
				return x
			ans = 0
			for i in str(x):
				ans += int(i)
			return ans
		while len(str(N)) > 1:
			N = h(N)
		return N


class Solution:

	def digsum(self, N):
		sum = 0
		for i in str(N):
			sum += int(i)
		return sum

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		return self.repeatedSumOfDigits(self.digsum(N))


class Solution:

	def repeatedSumOfDigits(self, N):

		def p(n):
			x = n
			s = 0
			if n < 10:
				return n
			else:
				while x != 0:
					a = x % 10
					s = s + a
					x //= 10
			return p(s)
		a = p(N)
		return a


class Solution:

	def repeatedSumOfDigits(self, N):
		N_copy = N // 10
		if N_copy == 0:
			return N
		else:
			sm = 0
			while N > 0:
				sm += N % 10
				N = N // 10
			return self.repeatedSumOfDigits(sm)


class Solution:

	def repeatedSumOfDigits(self, N):
		if N <= 9:
			return N
		new = 0
		while N:
			digit = N % 10
			N = N // 10
			new += digit
		return self.repeatedSumOfDigits(new)


class Solution:

	def repeatedSumOfDigits(self, N):
		sums = 0

		def sumof(n):
			new = 0
			for i in str(n):
				new += int(i)
			if new < 10:
				return new
			else:
				return sumof(new)
		if N < 10:
			return N
		else:
			s = sumof(N)
			return s


class Solution:

	def repeatedSumOfDigits(self, N):
		return N % 9 or 9


class Solution:

	def repeatedSumOfDigits(self, N):
		s = 0
		for i in str(N):
			s += int(i)
		su = 0
		for j in str(s):
			su += int(j)
		temp_val = str(su)
		if len(temp_val) > 1:
			return self.repeatedSumOfDigits(su)
		else:
			return su


class Solution:

	def repeatedSumOfDigits(self, N):
		while len(str(N)) != 1:
			m = 0
			for i in str(N):
				m = m + int(i)
			N = m
		return N
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.repeatedSumOfDigits(N))


class Solution:

	def repeatedSumOfDigits(self, n):
		s = n % 9
		if s == 0:
			return 9
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.repeatedSumOfDigits(N))


class Solution:

	def repeatedSumOfDigits(self, N):
		while N >= 10:
			b = N
			s = 0
			while b != 0:
				s += b % 10
				b = b // 10
			N = s
		return N
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.repeatedSumOfDigits(N))


class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		else:
			digits = str(N)
			sum = 0
			for digit in digits:
				sum += int(digit)
			return self.repeatedSumOfDigits(sum)


class Solution:

	def repeatedSumOfDigits(self, N):

		def summ(N):
			if len(str(N)) == 1:
				return N
			else:
				N = str(N)
				a = [int(i) for i in N]
				N = sum(a)
				return summ(N)
		s = summ(N)
		return s


class Solution:

	def repeatedSumOfDigits(self, N):

		def sumofd(N):
			N = str(N)
			sum1 = 0
			for i in N:
				sum1 = sum1 + int(i)
			return sum1
		while len(str(N)) > 1:
			N = sumofd(N)
		return N


class Solution:

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		else:
			return 1 + (N - 1) % 9


class Solution:

	def repeatedSumOfDigits(self, N):
		s1 = 0
		while N > 0:
			s1 += N % 10
			N = N // 10
		if s1 < 10:
			return s1
		else:
			return self.repeatedSumOfDigits(s1)


class Solution:

	def digSum(self, N):
		c = 0
		d = 0
		while N != 0:
			d = N % 10
			c = c + d
			N = N // 10
		return c

	def repeatedSumOfDigits(self, N):
		w = self.digSum(N)
		if w <= 9:
			return w
		else:
			return self.repeatedSumOfDigits(w)


class Solution:

	def repeatedSumOfDigits(self, N):
		if len(str(N)) == 1:
			return N
		else:
			main = []
			main[:0] = str(N)
			main = list(map(int, main))
			N = sum(main)
			return self.repeatedSumOfDigits(N)


class Solution:

	def repeatedSumOfDigits(self, N):

		def sum11(N):
			if N < 10:
				return N
			sum1 = 0
			while N != 0:
				r = N % 10
				sum1 += r
				N = N // 10
			return sum11(sum1)
		return sum11(N)


class Solution:

	def repeatedSumOfDigits(self, N):
		result = 0
		resd = 0
		resd1 = 0
		while N > 0:
			m = N % 10
			N = N // 10
			result = result + m
		if result >= 10:
			while result > 0:
				resf = result % 10
				result = result // 10
				resd = resd + resf
		else:
			return result
		if resd >= 10:
			while resd > 0:
				resdf1 = resd % 10
				resd = resd // 10
				resd1 = resd1 + resdf1
			return resd1
		return resd


class Solution:

	def repeatedSumOfDigits(self, n):
		if n == 0:
			return 0
		elif n % 9 != 0:
			return n % 9
		else:
			return 9


class Solution:

	def sumdigit(self, x):
		sum = 0
		while x > 0:
			a = x % 10
			sum = sum + a
			x = x // 10
		if sum >= 10:
			return self.sumdigit(sum)
		return sum

	def repeatedSumOfDigits(self, N):
		if N < 10:
			return N
		else:
			return self.sumdigit(N)


class Solution:

	def repeatedSumOfDigits(self, n):
		if n % 9 == 0:
			return 9
		elif n < 10:
			return n
		else:
			c = 0
			while n > 0:
				c += n % 10
				n //= 10
			return self.repeatedSumOfDigits(c)


class Solution:

	def repeatedSumOfDigits(self, N):
		m = str(N)
		while len(m) != 1:
			sr = 0
			for i in m:
				sr += int(i)
			m = str(sr)
		return int(m)


class Solution:

	def repeatedSumOfDigits(self, N):
		if len(str(N)) >= 2:
			sum1 = 0
			while N != 0:
				rem = N % 10
				sum1 = sum1 + rem
				N = N // 10
			return Solution.repeatedSumOfDigits(self, sum1)
		else:
			return N

	def su(n):
		sum1 = 0