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. 异常处理_python

    一.异常处理格式: name=[1,2]data={}try: name[3] data['name']except (KeyError,IndexError) as e : #捕捉指定的几个错误类型 ...

  2. Qt Gui 第一章~第二章

    一.Qt启动 qmake -project; 创建xxx.pro qmake xxx.pro; 生成makefile文件 make:构建该程序,生成可执行文件 运行程序:windows:xxx:mac ...

  3. [AT3867] Digit Sum 2

    给出N,求小于等于N的正整数中用十进制表示各数位数字之和的最大值. Solution 如果是X999的形式,那么就是自己 否则,就是(X-1)999 #include <bits/stdc++. ...

  4. 根据JSON的值设置radio选中状态

    说明:页面有一组单选按钮radio,现在页面发送请求得到一组json数据,包括radio的值. 需要根据JSON中的值绑定radio的选中状态> <table class="ta ...

  5. 解决Oracle ORA-01033: ORACLE initialization or shutdown in progress错误 和 ORA-01589错误 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项

    要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项 SQL> startupORACLE 例程已经启动. Total System Global Area  13533 ...

  6. 文本中自动出现的 &#8203

    文本中自动出现的 &#8203   所借鉴原页面地址:https://blog.csdn.net/judyc/article/details/53097142 因判断容器内字符长度来做其它处理 ...

  7. davinci入门必读

    http://www.usr.cc/forum.php/static/image/smiley/tiger/archiver/forum.php?mod=viewthread&action=p ...

  8. Linux零碎002

    1.if else就近原则: 2.指针位数与机器地址总线宽度一致: 3.数组即常量指针,用法和指针类似,在操作指针时:p与&p[0]含义一样: 4.编译器按照内存递减的方式来分配变量.

  9. 阿里云负载均衡-note

    公网负载均衡实例 公网类型的负载均衡实例可以通过Internet将客户端请求按照您制定的监听规则分发到添加的后端服务器ECS上. 在您创建公网负载均衡实例后,系统会为其分配一个公网服务地址,您可以将您 ...

  10. jQuery操作css

    jQuery addClass() 方法 向被选中元素添加class属性,参数为属性值 $("div").addClass("imp"); 也可以同时向多个元素 ...