Little Elephant was fond of inventing new games. After a lot of research, Little Elephant came to know that most of the animals in the forest were showing less interest to play the multi-player games. Little Elephant had started to invent single player games, and succeeded in inventing the new single player game named COIN FLIP.

In this game the player will use $N$ coins numbered from $1$ to $N$, and all the coins will be facing in "Same direction" (Either Head or Tail), which will be decided by the player before starting of the game.

The player needs to play $N$ rounds. In the $k$-th round the player will flip the face of the all coins whose number is less than or equal to $k$. That is, the face of coin $i$ will be reversed, from Head to Tail, or, from Tail to Head, for $i ≤ k$.

Elephant needs to guess the total number of coins showing a particular face after playing $N$ rounds. Elephant really becomes quite fond of this game COIN FLIP so Elephant plays $G$ times. Please help the Elephant to find out the answer.

------  Input: ------
The first line of input contains an integer $T$, denoting the number of test cases. Then $T$  test cases follow.

The first line of each test contains an integer $G$, denoting the number of games played by Elephant. Each of the following $G$ lines denotes a single game, and contains $3$ space-separated integers $I$, $N$, $Q$, where $I$ denotes the initial state of the coins, $N$ denotes the number of coins and rounds, and $Q$, which is either $1$, or $2$ as explained below.

Here $I=1$ means all coins are showing Head in the start of the game, and $I=2$ means all coins are showing Tail in the start of the game. $Q=1$ means Elephant needs to guess the total number of coins showing Head in the end of the game, and $Q=2$ means Elephant needs to guess the total number of coins showing Tail in the end of the game.

------  Output: ------
For each game, output one integer denoting the total number of coins showing the particular face in the end of the game.

------  Constraints: ------

$1 ≤ T ≤ 10$

$1 ≤ G ≤ 2000$

$1 ≤ N ≤ 10$

$1 ≤ I ≤ 2$

$1 ≤ Q ≤ 2$

----- Sample Input 1 ------ 
1
2
1 5 1
1 5 2
----- Sample Output 1 ------ 
2
3
----- explanation 1 ------ 
In the 1st game in Example,
$I=1$, so initial arrangement of coins are H H H H H,
and now Elephant will play 5 rounds and coin faces will be changed as follows<
After the 1st Round: T H H H H
After the 2nd Round: H T H H H
After the 3rd Round: T H T H H
After the 4th Round: H T H T H
After the 5th Round: T H T H T
Finally Q=1, so we need to find the total number of coins showing Head, which is 2

In the 2nd game in Example:
This is similar to the 1st game, except Elephant needs to find the total number of coins showing Tail.
So the Answer is $3$. (Please see the final state of the coins in the $1^{st}$ game)

Source: codechef | Difficulty: EASY
Tags: Complete search

Ad-hoc


