You are the gym teacher in the school.

There are nn students in the row. And there are two rivalling students among them. The first one is in position aa, the second in position bb. Positions are numbered from 11 to nn from left to right.

Since they are rivals, you want to maximize the distance between them. If students are in positions pp and ss respectively, then distance between them is |p−s||p−s|.

You can do the following operation at most xx times: choose two adjacent (neighbouring) students and swap them.

Calculate the maximum distance between two rivalling students after at most xx swaps.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.

The only line of each test case contains four integers nn, xx, aa and bb (2≤n≤1002≤n≤100, 0≤x≤1000≤x≤100, 1≤a,b≤n1≤a,b≤n, a≠ba≠b) — the number of students in the row, the number of swaps which you can do, and positions of first and second rivaling students respectively.

Output

For each test case print one integer — the maximum distance between two rivaling students which you can obtain.

Example
input

Copy
3
5 1 3 2
100 33 100 1
6 0 2 3
output

Copy
2
99
1
Note

In the first test case you can swap students in positions 33 and 44. And then the distance between the rivals is equal to |4−2|=2|4−2|=2.

In the second test case you don't have to swap students.

In the third test case you can't swap students.

#include<bits/stdc++.h>
using namespace std ;
int n,x,a,b;
int main() {
int t;
cin>>t;
while(t--) {
cin>>n>>x>>a>>b;
if((abs(a-b)+x)>(n-)) cout<<n-<<endl;
else cout<<(abs(a-b)+x)<<endl;
}
return ;
}

Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  2. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  4. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  5. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

    E. The Contest A team of three programmers is going to play a contest. The contest consists of

  6. Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心

    D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of

  7. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

  8. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题

    B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...

  9. Educational Codeforces Round 76 (Rated for Div. 2) D题

    题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...

随机推荐

  1. Java并发,synchronized锁住的内容

    synchronized用在方法上锁住的是什么? 锁住的是当前对象的当前方法,会使得其他线程访问该对象的synchronized方法或者代码块阻塞,但并不会阻塞非synchronized方法. 脏读 ...

  2. chrome js报错Uncaught SyntaxError: Unexpected string

    个人博客 地址:http://www.wenhaofan.com/article/20180912123136 js报错,最后发现是$(function(){})这部分()不完整 $(function ...

  3. 题解 P5613 【[MtOI2019]黑蚊子多】

    题目传送门 一道模拟题目,签到送分题. 您需要的知识 1.while循环 2.for循环 3.一维数组 思路: Step 1:按题目要求,定义a[],n,m,k int a[10001]; int n ...

  4. Hive学习笔记二

    目录 Hive常见属性配置 将本地库文件导入Hive案例 Hive常用交互命令 Hive其他命令操作 参数配置方式 Hive常见属性配置 1.Hive数据仓库位置配置 1)Default数据仓库的最原 ...

  5. react 和 vue 的优缺点总结

    React推广了Virtual DOM并创造了新的语法——JSX,JSX允许开发者在JavaScript中书写HTML Vue使用模板系统而不是JSX,但能对现有应用的升级更加容易,这是因为模板用的就 ...

  6. asp.net中正则表达式使用

    一.限定符:限定符提供了一种简单方法,用于指定允许特定字符或字符集自身重复出现的次数.限定符始终引用限定符前(左边)的模式,通常是单个字符,除非使用括号创建模式组. (一)非显示限定符 1. *,描述 ...

  7. TP-网页静态化

    首先放上一张某手册中的一段代码: 我们要想在TP框架中执行网页静态化,在这段代码的基础上稍加添加就可以了: 在TP5框架中,为了方便寻找模板文件与生成的静态文件,我们将模板文件以及生成的静态文件放在p ...

  8. PP: Data-driven classification of residential energy consumption patterns by means of functional connectivity networks

    Purpose Implement a good user aggregation and classification. or to assess the interrelation pattern ...

  9. codeforces 1288E. Messenger Simulator(树状数组)

    链接:https://codeforces.com/contest/1288/problem/E 题意:序列p的长度为n,初始序列为1 2 3 4 ...n,然后有m次操作,每次指定序列中一个数移动到 ...

  10. codeforces 1283D. Christmas Trees(bfs)

    链接: https://codeforces.com/contest/1283/problem/D 题意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小. 思路 ...