Suppose you are living with two cats: A and B. There are $n$ napping spots where both cats usually sleep.

Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:

Cat A changes its napping place in order: $n, n - 1, n - 2, \dots, 3, 2, 1, n, n - 1, \dots$ In other words, at the first hour it's on the spot $n$ and then goes in decreasing order cyclically;

Cat B changes its napping place in order: $1, 2, 3, \dots, n - 1, n, 1, 2, \dots$ In other words, at the first hour it's on the spot $1$ and then goes in increasing order cyclically.

The cat B is much younger, so they have a strict hierarchy: A and B don't lie together. In other words, if both cats'd like to go in spot $x$ then the A takes this place and B moves to the next place in its order (if $x < n$ then to $x + 1$, but if $x = n$ then to $1$). Cat B follows his order, so it won't return to the skipped spot $x$ after A frees it, but will move to the spot $x + 2$ and so on.

Calculate, where cat B will be at hour $k$?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first and only line of each test case contains two integers $n$ and $k$ ($2 \le n \le 10^9$; $1 \le k \le 10^9$) — the number of spots and hour $k$.


-----Output-----

For each test case, print one integer — the index of the spot where cat B will sleep at hour $k$.


-----Examples-----

Input
7
2 1
2 2
3 1
3 2
3 3
5 5
69 1337
Output
1
2
1
3
2
2
65


-----Note-----

In the first and second test cases $n = 2$, so:

at the $1$-st hour, A is on spot $2$ and B is on $1$;

at the $2$-nd hour, A moves to spot $1$ and B — to $2$.

If $n = 3$ then:

at the $1$-st hour, A is on spot $3$ and B is on $1$;

at the $2$-nd hour, A moves to spot $2$; B'd like to move from $1$ to $2$, but this spot is occupied, so it moves to $3$;

at the $3$-rd hour, A moves to spot $1$; B also would like to move from $3$ to $1$, but this spot is occupied, so it moves to $2$.

In the sixth test case:

A's spots at each hour are $[5, 4, 3, 2, 1]$;

B's spots at each hour are $[1, 2, 4, 5, 2]$.

Source: codeforces | Difficulty: EASY
Tags: Number theory

Mathematics


Solutions:
import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
		continue
	ch = n // 2
	print((k - 1 + (k - 1) // ch) % n + 1)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		m = n // 2
		add = (k - 1) // m
		k += add
		if k > n:
			if k % n == 0:
				print(n)
			else:
				print(k % n)
		else:
			print(k)


t = int(input())
for _ in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if n % 2:
		t = int(2 * (k - 1) / (n - 1))
		print((k - 1 + t) % n + 1)
	else:
		print((k - 1) % n + 1)


import math
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split(' '))
	if n % 2 == 0:
		a = k % n
		if k % n == 0:
			a += n
		print(a)
	else:
		three = int(n / 2)
		a = k % n
		if k % n == 0:
			a += n
		z = math.ceil(k / three) - 1
		ans = a + z
		r = ans % n
		if r == 0:
			r += n
		print(r)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k % n != 0:
			print(k % n)
		else:
			print(n)
	else:
		a = n // 2
		b = k + (k - 1) // a
		if b % n != 0:
			print(b % n)
		else:
			print(n)


import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		x = k % n
		if x == 0:
			ans = n
		else:
			ans = x
	else:
		q = k - 1
		x = q // (n // 2)
		e = k + x
		r = e % n
		if r == 0:
			r = n
		ans = r
	sys.stdout.write(str(ans) + '\n')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		mid = n // 2
		ans = (k // mid + k) % n
		print(ans + 1)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		s = k // (n // 2)
		print((k + s) % n + 1)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192
from collections import Counter

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1 + n) % n + 1)
	else:
		k -= 1
		val = n // 2
		inc = k // val
		print((k + inc + n) % n + 1)


import sys
from sys import stdin, stdout
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def code(n, k):
	if n % 2 == 0:
		a = k % n
		if a == 0:
			return n
		else:
			return a
	else:
		s = n // 2
		sn = (k - 1) // s
		a = (k + sn) % n
		if a == 0:
			return n
		else:
			return a
t = int(input())
for i in range(t):
	(n, k) = get_ints()
	ans = code(n, k)
	print(ans)


