Count the given numbers on your fingers and find the correct finger on which the number ends.
	The first number starts from the thumb, second on the index finger, third on the middle finger, fourth on the ring finger and fifth on the little finger.
	Again six comes on the ring finger and so on.
	
Example 1:
Input:
N = 3
Output:
3
Explanation:
3 ends on the finger 3.
Example 2:
Input:
N = 6
Output:
4
Explanation:
6 ends on the finger 4.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function fingerCount() which takes an integer N as input parameter and returns the finger number on which this number ends.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^6

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

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

Solutions:
class Solution:

	def fingerCount(self, N):
		rem = N % 8
		if not rem:
			return 2
		if rem <= 5:
			return rem
		else:
			return 5 - rem % 5


class Solution:

	def fingerCount(self, N):
		if N % 8 == 1 or N % 8 == 9:
			return 1
		elif N % 8 == 2 or N % 8 == 8:
			return 2
		elif N % 8 == 3 or N % 8 == 7:
			return 3
		elif N % 8 == 4 or N % 8 == 6:
			return 4
		elif N % 8 == 5 or N % 8 == 13:
			return 5
		elif N % 8 == 0:
			return 2


class Solution:

	def fingerCount(self, N):
		r = N % 8
		if not r:
			return 2
		elif r <= 5:
			return r
		else:
			return 5 - r % 5


class Solution:

	def fingerCount(self, n):
		l = [1, 2, 3, 4, 5, 4, 3, 2]
		ans = n
		k = 0
		ans = ans // 8
		for i in range(0, 8):
			if 8 * ans + i == n:
				return l[i - 1]


class Solution:

	def fingerCount(self, N):
		r = N % 8
		if r == 0:
			return 2
		if r < 5:
			return r
		else:
			return 10 - r


class Solution:

	def fingerCount(self, N):
		n = N % 8
		if n < 6 and n > 0:
			return n
		elif n == 6:
			return 4
		elif n == 7:
			return 3
		elif n == 0:
			return 2


class Solution:

	def fingerCount(self, N):
		if N <= 5:
			return N
		elif N == 6:
			return 4
		elif N == 7:
			return 3
		elif N % 8 == 0:
			return 2
		else:
			x = N % 8
			if x > 5:
				return 5 - (x - 5)
			else:
				return x


class Solution:

	def fingerCount(self, n):
		if n >= 9:
			ans = (n - 9) % 8
			if ans % 8 == 0:
				return 1
			elif ans % 8 == 1 or ans % 8 == 7:
				return 2
			elif ans % 8 == 2 or ans % 8 == 6:
				return 3
			elif ans % 8 == 3 or ans % 8 == 5:
				return 4
			elif ans % 8 == 4:
				return 5
		else:
			ans = n - 1
			if ans % 8 == 0:
				return 1
			elif ans % 8 == 1 or ans % 8 == 7:
				return 2
			elif ans % 8 == 2 or ans % 8 == 6:
				return 3
			elif ans % 8 == 3 or ans % 8 == 5:
				return 4
			elif ans % 8 == 4:
				return 5


class Solution:
	import array as arr
	even = arr.array('i', [4, 3, 2, 1])
	odd = arr.array('i', [2, 3, 4, 5])

	def fingerCount(self, n):
		if n <= 5:
			fingpos = n
		else:
			q = (n - 5) // 4
			rem = (n - 5) % 4
			if q % 2 == 0:
				if rem == 0:
					fingpos = self.odd[3]
				else:
					fingpos = self.even[rem - 1]
			elif rem == 0:
				fingpos = self.even[3]
			else:
				fingpos = self.odd[rem - 1]
		return fingpos


class Solution:

	def fingerCount(self, N):
		if n <= 5:
			return n
		elif (n - 5) % 8 == 1 or (n - 5) % 8 == 7:
			return 4
		elif (n - 5) % 8 == 2 or (n - 5) % 8 == 6:
			return 3
		elif (n - 5) % 8 == 3 or (n - 5) % 8 == 5:
			return 2
		elif (n - 5) % 8 == 4:
			return 1
		else:
			return 5


class Solution:

	def fingerCount(self, N):
		c = 0
		d = N % 8
		if d == 1:
			c = 1
		if d == 0 or d == 2:
			c = 2
		if d == 3 or d == 7:
			c = 3
		if d == 4 or d == 6:
			c = 4
		if d == 5:
			c = 5
		return c


class Solution:

	def fingerCount(self, N):
		N = N % 16
		if N == 1 or N == 9:
			return 1
		if N in [0, 2, 8, 10]:
			return 2
		if N in [3, 7, 11, 15]:
			return 3
		if N in [5, 13]:
			return 5
		if N in [4, 6, 12, 14]:
			return 4


class Solution:

	def fingerCount(self, N):
		finger = N % 8
		if finger >= 6:
			finger = 10 - finger
		elif finger == 0:
			finger = 2
		return finger


