Given a non-negative integer N, repeatedly add all its digits until the result has only one digit.
Example 1:
Input:
N = 98
Output:
8
Explanation:
Sum of digit of N = 98  is 9 + 8 = 17
Sum of digit of 17 = 1 + 7 = 8
Since 8 is the single digit number hence it is the 
required answer.
Example 2:
Input:
N = 1
Output:
1
Explanation:
Since 1 is the single-digit number hence it is the 
required answer.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function singleDigit() which takes an integer N as an input parameter and return the single-digit you will get after repeatedly adding the digits of N.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{18}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def singleDigit(self, N):
    	#code here 

Solutions:
class Solution:

	def singleDigit(self, N):
		while True:
			if int(N / 10) > 0:
				N = self.sum_no(N)
			else:
				break
		return N

	def sum_no(self, n):
		total_no = 0
		while n > 0:
			total_no = total_no + n % 10
			n = int(n / 10)
		return total_no


class Solution:

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


class Solution:

	def singleDigit(self, N):
		s = str(N)
		while len(s) != 1:
			k = 0
			for i in s:
				k = k + int(i)
			s = str(k)
		return s


class Solution:

	def singleDigit(self, N):
		return (N - 1) % 9 + 1 if N > 0 else 0


class Solution:

	def singleDigit(self, N):
		su = 0
		while N > 0 or su > 9:
			if N == 0:
				N = su
				su = 0
			digits = N % 10
			su = su + digits
			N = N // 10
		return su


class Solution:

	def singleDigit(self, N):
		st = str(N)
		while len(st) != 1:
			ans = 0
			for i in st:
				ans = ans + int(i)
			st = str(ans)
		return ans


class Solution:

	def singleDigit(self, N):
		s = str(N)
		if len(s) < 2:
			return N
		else:
			while len(s) > 1:
				d = [int(x) for x in s]
				d = sum(d)
				s = str(d)
			return s


class Solution:

	def convert_to_digits(self, n):
		digits = [int(i) for i in str(n)]
		return digits

	def singleDigit(self, N):
		Sum = sum(self.convert_to_digits(N))
		str_sum = str(Sum)
		while len(str_sum) != 1:
			Sum = sum(self.convert_to_digits(Sum))
			str_sum = str(Sum)
		return Sum


class Solution:

	def singleDigit(self, N):
		sum = 0
		nextsum = 0
		while N != 0:
			temp = N % 10
			sum = sum + temp
			N = N // 10
		if sum >= 10:
			return self.singleDigit(sum)
		else:
			return sum


class Solution:

	def singleDigit(self, N):
		str_N = str(N)
		sum1 = 0
		if len(str_N) == 1:
			return N
		while len(str_N) != 1:
			for i in str_N:
				sum1 += int(i)
			str_N = str(sum1)
			sum1 = 0
		return int(str_N)


class Solution:

	def singleDigit(self, N):
		l = []
		while len(str(N)) > 1:
			x = str(N)
			for i in x:
				l.append(int(i))
			N = sum(l)
			l = []
		return N


class Solution:

	def singleDigit(self, N):
		while len(str(N)) > 1:
			a = list(map(int, str(N)))
			N = sum(a)
		return N


class Solution:

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


class Solution:

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


class Solution:

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


class Solution:

	def singleDigit(self, N):

		def numsum(n):
			sum = 0
			while n > 0:
				sum += n % 10
				n = n // 10
			return sum

		def continues(n):
			while n > 9:
				n = numsum(n)
			return n
		return continues(N)


class Solution:

	def singleDigit(self, N):
		S = 0
		for i in str(N):
			S += int(i)
		if S > 9:
			return self.singleDigit(S)
		else:
			return S


class Solution:

	def singleDigit(self, N):
		while len(str(N)) > 1:
			s = 0
			while N:
				r = N % 10
				s += r
				N = N // 10
			N = s
		return s


class Solution:

	def singleDigit(self, N):
		from functools import reduce
		while N > 9:
			N = reduce(lambda x, y: int(x) + int(y), list(str(N)))
		return N


class Solution:

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


class Solution:

	def singleDigit(self, N):
		N = str(N)
		sum = 0
		while sum >= 0:
			sum = 0
			for i in N:
				sum += int(i)
			if sum < 10:
				break
			else:
				N = str(sum)
		return sum


class Solution:

	def singleDigit(self, N):
		return 1 + (N - 1) % 9


class Solution:

	def singleDigit(self, N):
		n = str(N)
		sum = 0
		if len(n) == 1:
			return n
		else:
			for i in n:
				sum = sum + int(i)
		return Solution.singleDigit(self, sum)