for _ in range(int(input())):
	(n, t) = map(int, input().split())
	if n % 2 == 0:
		if t % n == 0:
			print(n)
		else:
			print(t % n)
	else:
		half = (n >> 1) + 1
		badha = int(t / half)
		if t < half:
			print(t)
		elif t >= half and t < n:
			print(t + 1)
		else:
			minus = t - half
			times = int(minus // (n >> 1))
			times += 1
			ans = -1
			if t % n == 0:
				ans = n
			else:
				ans = t % n
			ans = ans + times
			if ans % n == 0:
				print(n)
			else:
				print(ans % n)


for Mahou_Shoujo_Madoka_Magica in range(int(input())):
	Homura = [int(i) for i in input().split()]
	n = Homura[0]
	t = Homura[1]
	if n % 2 == 1:
		k = (n - 1) // 2
		cycles = t // k
		excess = t % k
		if excess != 0:
			move = (k + 1) * cycles + excess
		else:
			move = (k + 1) * cycles - 1
		print((move - 1) % n + 1)
	else:
		print((t - 1) % n + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = n
	B = 1
	if n % 2 == 0:
		ans = k % n
		if ans == 0:
			ans = n
	elif n % 2 == 1:
		if n == 3:
			a = k % n
			if a == 1:
				ans = 1
			elif a == 2:
				ans = 3
			elif a == 0:
				ans = 2
		else:
			a = (k - 1) // (n // 2)
			if k < n // 2 + 1:
				ans = k
			elif k - 1 == n // 2:
				ans = k + 1
			else:
				ans = k % n + a
		b = ans // n
		ans -= n * b
		if ans == 0:
			ans = n
	print(ans)


T = int(input())
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	k -= 1
	col = -1
	if n % 2 == 0:
		x = k % n
		if x == 0:
			print(1)
		else:
			print(1 + x)
	else:
		tim = n // 2
		coll = k // tim
		x = k % n
		col = coll % n
		if x == 0:
			print(1 + col)
		else:
			temp = 1 + x
			if col > n - temp:
				col -= n - temp
				print(col)
			else:
				print(temp + col)


t = int(input())
for case in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if n % 2 == 0:
		if k % n != 0:
			print(k % n)
		else:
			print(n)
	else:
		bruh = (k + (k - 1) // (n // 2)) % n
		if bruh == 0:
			print(n)
		else:
			print(bruh)


import sys
import bisect

def solve():

	def mymod(k, n):
		k %= n
		return n if k == 0 else k
	(n, k) = list(map(int, sys.stdin.readline().rstrip().split(' ')))
	if n % 2 == 0:
		res = mymod(k, n)
		print(res)
		return
	rotation = n // 2 * n
	rot_pos = mymod(k, rotation)
	group = (rot_pos - 1) // n
	start = group * 2 + 1
	group_pos = mymod(rot_pos, n)
	delta = group_pos > n // 2 - group
	delta += group_pos > n // 2 * 2 - group
	print(mymod(start + group_pos - 1 + delta, n))
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
	solve()


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		k -= 1
		if n % 2 == 0:
			print(k % n + 1)
		else:
			med = int(n * 0.5)
			print((k + int(k / med)) % n + 1)
main()


t = int(input())
for _ in range(t):
	(n, k) = [int(s) for s in input().split(' ')]
	if n % 2 == 0:
		k = k % n
		if k == 0:
			k = n
		print(k)
	elif n == 3:
		k = k % n
		if k == 0:
			k = n
		if k == 1:
			print(k)
		elif k == 2:
			print(3)
		else:
			print(2)
	else:
		tot = n // 2
		part = (k + n - 1) // n
		part = part % tot
		if part == 0:
			part = tot
		start = part * 2 - 1
		k = k % n
		if k == 0:
			k = n
		ex1 = tot + 1 - part + 1
		ex2 = n - part + 1
		if k >= ex2:
			ans = start + k - 1 + 2
		elif k >= ex1:
			ans = start + k
		else:
			ans = start + k - 1
		ans = ans % n
		if ans == 0:
			ans = n
		print(ans)


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		result = (k + (k - 1) // ((n - 1) // 2)) % n
	else:
		result = k % n
	if result == 0:
		result = n
	print(result)


def main():
	q = int(input())
	for t in range(q):
		(n, k) = map(int, input().split())
		k -= 1
		if k == 0:
			print(1)
		elif n % 2 == 1:
			h = n // 2
			step = h + 1
			all = k // h * step + k % h
			print(all % n + 1)
		else:
			print(k % n + 1)
main()


for case in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		p = (k - n // 2 - 1) // (n // 2)
		print(((k - 1) % n + p + 1) % n + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		k = k + (k - 1) // (n // 2)
	print(k % n if k % n != 0 else n)


from math import *
t = int(input())
for _ in range(t):
	(spots, k) = map(int, input().split())
	if spots % 2 == 1:
		thing = spots // 2
		period = thing * spots
		block = ceil(k / thing)
		if block % 2 == 1:
			start = block // 2 + 1
		else:
			maxx = spots // 2 + 1
			start = maxx + block // 2
		if k % thing != 0:
			ans = start + k % thing - 1
		else:
			ans = start + thing - 1
		ans = ans % spots
		if ans == 0:
			ans = spots
	else:
		thing = k % spots
		if thing == 0:
			ans = spots
		else:
			ans = thing
	print(ans)


def getAns(n, k):
	if n % 2 == 1:
		skippedCycLen = (n + 1) // 2
		nSkipped = (k - 1) // (skippedCycLen - 1)
		b = k + nSkipped
		ans = b % n
		if ans == 0:
			ans = n
	else:
		ans = k % n
		if ans == 0:
			ans = n
	return ans

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, k) = readIntArr()
		allans.append(getAns(n, k))
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


import math
from collections import defaultdict
DEBUG = True

def log(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)

def rint():
	return int(input())

def rlist(f=int):
	return list(map(f, input().split()))

def rstr():
	return input()

class Solution:

	def __init__(self):
		pass

	def run(self):
		(n, k) = rlist()
		if n % 2 == 0:
			return (k - 1) % n + 1
		freq = n // 2
		collisions = (k - 1) // freq
		return (k - 1 + collisions) % n + 1
t = int(input())
s = Solution()
for i in range(t):
	print(s.run())


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
		continue
	y = (n - 1) // 2
	x = (k - 1) // y
	if (x + k) % n == 0:
		print(n)
	else:
		print((x + k) % n)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = n
	b = 1
	if n % 2 == 0:
		x = k % n
		if x == 0:
			print(n)
		else:
			print(x)
	else:
		mid = n // 2 + 1
		rem = k % (mid - 1)
		if rem == 0:
			rem = -1
		x = k // (mid - 1)
		mid *= x
		mid += rem
		ans = mid % n
		if ans == 0:
			ans = n
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	K -= 1
	if N % 2 == 0:
		print(K % N + 1)
	else:
		S = N // 2
		rounds = K // S
		print((rounds * (S - 1) + 2 * rounds + K % S) % N + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	k = k - 1
	f = n // 2
	print((k + n % 2 * (k // f)) % n + 1)


import sys
import math
inf = float('inf')

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k = k - 1
	if n % 2 != 0:
		d = n // 2
		a = k // d
		print((k + a) % n + 1)
	else:
		print(k % n + 1)


import math

def solve(n, k):
	if n % 2 == 0:
		k = k % n
		if k == 0:
			return n
		return k
	else:
		m = math.ceil(n / 2)
		d = math.floor(n / 2)
		if k < m:
			return k
		elif k == m:
			return (m + 1) % (n + 1)
		else:
			target = (k - m) // d + 1
			res = k + target
			res = res % n
			if res == 0:
				return n
			return res
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	k = k - 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		mid = n // 2
		ans = (k // mid + k) % n
		print(ans + 1)
	t -= 1


from sys import stdin as stin, stdout as stout, setrecursionlimit as srl
from collections import defaultdict as dd, Counter, deque as dq
import math

def get_ints():
	return map(int, stin.readline().split())

def get_list():
	return list(map(int, stin.readline().split()))

def get_int():
	return int(stin.readline())

def get_str():
	return stin.readline()
for t in range(get_int()):
	(n, k) = get_ints()
	if n % 2 == 0:
		k = k - 1
		ans = k % n
		print(ans + 1)
	else:
		a = n
		b = 1
		if k <= n // 2 + 1:
			if k <= n // 2:
				print(k)
			else:
				print(k + 1)
		else:
			s = n // 2
			c = k - (s + 1)
			r = c % s
			q = c // s
			if r == 0:
				print((k % n + q) % n + 1)
			else:
				print((k % n + q) % n + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n % 2 == 0:
		time = k % n
		ans = time
		if time == 0:
			print(n)
			ans = n
		else:
			print(time)
	else:
		tt = 0
		no = (k - 1) // (n // 2)
		if n != 3:
			tt = (no + k) % n
		else:
			tt = (2 * k - 1) % n
		ans = tt
		if tt == 0:
			print(n)
			ans = n
		else:
			print(tt)


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	ans = k - 1
	if n % 2:
		ans += (k - 1) // (n // 2)
	ans %= n
	return ans + 1
for _ in range(int(input())):
	print(solve())


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	k -= 1
	if k == 0:
		print(1)
		continue
	if n % 2 == 0:
		print(k % n + 1)
	else:
		print((k + k // (n // 2)) % n + 1)


def calc():
	[n, k] = list(map(int, input().split(' ')))
	if n % 2 == 0:
		ans = (k - 1) % n + 1
		print(ans)
	else:
		skips = (k - 1) // (n // 2)
		ans = (k - 1 + skips) % n + 1
		print(ans)
t = int(input())
for i in range(t):
	calc()


T = int(input())
for test_case in range(T):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		print((k - 1 + (k - 1) // (n // 2)) % n + 1)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(k % n if k % n != 0 else n)
	else:
		tmp = n // 2
		pl = (k - 1) // tmp
		print((k + pl) % n if (k + pl) % n != 0 else n)


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		t = n // 2
		i = (k - 1) % (n * t)
		print((i + i // t) % n + 1)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		x = k % n
		if x == 0:
			x = n
		print(x)
	else:
		a = n // 2
		b = (k - 1) // a
		y = (k + b) % n
		if not y:
			y = n
		print(y)


t = int(input())
for __ in range(t):
	(n, k) = [int(e) for e in input().split()]
	k -= 1
	print((k + n % 2 * k // (n // 2)) % n + 1)


import math
for t in range(int(input())):
	out = 0
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		out = k % n
	elif k < n // 2 + 1:
		out = k
	else:
		out = (k + 1 + (k - n // 2 - 1) // (n // 2)) % n
	if out == 0:
		print(n)
	else:
		print(out)


def solve():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		sz = n // 2
		block = n * sz
		k = (k - 1) % block
		k = k // sz + k
		print(k % n + 1)
for _ in range(int(input())):
	solve()


inn = lambda : int(input())
inm = lambda : map(int, input().split())
ins = lambda : str(input())
ina = lambda : list(map(int, input().split()))

def solve():
	(n, k) = inm()
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
		return
	k %= n * (n // 2)
	idx = k // n
	k -= n * idx
	if k < n // 2 - idx:
		print(2 * idx + 1 + k)
	elif k == n // 2 - idx:
		print(2 * idx + 1 + k + 1)
	elif k > n // 2 - idx and k < n - 1 - idx:
		odd = (2 * idx + 1 + k) % n + 1
		print(odd)
	elif k >= n - 1 - idx:
		odd = (2 * idx + 1 + k) % n + 2
		print(odd)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict
import math
t = I()
for _ in range(t):
	(a, b) = lint()
	if a % 2 == 0:
		print(b - (b - 1) // a * a)
	else:
		t = (a - 1) // 2
		ans = a + 1 - b + b // a * a + (b - 1) % t * 2 + 1
		if ans > a:
			ans = ans - (ans - 1) // a * a
		print(ans)


t = int(input())
import math
while t > 0:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		half = n // 2
		extra_move = k // half
		print((k + extra_move) % n + 1)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd, log
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		diff = n // 2
		if k <= n // 2:
			print(k)
		elif k >= n // 2 + 1 and k < n:
			print(k + 1)
		else:
			possible_diff = (k - (n // 2 + 1)) // diff
			print((k + possible_diff) % n + 1)


from math import sqrt
import operator
import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(n, k):
	k -= 1
	res = (k + n % 2 * (k // (n // 2))) % n + 1
	return res

def main():
	cnt = read_one_int()
	for _ in range(cnt):
		(n, k) = read_list_of_ints()
		res = check_seq(n, k)
		print(res)
main()


import sys

def int_inp():
	return int(sys.stdin.readline())
t = int_inp()
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	if n % 2 == 0:
		x = k % n
	else:
		r = (k - 1) // (n // 2)
		x = (k + r) % n
	if x == 0:
		x += n
	print(x)


def solve(n, k):
	if k % n == 0:
		print(n)
	else:
		print(k % n)
for pratyush in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2:
		x = n // 2
		y = (k - 1) // x
		k += y
	solve(n, k)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def function(arr, size, dp):
	if size == 1 or size == 0:
		return 1
	key = ''.join(map(str, arr[:size]))
	if dp[key]:
		return dp[key]
	output = function(arr, size - 1, dp)
	key = ''.join(map(str, arr[:size - 1]))
	dp[key] = output
	if arr[size - 2] * 10 + arr[size - 1] <= 26:
		output += function(arr, size - 2, dp)
		key = ''.join(map(str, arr[:size - 2]))
		dp[key] = output
	return output

def main():
	for _ in range(ii()):
		(n, k) = mi()
		if n % 2 == 0:
			print(n if k % n == 0 else k % n)
		else:
			d = n // 2
			a = d + 1
			if k < a:
				print(k)
			else:
				m = (k - a) // d + 1
				print(n if (k + m) % n == 0 else (k + m) % n)
main()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
		continue
	else:
		if (k - 1) % (n - 1) + 1 > n // 2:
			ans = (k - 1) % (n - 1) + 1 + 1 + (k - 1) // (n - 1)
		else:
			ans = (k - 1) % (n - 1) + 1 + k // (n - 1)
		print((ans - 1) % n + 1)


def solve(n, k):
	if n % 2 == 0:
		x = k % n
		if x == 0:
			return n
		else:
			return x
	y = n // 2
	if k % y == 0:
		rm = (k - 1) // y
	else:
		rm = k // y
	x = (k % n + rm) % n
	if x == 0:
		pos = n
	else:
		pos = x
	return pos
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	print(solve(n, k))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		t = (k - 1) // (n // 2)
		print((t * (n // 2 + 1) + (k - 1) % (n // 2)) % n + 1)


from math import ceil, floor, log
import sys
from heapq import heappush, heappop
from collections import Counter, defaultdict, deque
input = lambda : sys.stdin.readline().strip()
c = lambda x: 10 ** 9 if x == '?' else int(x)

class node:

	def __init__(self, x, y):
		self.a = [x, y]

	def __lt__(self, b):
		return b.a[0] < self.a[0]

	def __repr__(self):
		return str(self.a[0]) + ' ' + str(self.a[1])

def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		print((k - 1 + ((k - 1) // (n // 2) if n % 2 == 1 else 0)) % n + 1)
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		x = (n + 1) // 2
		re = (k - 1) // (n // 2) + 1
		re -= 1
		ex = 1 + re * x
		ex = ex % n
		if ex == 0:
			ex = n
		tt = (k - 1) % (n // 2)
		ex += tt
		ex = ex % n
		if ex == 0:
			ex = n
		print(ex)


def solve(n, k):
	k -= 1
	if n % 2 == 0:
		return k % n + 1
	c = n // 2
	k2 = k // c * (c + 1) + k % c
	return k2 % n + 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
for j in range(t):
	nums = input().split()
	n = int(nums[0])
	k = int(nums[1])
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		r = k % ((n - 1) / 2)
		if r == 0:
			r = (n - 1) / 2
		place = 2 * r - k
		if place % n == 0:
			print(n)
		else:
			print(int(place % n))


t = int(input())
while t:
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		a = 0
		if k % n != 0:
			a = n + 1 - k % n
		else:
			a = 1
		clash = n // 2
		if (k - 1) % clash == 0:
			if a == n:
				print(1)
			else:
				print(a + 1)
		else:
			diff = (k - 1) % clash
			temp = 0
			if a == n:
				temp = 1
			else:
				temp = a + 1
			x = temp + 2 * diff
			if x > n:
				if x % n == 0:
					x = n
				else:
					x = x % n
			print(x)
	t -= 1


for t in range(int(input())):
	(n, k) = map(int, input().split())
	k -= 1
	a = n // 2
	g = k // a
	e = k + g
	print([k % n + 1, e % n + 1][n % 2])


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	elif (k + ceil(k / (n // 2)) - 1) % n == 0:
		print(n)
	else:
		print((k + ceil(k / (n // 2)) - 1) % n)


import sys, math
from collections import defaultdict
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n & 1:
		shift = math.ceil(k / (n // 2) - 1)
		ans = (k + shift) % n
	else:
		ans = k % n
	if ans == 0:
		ans = n
	print(ans)


import sys
import math
import bisect
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for T in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		mod = k % n
		if mod == 0:
			print(n)
		else:
			print(mod)
	elif k <= n // 2:
		print(k)
	else:
		X = n // 2
		shift = k // X
		if k // X == k / X:
			shift -= 1
		k += shift
		if k % n != 0:
			print(k % n)
		else:
			print(n)


q = int(input())
for queries in range(0, q):
	(n, k) = map(int, input().split())
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		print((k % n + k // (n // 2)) % n + 1)


trails = int(input())
answer_list = []
for x in range(trails):
	numbers = input().split(' ')
	n = int(numbers[0])
	k = int(numbers[1])
	if n % 2 == 0:
		answer = (k - 1) % n + 1
		answer_list.append(answer)
	else:
		diff = k - 1
		flored = diff // ((n - 1) / 2)
		answer = int((diff + flored) % n + 1)
		answer_list.append(answer)
for g in answer_list:
	print(g)


import math
t = int(input())
for t in range(t):
	(p, q) = map(int, input().split())
	if p % 2 != 0:
		q1 = p // 2
		q1 = q // q1
		if q % (p // 2) == 0:
			q1 = q1 - 1 + q % p
			q1 = q1 % p
			if q1 != 0:
				print(q1)
			else:
				print(p)
		else:
			q = q % p
			q1 = (q1 + q) % p
			if q1 != 0:
				print(q1)
			else:
				print(p)
	elif q % p == 0:
		print(p)
	else:
		print(q % p)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		pos = k % n
		print(pos if pos != 0 else n)
	else:
		skips = n // 2
		nskips = k // skips if k % skips != 0 else k // skips - 1
		pos = (k + nskips) % n
		print(pos if pos != 0 else n)


import sys
from math import gcd

def debug(*args):
	print(*args, file=sys.stderr)

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return map(int, sys.stdin.readline().strip().split())

def read_str_split():
	return list(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def Main():
	t = read_int()
	for _ in range(t):
		(n, k) = read_ints()
		if n % 2 == 0:
			if k % n == 0:
				print(n)
			else:
				print(k % n)
		else:
			x = n // 2 + 1
			dist = x - 1
			y = dist * n // gcd(dist, n)
			z = k % y
			ans = (z + (z - 1) // dist) % n
			if ans == 0:
				print(n)
			else:
				print(ans)
Main()


import sys
import math

def isPrime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def pa(a):
	s = ''
	for i in a:
		s += str(i) + ' '
	print(s)

def y():
	print('YES')

def n():
	print('x')
t = int(input().strip())
for a0 in range(t):
	l = [int(i) for i in input().split()]
	n = l[0]
	k = l[1]
	j = k
	c = 0
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		c = 1
		q1 = (n + 1) // 2
		if k < q1:
			print(k % n)
		else:
			c = q1 - 1
			q3 = k % n
			q2 = q1 - 1
			if q3 == 0:
				q3 = n
			q4 = k % q2
			x = 0
			if q4 == 0:
				x = k // q2 - 1
			else:
				x = k // q2
			q6 = x % n
			if q4 > n:
				pass
			if q6 == 0:
				print(q3)
			elif q3 + q6 > n:
				print(-n + q3 + q6)
			else:
				y = q6 + q3
				print(y)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = k % n
		if ans == 0:
			ans = n
		print(ans)
	else:
		half = int(n / 2)
		temp = int((k - 1) / half)
		ans = (k + temp) % n
		if ans == 0:
			ans = n
		print(ans)


test_cases = int(input())
res = []
for test in range(test_cases):
	st = input()
	ls = st.split()
	n = int(ls[0])
	k = int(ls[1])
	if n % 2 == 0:
		if k % n == 0:
			res.append(n)
		else:
			res.append(k % n)
	else:
		k1 = k - 1
		div = n // 2
		quo = k1 // div
		rem = k1 % div
		po1 = quo * div + 1
		v1 = 0
		if po1 % n == 0:
			v1 = 1
		else:
			v1 = n - po1 % n + 1
		if (v1 + rem + 1) % n == 0:
			res.append(n)
		else:
			res.append((v1 + rem + 1) % n)
for value in res:
	print(value)


def solve():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		k -= 1
		print(1 + k % n)
	else:
		k -= 1
		aloc = n - k % n
		dist = n - 2 - 2 * (k % (n >> 1))
		if aloc - dist - 1 > 0:
			print(aloc - dist - 1)
		else:
			print(n - (dist - aloc + 1))
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(n, k) = (int(x) for x in input().split(' '))
	if n % 2 == 0:
		ans = k % n
		if ans > 0:
			print(ans)
		else:
			print(n)
	else:
		p = n // 2
		cnt = (k - 1) // p
		ans = (k + cnt) % n
		if ans > 0:
			print(ans)
		else:
			print(n)


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	k -= 1
	print((k + n % 2 * k // (n // 2)) % n + 1)


from collections import defaultdict

def get_ans(n, k):
	if n % 2 == 0:
		if k % n == 0:
			return n
		else:
			return k % n
	k = k - 1
	temp = (n - 1) // 2
	ans = (1 + k + k // temp) % n
	if ans == 0:
		ans = n
	return ans
t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	print(get_ans(n, k))


from sys import stdin, stdout

def solve(tc):
	(n, k) = map(int, stdin.readline().split())
	if n & 1 == 0:
		if n >= k:
			print(k)
		else:
			k -= 1
			print(k % n + 1)
	elif n > k:
		if n // 2 >= k:
			print(k)
		else:
			print(k + 1)
	else:
		moved = n // 2 + 1
		k -= moved
		d = k // (n // 2)
		r = k % (n // 2)
		moved += (n // 2 + 1) * d + r
		print(moved % n + 1)
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


from math import *
import threading
import sys
mod = 10 ** 9
inf = 10 ** 6
yes = 'YES'
no = 'NO'

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d

def power_of_n(x, n):
	cnt = 0
	while x % n == 0:
		cnt += 1
		x //= n
	return cnt
import itertools
sys.setrecursionlimit(300000)
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	if n & 1:
		k = k + (k - 1) // (n // 2)
	check = k % n
	if check:
		print(check)
	else:
		print(n)


t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(1 + (k - 1) % n)
	else:
		freq = (n + 1) // 2 - 1
		b = 1 + (k + (k - 1) // freq - 1) % n
		print(b)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = lambda x: x % (10 ** 9 + 7)

def d(a):
	d = {}
	for i in a:
		if i not in d:
			d[i] = 0
		d[i] += 1
	return d
from math import ceil
for _ in range(rn()):
	(n, k) = rns()
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		ans = 0
		if k % n == 0:
			ans = n
		else:
			ans = k % n
		if k >= ceil(n / 2):
			a = ceil(n / 2)
			b = n // 2
			k -= a
			ans += 1
			ans += k // b
		if ans % n == 0:
			print(n)
		else:
			print(ans % n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		c = k - (n // 2 + 1)
		if c < 0:
			print(k % n)
		elif c == 0:
			print(k + 1)
		else:
			c = c // (n // 2) + 1
			c = (c % n + k % n) % n
			if c == 0:
				print(n)
			else:
				print(c)
	else:
		x = k % n
		if x == 0:
			print(n)
		else:
			print(x)


from sys import stdin as si, stdout as so
for _ in range(int(si.readline())):
	(n, k) = map(int, si.readline().split())
	if n % 2 == 0:
		so.write(str(1 + (k - 1) % n) + '\n')
	else:
		m = n // 2
		p = (k - 1) // m
		q = (k + p) % n
		if q == 0:
			so.write(str(n) + '\n')
		else:
			so.write(str(q) + '\n')


import math
import sys
import os.path
if os.path.exists('input_file.txt'):
	sys.stdin = open('input_file.txt', 'r')
	sys.stdout = open('output_file.txt', 'w')
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		anss = k % n
		if anss == 0:
			print(n)
		else:
			print(k % n)
	else:
		st = n // 2
		no = math.ceil(k / st) - 1
		no %= n
		ans = k % n
		ans += no
		ans %= n
		if ans == 0:
			print(n)
		else:
			print(ans)


from sys import stdin

def main():
	cases = int(stdin.readline().strip())
	while cases:
		(n, k) = map(int, stdin.readline().split())
		if n % 2 != 0:
			k = k % (n * (n // 2))
			if k % (n * (n // 2)) == 0:
				k = n * (n // 2)
			if k <= n // 2:
				print(k)
			else:
				aux = k - (n // 2 + 1)
				if k % n == 0:
					p = n
				else:
					p = k % n
				res = (p + aux // (n // 2) + 1) % n
				if res != 0:
					print(res)
				else:
					print(n)
		elif k % n != 0:
			print(k % n)
		else:
			print(n)
		cases -= 1
main()


import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def flush():
	return sys.stdout.flush()

def nicf():
	return int(sys.stdin.readline())

def nscf():
	return map(int, sys.stdin.readline().split())

def nacf():
	return list(map(int, sys.stdin.readline().split()))

def na1cf():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def solve():
	(n, k) = ns()
	k -= 1
	if n % 2 == 0:
		res = k % n
		res += 1
	else:
		l = n // 2
		res = k // l + k
		res %= n
		res += 1
	print(res)

def main():
	t = ni()
	for ti in range(t):
		solve()
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		t = (n - 1) // 2
		if k % n:
			q = k // n
		else:
			q = k // n - 1
		q = q % t
		s = 1
		if q != 0:
			s = 1 + q * 2
		if k % n:
			x = k % n
		else:
			x = n
		m = (s + n) // 2
		if s + x - 1 < m:
			print(s + x - 1)
		elif s + x <= n:
			print(s + x)
		else:
			m = (s + 1) // 2
			if (s + x) % n < m:
				print((s + x) % n)
			else:
				print((s + x) % n + 1)
	elif k % n:
		print(k % n)
	else:
		print(n)


t = int(input())
for t in range(t):
	values = input()
	values = values.split()
	s = int(values[0])
	h = int(values[1])
	h = h - 1
	if s % 2 == 0:
		pos = int(h % s)
		print(pos + 1)
	else:
		mid = int(s / 2)
		pos = int(int(int(h / mid) + h) % s)
		print(pos + 1)


import sys
pin = sys.stdin.readline
for T in range(int(pin())):
	(N, K) = map(int, pin().split())
	if N % 2 == 0:
		print((K - 1) % N + 1)
	else:
		M = N // 2
		L = (K - 1) // M + (K - 1)
		print(L % N + 1)


def inc_b(b):
	if b == n:
		b = 1
	else:
		b += 1
	return b

def dec_a(a):
	if a == 1:
		a = n
	else:
		a -= 1
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a_ini = n
	b_ini = 1
	if n % 2 == 0:
		b_ini = k % n
	else:
		temp = n // 2
		if k - 1 >= n // 2:
			b_ini = ((k - 1) // temp + k) % n
		else:
			b_ini = k % n
	if b_ini == 0:
		print(n)
	else:
		print(b_ini)


def solution(n, k):
	if n % 2 == 0:
		return k % n + 1
	else:
		mid = n // 2
		ans = (k // mid + k) % n
		return ans + 1
for i in range(int(input())):
	(a, k) = input().split()
	(a, k) = (int(a), int(k))
	print(solution(a, k - 1))


for _ in range(int(input())):
	(n, k) = [int(e) for e in input().split()]
	k -= 1
	print((k + n % 2 * k // (n // 2)) % n + 1)


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	a = n
	b = 1
	a = n - k % n + 1
	if a == n + 1:
		a = 1
	if n % 2 == 0:
		b = k % n
		if b == 0:
			b = n
	else:
		count = (k - 1) // (n // 2)
		b = (k + count) % n
		if b == 0:
			b = n
	print(b)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			ans = k % n
		else:
			m = n // 2
			p = (k - 1) // m
			q = (k - 1) % m
			place_a_p = (n - m * p) % n
			place_b_p = place_a_p + 1
			ans = (place_b_p + q) % n
		if ans == 0:
			ans = n
		print(ans)
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	b -= 1
	if a % 2 != 1:
		print(b % a + 1)
	else:
		print((b % a + b // (a // 2)) % a + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = n
	B = 1
	if n % 2 == 0:
		if k % n == 0:
			B = n
		else:
			B = k % n
	else:
		temp = (k - 1) // (n // 2) + k
		if temp % n == 0:
			B = n
		else:
			B = temp % n
	print(B)


from collections import Counter
t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(k % n if k % n != 0 else n)
	else:
		toAdd = (k - 1) // (n // 2)
		k2 = k + toAdd
		print(k2 % n if k2 % n != 0 else n)
	t -= 1


def func(n, k):
	f = n // 2
	k -= 1
	print((k + n % 2 * (k // f)) % n + 1)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	func(n, k)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	pos = -1
	if n % 2 == 1:
		rem1 = (k - 1) // (n // 2)
		k += rem1
	rem = k % n
	if rem == 0:
		pos = n
	else:
		pos = rem
	print(pos)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n & 1:
		k -= 1
		a = n // 2
		k += k // a
		k += 1
	if k % n == 0:
		print(n)
	else:
		print(k % n)


t = int(input())
for x in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	if n % 2 == 0:
		answer = (k - n) % n
	elif k >= n // 2 + 1:
		answer = (k + (k - 1) // (n // 2)) % n
	else:
		answer = k
	if answer == 0:
		print(n)
	else:
		print(answer)


from math import ceil
tests = int(input())
cache = {}
for (pos, _) in enumerate(range(tests), start=1):
	(n, k) = list(map(int, input().split()))
	k -= 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		d = n // 2
		r = k // n % d
		b = k % n
		pos_a = d + r
		start = 2 * r
		end = start + b
		if start <= pos_a <= end:
			end += 1
		if end >= n:
			if end - pos_a > d:
				end += 1
			end -= n
		print(end + 1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		x = b % a
		if x == 0:
			print(a)
		else:
			print(x)
	else:
		x = (b + (b - 1) // ((a - 1) // 2)) % a
		if x == 0:
			print(a)
		else:
			print(x)


import sys
input = sys.stdin.readline
import math
t = int(input())
for f in range(t):
	(n, k) = map(int, input().split())
	check = n // 2
	if n % 2:
		k += (k - 1) // check
	ans = k % n
	if ans == 0:
		ans = n
	print(ans)


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k == n or k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		l = 0
		k = k + int((k - 1) / int(n / 2))
		print(n if k % n == 0 else k % n)
	t = t - 1


def solve(n, k, ans):
	k -= 1
	pos = (1 + k) % n
	if pos == 0:
		pos = n
	if n % 2 == 0:
		ans.append(str(pos))
		return pos
	add = k // (n // 2)
	pos += add
	pos %= n
	if pos == 0:
		pos = n
	ans.append(str(pos))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		solve(n, k, ans)
	print('\n'.join(ans))
main()


import os, sys, time, collections, math, pprint, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)
ceil = lambda n, x: (n + x - 1) // x
(osi, oso) = ('/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
input = sys.stdin.readline

def maps():
	return map(int, input().split())
for __ in range(int(input())):
	(n, k) = maps()
	k -= 1
	collisions = k // (n // 2)
	print((k + n % 2 * collisions) % n + 1)


import math
t = int(input())
for i in range(t):
	nums = [int(x) for x in input().split()]
	n = nums[0]
	k = nums[1] - 1
	if n % 2 == 0:
		z = k % n
		z += 1
		print(z)
	else:
		m = 0 + n
		s = 0 + k
		m -= 1
		m /= 2
		x = math.floor(s / m)
		z = k % n
		z += x
		z = z % n
		z += 1
		print(z)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
MOD = 10 ** 9 + 7

def solve():
	(n, k) = map(int, input().split())
	k -= 1
	res = (k + n % 2 * (k // (n // 2))) % n + 1
	print(res)
t = int(input())
for _ in range(t):
	solve()


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
inf = 10 ** 16
md = 10 ** 9 + 7
for _ in range(II()):
	(n, k) = MI()
	if n & 1:
		d = n // 2
		if k < d:
			print(k)
		else:
			skip = (k - 1) // d
			ans = (k - 1 + skip) % n + 1
			print(ans)
	else:
		print((k - 1) % n + 1)


t = int(input())

def get_answer(n, k):
	if n % 2 == 0:
		return k % n if k % n > 0 else n
	else:
		loop = k % (n // 2 * n)
		if loop == 0:
			return n - 1
		add = (loop - 1) // (n // 2)
		step = (loop + add) % n
		return step if step > 0 else n
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	print(get_answer(n, k))


def conv(k):
	return (k - 1) % n + 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		print(conv((k - 1) // (n // 2) * (n // 2 + 1) + (k - 1) % (n // 2) + 1))
	else:
		print(conv(k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2:
		diff = n // 2
		if k - diff <= 0:
			print(k)
		else:
			ans = (k - 1) % n
			same = (k - 1) // (n // 2)
			print((ans + same) % n + 1)
	else:
		print((k - 1) % n + 1)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(n, k) = map(int, input().split())
		k = k - 1
		half = n // 2
		ans = (k + n % 2 * (k // half)) % n + 1
		print(ans)
main()


def solve():
	(n, k) = map(int, input().split())
	if n % 2:
		k -= 1
		place = 1
		temp = place + k // (n // 2) + k % n
		if temp % n == 0:
			print(n)
		else:
			print(temp % n)
	elif k % n == 0:
		print(n)
	else:
		print(k % n)
for _ in range(int(input())):
	solve()


import math
loops = int(input())
for x in range(loops):
	temp = input().split(' ')
	spots = int(temp[0])
	hours = int(temp[1])
	if hours == 1:
		print(1)
	elif spots % 2 == 0:
		loc = hours
		loc = loc % spots
		if loc == 0:
			loc = spots
		print(loc)
	else:
		loc = 1
		hours = hours - 1
		jumps = spots // 2
		loc = loc + hours + hours // jumps
		loc = loc % spots
		if loc == 0:
			loc = spots
		print(loc)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a ^ b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print((k - 1) % n + 1)
		continue
	else:
		excess = (k - 1) // (n // 2)
		excess %= n
		ans = (k - 1 + excess) % n + 1
		print(ans)


T = int(input())
r = 1
while r <= T:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = (k - 1) % n + 1
	else:
		part = (n - 1) // 2
		num = (k - 1) // part * (part + 1) + (k - 1) % part + 1
		ans = (num - 1) % n + 1
	print(ans)
	r += 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = k - 1
	if n % 2:
		ans += (k - 1) // (n // 2)
	print(ans % n + 1)


import sys
input = sys.stdin.readline

def solve():
	for i in range(int(input())):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(1 + (k - 1) % n)
		else:
			p = n // 2
			print(1 + (k - 1 + (k - 1) // p) % n)
solve()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	pos = 0
	k -= 1
	if n % 2 == 0:
		print((pos + k) % n + 1)
	else:
		shift = k // (n - 1)
		rem = k % (n - 1)
		pos = (pos + shift + rem) % n
		if rem >= n // 2:
			pos = (pos + 1) % n
		print(pos + 1)


def get_ans(ans, n):
	return ans if ans != 0 else n
tests = int(input())
for t in range(tests):
	(n, k) = list(map(int, input().split(' ')))
	if n % 2 == 0:
		ans = k % n
		print(get_ans(ans, n))
	else:
		first_err = n // 2 + 1
		freq = n // 2
		errs = (k - first_err) // freq + 1
		ans = (k + errs) % n
		print(get_ans(ans, n))


def catPosition(spots, k):
	if spots % 2 == 0:
		return k % spots + 1
	else:
		return (k // (spots // 2) + k) % spots + 1
tests = int(input())
for test in range(tests):
	temp = input().split()
	print(catPosition(int(temp[0]), int(temp[1]) - 1))


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = get_ints()
	if n & 1:
		x = (k + (k - 1) // ((n - 2) // 2 + 1)) % n
		if x == 0:
			print(n)
		else:
			print(x)
	elif k % n == 0:
		print(n)
	else:
		print(k % n)


T = int(input())
while T:
	T -= 1
	(n, k) = map(int, input().split())
	k -= 1
	if n & 1:
		t = n >> 1
		rnd = k // t
		pos = rnd * (t + 1) % n
		pos = (pos + k - t * rnd) % n + 1
	else:
		pos = k % n + 1
	print(pos)


def create_new_cycle(spots, hour):
	repetition = (spots - 1) / 2
	cycle_size = repetition * spots
	base_number = hour % cycle_size
	if base_number == 0:
		base_number = cycle_size
	if base_number % repetition == 0:
		sub = base_number
	else:
		sub = base_number + (repetition - base_number % repetition)
	sub = int(sub / repetition) - 1
	current_spot = (hour + sub) % spots
	if current_spot == 0:
		current_spot = spots
	print(current_spot)
t = int(input())
for i in range(t):
	numbers = list((int(num) for num in input().split(' ')))
	(spots, hour) = (numbers[0], numbers[1])
	if spots % 2 == 0:
		if hour % spots == 0:
			print(spots)
		else:
			print(hour % spots)
	else:
		create_new_cycle(spots, hour)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	k = k - 1
	if n % 2 == 0:
		print(1 + k % n)
	else:
		x = k // ((n - 1) // 2)
		print(1 + (k + x) % n)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
from math import inf, log, ceil

def f(a, b):
	c = 0
	if b == 1:
		return a
	while a > 0:
		a //= b
		c += 1
	return c
for _ in range(t()):
	(n, k) = ll()
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		m = (n + 1) // 2
		N = (k - 1) // (m - 1)
		X = n - (m - 1) * N % n + 1
		B = (X + (k - 1) % (m - 1)) % n
		if B == 0:
			print(n)
		else:
			print(B)


def read_input(filename: str=None) -> None:
	from sys import stdin
	stdin = open(filename) if filename else stdin
	cases = int(stdin.readline())
	while cases:
		cases = cases - 1
		(size, target) = tuple(map(int, stdin.readline().split()))
		if not size % 2:
			print((target - 1) % size + 1)
			continue
		(position, distance) = ((target - 1) % size + 1, size // 2)
		collisions = 0 if distance > target - 1 else (target - 1) // distance
		print((position - 1 + collisions) % size + 1)

def main():
	read_input()
main()


import math as m
i = int(input())
inp = []
for a in range(0, i):
	inp.append([int(x) for x in input().split()])
for [n, k] in inp:
	k = k - 1
	if n % 2 == 0:
		print(k % n + 1)
	else:
		s = (n - 1) // 2
		skips = k // s
		print((k + skips) % n + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k -= 1
	if n & 1 == 0:
		ans = k % n + 1
	else:
		perconflict = (n - 1) // 2
		conflicts = k // perconflict
		ans = (k + conflicts) % n + 1
	print(ans)


t = int(input())
res = []
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		a = k % n
		if a == 0:
			a = n
		res.append(a)
	else:
		if k == 1:
			b = 0
		else:
			b = (k - 1) // ((n - 1) / 2)
		a = (k + b) % n
		if a == 0:
			a = n
		res.append(int(a))
for i in res:
	print(i)


import math
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		d = n - (n // 2 + 1)
		a = n // 2 + 1
		num = math.floor((k - a) / d) + 1
		k = num + k
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	t -= 1


n = int(input())
ans = []
for i in range(n):
	(a, b) = (int(num) for num in input().split())
	if a % 2 == 0:
		if b % a == 0:
			ans.append(a)
			continue
		ans.append(b % a)
	else:
		if (a + 1) // 2 - 1 == 0:
			ans.append(1)
			continue
		time = b // ((a + 1) // 2 - 1)
		if b % ((a + 1) // 2 - 1) == 0:
			time -= 1
		b += time
		if b % a == 0:
			ans.append(a)
			continue
		else:
			ans.append(b % a)
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		p = (k - 1) % n + 1
	else:
		s = (k - 1) // (n // 2)
		p = (k - 1 + s) % n + 1
	print(p)


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		k -= 1
		print(k % n + 1)
	else:
		k -= 1
		print((k // (n // 2) + k) % n + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		if k % n == 0:
			print(n)
		else:
			print(k % n)
	else:
		m = n // 2
		poss = (k - 1) // m
		res = (k + poss) % n
		if res == 0:
			print(n)
		else:
			print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		rem = k % n
		if rem == 0:
			print(n)
		else:
			print(rem)
	else:
		a = n // 2 + 1
		d = n // 2
		num = (k - a) // d
		num += 1
		rem = k % n
		if rem == 0:
			ans = n
		else:
			ans = rem
		ans += num
		rem = ans % n
		if rem == 0:
			print(n)
		else:
			print(rem)


import sys
input = sys.stdin.readline

def solution(n, k):
	if n % 2 == 0:
		print((k - 1) % n + 1)
	else:
		jumps = (k - 1) // ((n - 1) // 2)
		print((k - 1 + jumps) % n + 1)
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	solution(n, k)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	n = int(temparr[0])
	k = int(temparr[1])
	if n & 1 == 0:
		ans = k % n
		if ans == 0:
			ans = n
		print(ans)
	else:
		half = n // 2 + 1
		halfrepeat = half - 1
		if k < half:
			print(k)
			continue
		elif k == half:
			print(k + 1)
			continue
		else:
			count = 1
			index = half
			kk = k - half
			count += kk // halfrepeat
			ans = (k + count) % n
			if ans == 0:
				ans = n
			print(ans)


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = rl()
	if (n + 1) % 2 != 0 or (n + 1) // 2 > k:
		ans = (k - 1) % n + 1
		print(ans if ans != 0 else n)
	else:
		jump = n // 2
		cnt = (k - 1) // jump
		idx = (2 * cnt + (k - 1 - cnt)) % n
		idx += 1
		print(idx if idx != 0 else n)


t = int(input())
for idx in range(t):
	nk = input()
	nks = list(map(int, nk.split(' ')))
	j = nks[0] // 2
	if nks[0] % 2 == 0:
		if nks[1] % nks[0] == 0:
			print(nks[0])
		else:
			print(nks[1] % nks[0])
	else:
		j = (nks[1] - 1) // j
		nks[1] += j
		if nks[1] % nks[0] == 0:
			print(nks[0])
		else:
			print(nks[1] % nks[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	pa = n
	pb = 1
	if n % 2 == 0:
		if k % n == 0:
			ans = n
		else:
			ans = k % n
	else:
		x = (n + 1) // 2
		s = k - x
		x = x - 1
		c = 1 + s // x
		y = k % n
		if y == 0:
			y = n
		ans = (y + c) % n
		if ans == 0:
			ans = n
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		v = (k - 1) % n + 1
	else:
		v = (k + (k - 1) // ((n - 1) // 2) - 1) % n + 1
	print(v)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		k = k % n
		if k == 0:
			print(n)
		else:
			print(k)
	else:
		x = 0
		mid = n // 2
		if k % (mid * n) == 0:
			y = mid * n
		else:
			y = k % (mid * n)
		if y % mid == 0:
			x = y // mid - 1
		else:
			x = y // mid
		if y % mid == 0:
			y = mid
		else:
			y = y % mid
		ans = y + x + x * mid
		if ans % n == 0:
			ans = n
		else:
			ans = ans % n
		print(ans)


import os
import sys
from io import BytesIO, IOBase
from math import gcd, inf, sqrt

def lcm(a, b):
	return a * b // gcd(a, b)

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def cheaker(a):
	j = 1
	p = False
	for i in a:
		if i != j:
			break
		j += 1
	q = len(a)
	for i in a[::-1]:
		if i != q:
			break
		q -= 1
	for i in range(j - 1, q):
		if a[i] == i + 1:
			return False
	return True

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def func(n, k):
	xx = k // (n // 2)
	yy = k % (n // 2)
	if not yy:
		xx -= 1
	po = k % n if k % n != 0 else n
	po += xx
	return po % n if po % n != 0 else n

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(k % n if k % n != 0 else n)
		else:
			print(func(n, k))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
for _ in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	if n % 2 == 0:
		print(k % n if k % n else n)
		continue
	period = n // 2
	conflict = (k - 1) // period
	print((k + conflict) % n if (k + conflict) % n else n)


answers = []

def solve(n, k):
	if n % 2 == 0:
		if k <= n:
			answers.append(k)
		elif k % n == 0:
			answers.append(n)
		else:
			answers.append(k % n)
		return
	else:
		first = n // 2 + 1
		repeat = n // 2
		if k < first:
			answers.append(k)
			return
		if (k - first) % repeat == 0:
			if k % n == 0:
				answers.append(2)
				return
			else:
				k = k % n
				req = n - k + 1
				if req + 1 <= n:
					answers.append(req + 1)
				else:
					answers.append(1)
		else:
			rem = (k - first) % repeat
			pos = k - rem
			temp = None
			if pos % n == 0:
				temp = 2
			else:
				pos = pos % n
				req = n - pos + 1
				if req + 1 <= n:
					temp = req + 1
				else:
					temp = 1
			if temp + rem <= n:
				answers.append(temp + rem)
			else:
				temp = (temp + rem) % n
				if temp == 0:
					answers.append(n)
				else:
					answers.append(temp)
T = int(input())
while T:
	(n, k) = [int(x) for x in input().split()]
	solve(n, k)
	T -= 1
for ans in answers:
	print(ans)


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	(n, h) = I()
	mid = (n + 1) // 2
	if n % 2 == 1 and h >= mid:
		h = h + (h - mid) // (mid - 1) + 1
	b = (h - 1) % n + 1
	print(b)


result = []
cases = int(input())
for i in range(cases):
	(n, k) = map(int, input().split(' '))
	if n % 2 == 0:
		result.append((k - 1) % n + 1)
	else:
		skip = (k - 1) // (n // 2)
		result.append((k + skip - 1) % n + 1)
for _ in result:
	print(_)