QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14551. Watching Game Replays

Statistics

In a special 1-on-1 competition, the two sides use a "best of $n$ games" format, where $n$ is a given odd number. This means the competition lasts at most $n$ games, and the first player to win $\frac{n+1}{2}$ games is declared the winner, at which point the competition ends immediately.

Spectator A missed the live broadcast of this competition. Now that the competition has ended, spectator A knows that the competition lasted exactly $m$ games ($\frac{n+1}{2} \le m \le n$), but does not know the outcome of each game. Now A wants to watch the recording of this competition. A needs to watch the game recordings in order starting from the first game. Every time A finishes watching a game, they will know the winner of that game.

Please calculate the minimum number of games A needs to watch starting from the first game to ensure that they can determine the winner of the entire competition based on the outcomes of the games they have watched.

Input

The input contains multiple test cases. The first line contains a single positive integer $T$, representing the number of test cases.

Each of the following $T$ lines contains two positive integers $n$ and $m$, separated by a space, representing that the competition lasts at most $n$ games and that the competition lasted exactly $m$ games.

Data constraints: $1 \le n \le 10^9$, $n$ is an odd number, $\frac{n+1}{2} \le m \le n$, $1 \le T \le 10^4$.

Output

Output $T$ lines, each containing one integer, representing the corresponding answer.

Examples

Input 1

1
7 4

Output 1

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.