class Solution:

	def fingerCount(self, N):
		if N <= 8:
			if N <= 5:
				return N
			else:
				return 10 - N
		else:
			if N % 8 == 1:
				return 1
			if N % 8 == 0 or N % 8 == 2:
				return 2
			if N % 8 == 3 or N % 8 == 7:
				return 3
			if N % 8 == 4 or N % 8 == 6:
				return 4
			if N % 8 == 5:
				return 5


class Solution:

	def fingerCount(self, N):
		no = N % 8
		if no == 0:
			return 2
		elif no < 5:
			return no
		else:
			return 10 - no


class Solution:

	def fingerCount(self, N):
		finger = {0: 2, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 4, 7: 3, 8: 2}
		N %= 8
		return finger[N]


class Solution:

	def fingerCount(self, N):
		if N % 8 == 5:
			return 5
		if N % 8 == 4 or N % 8 == 6:
			return 4
		if N % 8 == 3 or N % 8 == 7:
			return 3
		if N % 8 == 2 or N % 8 == 0:
			return 2
		if N % 8 == 1:
			return 1
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		n = int(input())
		ob = Solution()
		answer = ob.fingerCount(n)
		print(answer)


class Solution:

	def fingerCount(self, N):
		rem = N % 8
		if not rem:
			return 2
		if rem <= 5:
			return rem
		else:
			return 5 - rem % 5
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		n = int(input())
		ob = Solution()
		answer = ob.fingerCount(n)
		print(answer)


class Solution:

	def fingerCount(self, N):
		if N == 1:
			return 1
		l = [2, 3, 4, 5, 4, 3, 2, 1]
		b = (N - 2) % 8
		return l[b]
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		n = int(input())
		ob = Solution()
		answer = ob.fingerCount(n)
		print(answer)


class Solution:

	def fingerCount(self, N):
		r = N % 8
		if r == 0:
			return 2
		elif r < 5:
			return r
		else:
			return 10 - r
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		n = int(input())
		ob = Solution()
		answer = ob.fingerCount(n)
		print(answer)


class Solution:

	def fingerCount(self, N):
		round = 0
		temp = N
		if temp < 5:
			return temp
		while temp > 0:
			if round % 2 == 0 and temp >= 5:
				temp = temp - 5
				round += 1
			elif round % 2 == 1 and temp >= 3:
				temp = temp - 3
				round += 1
			else:
				break
		if temp == 0:
			if round % 2 == 1:
				return 5
			else:
				return 2
		elif round % 2 == 1:
			return 5 - temp
		else:
			return temp


class Solution:

	def fingerCount(self, N):
		rem = n % 8
		if rem == 0:
			return 2
		elif rem < 5:
			return rem
		else:
			return 10 - rem


class Solution:

	def fingerCount(self, N):
		rem = N % 8
		if rem == 0 or rem == 2:
			return 2
		elif rem <= 5:
			return rem
		else:
			return 5 - rem % 5


class Solution:

	def fingerCount(self, N):
		a = [4, 3, 2, 1]
		n = (N - 2) // 4
		if n % 2 == 0:
			return (N - 2) % 4 + 2
		else:
			return a[(N - 2) % 4]


class Solution:

	def fingerCount(self, N):
		l1 = [1, 9, 17, 25, 33, 41]
		l2 = [2, 8, 10, 16, 18, 24, 26, 32, 34]
		l3 = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43]
		l4 = [4, 6, 12, 14, 20, 22, 28, 30, 36]
		l5 = [5, 13, 21, 29, 37, 45, 53]
		if N % 8 == 1:
			return 1
		elif N % 8 == 0 or N % 8 == 2:
			return 2
		elif N % 8 == 3 or N % 8 == 7:
			return 3
		elif N % 8 == 4 or N % 8 == 6:
			return 4
		elif N % 8 == 5:
			return 5


class Solution:

	def fingerCount(self, N):
		m = N % 8
		if m >= 1 and m <= 5:
			return m
		elif m == 0:
			return 2
		elif m == 7:
			return 3
		elif m == 6:
			return 4


class Solution:

	def fingerCount(self, N):
		t = N % 8
		if t == 0:
			return 2
		if t == 7:
			return 3
		if t == 6:
			return 4
		return t


class Solution:

	def fingerCount(self, N):
		if N <= 5:
			return N
		res1 = (N - 1) / 8 + 1
		if res1 == float(int(res1)):
			return 1
		res1 = (N - 2) / 8 + 1
		res2 = (N - 8) / 8 + 1
		if res1 == float(int(res1)) or res2 == float(int(res2)):
			return 2
		res1 = (N - 3) / 4 + 1
		if res1 == float(int(res1)):
			return 3
		res1 = (N - 4) / 8 + 1
		res2 = (N - 6) / 8 + 1
		if res1 == float(int(res1)) or res2 == float(int(res2)):
			return 4
		res1 = (N - 5) / 8 + 1
		if res1 == float(int(res1)):
			return 5


class Solution:

	def fingerCount(self, N):
		temp = [1, 2, 3, 4, 5, 4, 3, 2]
		return temp[(N - 1) % 8]