class Solution:

	def singleDigit(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 singleDigit(self, N):
		while N > 9:
			N = sum(list(map(int, str(N))))
		return N


class Solution:

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


class Solution:

	def digitAdd(self, n):
		ans = 0
		while n != 0:
			digit = n % 10
			n = n // 10
			ans += digit
		N = ans
		return N

	def singleDigit(self, N):
		if N < 10:
			return N
		else:
			return self.singleDigit(self.digitAdd(N))


class Solution:

	def singleDigit(self, N):
		while N >= 10:
			res = 0
			while N != 0:
				res += N % 10
				N //= 10
			N = res
		return N


class Solution:

	def singleDigit(self, N):
		while N > 9:
			sm = 0
			while N:
				sm += N % 10
				N = N // 10
			N = sm
		return N


class Solution:

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

	def singleDigit(self, N):
		while len(str(N)) != 1:
			N = self.sumOfDigits(N)
		return N


class Solution:

	def singleDigit(self, N):
		sumdigit = 0
		while N != 0:
			sumdigit = sumdigit + N % 10
			N = N // 10
		if sumdigit // 10 == 0:
			return sumdigit
		else:
			return self.singleDigit(sumdigit)


class Solution:

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


class Solution:

	def singleDigit(self, N):
		while N > 9:
			total = 0
			while N > 0:
				num = N % 10
				total += num
				N = int(N / 10)
			N = total
		return N


class Solution:

	def singleDigit(self, N):
		Sum = 0
		while N > 0:
			Sum += N % 10
			N = N // 10
		if Sum // 10 == 0:
			return Sum
		return self.singleDigit(Sum)


class Solution:

	def singleDigit(self, N):

		def addition(N):
			val = 0
			while N != 0:
				val += N % 10
				N = N // 10
			return val
		while N > 9:
			N = addition(N)
		return N


class Solution:

	def singleDigit(self, N):
		if N < 10:
			return N
		else:
			sum = 0
			sum = self.singleDigit(N // 10 + N % 10)
			return sum
		return -1


class Solution:

	def singleDigit(self, n):
		s = 0
		while n != 0:
			s += n % 10
			n = n // 10
		if s < 10:
			return s
		else:
			n = s
			return self.singleDigit(n)


class Solution:

	def singleDigit(self, n):
		if n % 9 == 0:
			return 9
		else:
			return n % 9


class Solution:

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


class Solution:

	def singleDigit(self, N):
		st = str(N)
		if len(st) < 2:
			return N
		summ = 0
		while summ == 0 or len(st) > 1:
			summ = 0
			for e in st:
				summ = summ + int(e)
			st = str(summ)
			if summ == 0:
				return 0
			if len(st) < 2:
				return int(st)


class Solution:

	def singleDigit(self, N):
		n = int(N)
		sum = 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 singleDigit(self, N):

		def single(n):
			num = 0
			while n:
				n1 = n % 10
				num += n1
				n = n // 10
			return num
		while N // 10:
			N = single(N)
		return N


class Solution:

	def singleDigit(self, N):

		def helper(n):
			if n < 10:
				return n
			else:
				x = 0
				while n > 0:
					x += n % 10
					n = n // 10
				return helper(x)
		return helper(N)


class Solution:

	def singleDigit(self, N):
		for i in range(N):
			if N < 10:
				return N
			else:
				k = 0
				for j in str(N):
					k = k + int(j)
				N = k


class Solution:

	def singleDigit(self, N):
		return 1 + (N - 1) % 9
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


from collections import Counter

class Solution:

	def singleDigit(self, n):
		n = str(n)
		c = dict(Counter(n))
		ans = 0
		for i in c.items():
			ans += int(i[0]) * i[1]
		if ans % 9 == 0:
			return 9
		return ans % 9
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


class Solution:

	def singleDigit(self, N):
		sum1 = 0
		while sum1 > 9 or N > 0:
			if N == 0:
				N = sum1
				sum1 = 0
			sum1 += int(N % 10)
			N = N / 10
		return sum1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


class Solution:

	def singleDigit(self, N):
		while len(str(N)) != 1:
			N = sum([int(i) for i in str(N)])
		return N
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


class Solution:

	def singleDigit(self, N):
		while N >= 10:
			N = sum(list(map(lambda x: int(x), list(str(N)))))
		return N
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


def addition(N):
	if N < 10:
		return N
	else:
		sum = 0
		while N != 0:
			sum = sum + N % 10
			N = N // 10
		return addition(sum)

class Solution:

	def singleDigit(self, N):
		return addition(N)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


class Solution:

	def singleDigit(self, n):
		s = str(n)
		c = 0
		if len(s) == 1:
			c = int(s)
			return c
		else:
			for x in s:
				c += int(x)
		return self.singleDigit(c)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


def find_actony_code(S):
	if len(S) == 1:
		return S
	digit_sum = 0
	for char in S:
		digit_sum += int(char) % 10
	return find_actony_code(str(digit_sum))

class Solution:

	def singleDigit(self, N):
		ans = str(N)
		v = find_actony_code(ans)
		return int(v)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)


class Solution:

	def singleDigit(self, N):
		if N == 0:
			return 0
		elif N % 9 == 0:
			return 9
		else:
			return N % 9
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.singleDigit(N)
		print(ans)