Solutions:
t = int(input())
for it in range(t):
	g = int(input())
	for its in range(g):
		(i, n, q) = map(int, input().split())
		if i == q:
			print(n // 2)
		else:
			print(n // 2 + n % 2)


t = input()
t = int(t)
for p in range(t):
	c = input()
	c = int(c)
	for j in range(c):
		(i, n, q) = input().split()
		(i, n, q) = (int(i), int(n), int(q))
		sol = int(n / 2)
		if i == q:
			print(sol)
		else:
			print(n - sol)


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


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


import math
num = int(input())
for i in range(num):
	t = int(input())
	for x in range(t):
		(i, n, q) = map(int, input().split())
		if i == 1:
			if q == 1:
				print(n // 2)
			else:
				print(math.ceil(n / 2))
		elif q == 2:
			print(n // 2)
		else:
			print(math.ceil(n / 2))


T = int(input())
for _ in range(T):
	g = int(input())
	for _ in range(g):
		(i, n, q) = map(int, input().split())
		if i == q:
			print(n // 2)
		else:
			print(n - n // 2)


for _ in range(int(input())):
	for i in range(int(input())):
		(I, N, Q) = map(int, input().split())
		if N % 2 == 0:
			print(N // 2)
		elif I == 1:
			print(N // 2) if Q == 1 else print(N // 2 + 1)
		else:
			print(N // 2 + 1) if Q == 1 else print(N // 2)


for t in range(int(input())):
	g = int(input())
	for j in range(g):
		(i, n, q) = map(int, input().split(' '))
		if n % 2 == 0:
			print(n // 2)
		elif n == 1:
			if i == q:
				print(0)
			else:
				print(1)
		elif i == q:
			print(int(n // 2))
		else:
			print(int(n // 2) + 1)


for i in range(int(input())):
	n = int(input())
	for j in range(n):
		(L, N, Q) = map(int, input().split())
		if L == Q:
			print(N // 2)
		else:
			print((N + 1) // 2)


for i in range(int(input())):
	g = int(input())
	for j in range(g):
		(i, n, q) = list(map(int, input().split()))
		(switch, same, heads, tails) = (0, 0, 0, 0)
		switch = (n + 1) // 2
		same = n // 2
		if i == 1:
			heads = same
			tails = switch
		else:
			heads = switch
			tails = same
		if q == 1:
			print(heads)
		else:
			print(tails)


for i in range(int(input())):
	a = int(input())
	ans = 0
	for i in range(a):
		l = list(map(int, input().split()))
		if l[1] % 2 == 1:
			if l[0] == 1:
				if l[2] == 1:
					ans = l[1] // 2
				else:
					ans = (l[1] + 1) // 2
			elif l[2] == 1:
				ans = (l[1] + 1) // 2
			else:
				ans = l[1] // 2
		else:
			ans = l[1] // 2
		print(ans)


for i in range(int(input())):
	g = int(input())
	for i in range(g):
		(i, n, q) = map(int, input().split())
		l = ''
		if i == 1:
			if q == 1:
				print(int(n // 2))
			else:
				print(n - int(n // 2))
		elif q == 1:
			print(n - int(n // 2))
		else:
			print(int(n // 2))


t = int(input())
while t > 0:
	g = int(input())
	while g > 0:
		(n, i, q) = map(int, input().split())
		if i % 2 == 0:
			print(i // 2)
		else:
			print(i // 2 if n == q else i // 2 + 1)
		g -= 1
	t -= 1


t = int(input())
for _ in range(t):
	g = int(input())
	for i in range(g):
		(i, n, q) = map(int, input().split())
		a = n // 2
		if i == q:
			print(a)
		else:
			print(n - a)


t = int(input())
while t:
	t -= 1
	G = int(input())
	while G:
		G -= 1
		(I, N, Q) = map(int, input().split())
		if N % 2 == 0:
			print(N // 2)
		elif I == Q:
			print(N // 2)
		else:
			print(N // 2 + 1)


import math
T = int(input())
for _ in range(T):
	g = int(input())
	for i in range(g):
		(i, n, q) = map(int, input().split())
		noti = n // 2 if n % 2 == 0 else n // 2 + 1
		if n % 2 == 0:
			print(n // 2)
		elif i != q:
			print(noti)
		else:
			print(n - noti)


for turn in range(int(input())):
	for game in range(int(input())):
		(i, n, q) = map(int, input().split())
		if n % 2 == 0:
			print(int(n / 2))
		else:
			if i == 1:
				head = int(n / 2)
				tail = n - head
			else:
				tail = int(n / 2)
				head = n - tail
			print(head) if q == 1 else print(tail)


for _ in range(int(input())):
	times = int(input())
	for i in range(times):
		(initial, coins, find) = map(int, input().split())
		if coins % 2 == 0:
			print(coins // 2)
		elif initial == find:
			print(coins // 2)
		else:
			print((coins + 1) // 2)


for _ in range(int(input())):
	g = int(input())
	G = []
	for i in range(g):
		(i, n, q) = map(int, input().split())
		res = n // 2 + abs(i - q) * n % 2
		print(res)


t = int(input())
for i in range(t):
	g = int(input())
	for j in range(g):
		(I, N, Q) = list(map(int, input().split()))
		if N % 2 == 0:
			print(N // 2)
		elif I == 1 and Q == 1:
			print(N // 2)
		elif I == 1 and Q == 2:
			print(N - N // 2)
		elif I == 2 and Q == 1:
			print(N - N // 2)
		elif I == 2 and Q == 2:
			print(N // 2)


for _ in range(int(input())):
	g = int(input())
	for count in range(g):
		(i, n, q) = map(int, input().split())
		if i == 1:
			if n % 2 == 0:
				print(int(n / 2))
			elif q == 1:
				print(int(n / 2))
			else:
				print(int(n / 2) + 1)
		elif n % 2 == 0:
			print(int(n / 2))
		elif q == 2:
			print(int(n / 2))
		else:
			print(int(n / 2) + 1)


T = int(input())
for i in range(T):
	G = int(input())
	for i in range(G):
		(I, N, Q) = map(int, input().split())
		if N % 2 == 0:
			print(N // 2)
		elif Q == I:
			print(N // 2)
		else:
			print(N - N // 2)


T = int(input())
for t in range(0, T):
	G = int(input())
	for G in range(0, G):
		(I, N, Q) = map(int, input().split())
		odd_pos_sum = N // 2 + N % 2
		odd_neg_sum = N // 2
		evn_sum = N // 2
		if N % 2 == 0:
			print(evn_sum)
		elif N % 2 != 0 and Q == I:
			print(odd_neg_sum)
		elif N % 2 != 0 and Q != I:
			print(odd_pos_sum)
		elif Q == 2:
			print(A.count(-1))


for t in range(int(input())):
	for p in range(int(input())):
		(a, b, c) = map(int, input().split())
		if b % 2 == 0 or a == c:
			print(int(b / 2))
		else:
			print(int(b / 2) + 1)


for x in range(int(input())):
	for x in range(int(input())):
		(I, N, Q) = map(int, input().split())
		if I == Q:
			print(N // 2)
		else:
			print((N + 1) // 2)


t = int(input())
for i in range(t):
	G = int(input())
	for j in range(G):
		(I, N, Q) = map(int, input().split())
		if N % 2 == 0:
			count = N // 2
		else:
			count = N // 2 + 1
		if I == Q:
			print(N - count)
		else:
			print(count)


for _ in range(int(input())):
	g = int(input())
	for i in range(g):
		(i, n, q) = list(map(int, input().split()))
		if i == 1 and n % 2 != 0 and (q == 1) or (i == 2 and n % 2 != 0 and (q == 2)):
			print(n // 2)
		elif i == 1 and n % 2 != 0 and (q == 2) or (i == 2 and n % 2 != 0 and (q == 1)):
			print(n // 2 + 1)
		else:
			print(n // 2)


t = int(input())
for tc in range(t):
	g = int(input())
	for j in range(g):
		(i, n, q) = map(int, input().split())
		print(n // 2 + abs(i - q) * (n % 2))


import math

def solve(arr):
	(i, n, q) = arr
	if (q - i) % 2:
		return math.ceil(n / 2)
	return n // 2
for _ in range(int(input())):
	for __ in range(int(input())):
		print(solve([int(x) for x in input().split()]))


for _ in range(int(input())):
	g = int(input())
	for i in range(g):
		initialLetter = ''
		(i, n, q) = map(int, input().split())
		if i == 1:
			initialLetter = 'H'
		else:
			initialLetter = 'T'
		if (initialLetter == 'H' and q == 2 or (initialLetter == 'T' and q == 1)) and n % 2 != 0:
			print(int(n / 2 + 1))
		else:
			print(int(n / 2))


for _ in range(int(input())):
	G = int(input())
	for __ in range(G):
		(I, N, Q) = map(int, input().split())
		if Q == I:
			print(N // 2)
		else:
			print(N // 2 + (N & 1))


T = int(input())
for p in range(T):
	h = int(input())
	for l in range(h):
		(I, N, Q) = map(int, input().split())
		if N % 2 == 0:
			print(N // 2)
		elif I == Q:
			print(N // 2)
		else:
			print(N // 2 + 1)


import math as m
for i in range(int(input())):
	n = int(input())
	for i in range(n):
		(i, o, k) = map(int, input().split())
		if o % 2 == 0:
			print(o // 2)
		elif i == k:
			print(o // 2)
		else:
			print(o // 2 + 1)


t = int(input())
assert t >= 1 and t <= 10
while t:
	g = int(input())
	for i in range(g):
		(i, n, q) = map(int, input().split())
		if n % 2 != 0:
			if i == q:
				print(n // 2)
			else:
				print(n // 2 + 1)
		else:
			print(n // 2)
	t -= 1


T = int(input())
for t in range(0, T):
	G = int(input())
	for g in range(0, G):
		(I, N, Q) = map(int, input().split())
		odd_pos_sum = N // 2 + N % 2
		odd_neg_sum = N // 2
		evn_sum = N // 2
		if N % 2 == 0:
			print(evn_sum)
		elif N % 2 != 0 and Q == I:
			print(odd_neg_sum)
		elif N % 2 != 0 and Q != I:
			print(odd_pos_sum)


testcase = int(input())
for _ in range(testcase):
	games = int(input())
	for _ in range(games):
		info = input().split()
		info = list(map(int, info))
		(I, N, Q) = info
		if N % 2 == 0 or I == Q:
			print(N // 2)
		else:
			print(N // 2 + 1)