M items are to be delivered in a circle of size N. Find the position where the M-th item will be delivered if we start from a given position K. Note that items are distributed at adjacent positions starting from K.
 
Example 1:
Input:
N = 5, M = 2, K = 1
Output:
2
Explanation:
If we start from 1st position, the
2nd item will land at the 2nd position.
Example 2:
Input:
N = 5, M = 8, K = 2
Output:
4
Explanation:
If we start from 2nd position, the
8th item will land at the 4th position.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function findPosition() which takes 3 Integers N,M and K as input and returns the answer.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N,M,K <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def findPosition(self, N , M , K):

        # code here

Solutions:
class Solution:

	def findPosition(self, N, M, K):
		nums_to_beg = N - (K - 1)
		if M <= nums_to_beg:
			return K - 1 + M
		else:
			answer = (M - nums_to_beg) % N
			if answer == 0:
				return N
			else:
				return answer


class Solution:

	def findPosition(self, N, M, K):
		a = (K + M - 1) % N
		if a == 0:
			return N
		else:
			return a


class Solution:

	def findPosition(self, N, M, K):
		if N == 1:
			return N
		ans = M % N + (K - 1)
		if ans == N:
			return ans
		else:
			return ans % N


class Solution:

	def findPosition(self, N, M, K):
		return (M + K - 2) % N + 1


class Solution:

	def findPosition(self, N, M, K):
		x = K + M - 1
		if x <= N:
			return x
		elif x % N == 0:
			return N
		else:
			return x % N


class Solution:

	def findPosition(self, N, M, K):
		if M <= N - K + 1:
			return M + K - 1
		M = M - (N - K + 1)
		if M % N == 0:
			return N
		else:
			return M % N
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(N, M, K) = map(int, input().split())
		ob = Solution()
		print(ob.findPosition(N, M, K))


class Solution:

	def findPosition(self, n, items, st_index):
		val = st_index + items % n - 1
		if val == 0:
			return n
		elif val > n:
			return val % n
		else:
			return val


class Solution:

	def findPosition(self, A, B, C):
		z = (C + B - 1) % A
		if z == 0:
			return A
		else:
			return z


class Solution:

	def findPosition(self, n, m, k):
		if m < n - k + 1:
			return m + k - 1
		else:
			m = m - (n - k + 1)
			if m % n == 0:
				return n
			else:
				return m % n


class Solution:

	def findPosition(self, N, M, K):
		sum = ((M - 1) % N + K - 1) % N
		return sum + 1


class Solution:

	def findPosition(self, N, M, K):
		if N == 1:
			return 1
		M = M % N
		ind = M + K - 1
		if ind > N:
			return ind - N
		return ind


class Solution:

	def findPosition(self, N, M, K):
		pos = (K + M - 1) % N
		if pos == 0:
			return N
		return pos


class Solution:

	def findPosition(self, N, M, K):
		c = K
		i = 2
		lp = M + K - 1
		if lp % N == 0:
			return N
		else:
			return lp % N


class Solution:

	def findPosition(self, members, items, st_pos):
		if members == 1:
			return 1
		elif (st_pos + items - 1) % members == 0:
			return members
		else:
			return (st_pos + items - 1) % members


class Solution:

	def findPosition(self, N, M, K):
		if K - 1 + M <= N:
			return K - 1 + M
		else:
			num = K - 1 + M
			while num > N:
				num -= N
			return num


class Solution:

	def findPosition(self, N, M, K):
		y = N - K + 1
		if M <= y:
			return M + K - 1
		x = M - y
		ans = x % N
		if ans == 0:
			return N
		return ans


class Solution:

	def findPosition(self, N, M, K):
		d = K - 1
		if M > N:
			pos = M % N
		else:
			pos = M
		pos += d
		if pos > N:
			pos = pos % N
		return pos


class Solution:

	def findPosition(self, N, M, K):
		m = M
		n = N
		k = K
		if m <= n - k + 1:
			return m + k - 1
		m = m - (n - k + 1)
		if m % n == 0:
			return n
		else:
			return m % n


class Solution:

	def findPosition(self, n, m, k):
		if n == 1:
			return 1
		m %= n
		ans = m + k - 1
		if ans == n:
			return ans
		return ans % n