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. P5331 [SNOI2019]通信 [线段树优化建图+最小费用最大流]

    这题真让人自闭-我EK费用流已经死了?- (去掉define int long long就过了) 我建的边害死我的 spfa 还是spfa已经死了? 按费用流的套路来 首先呢 把点 \(i\) 拆成两 ...

  2. (转)Android访问webservice

    纠正网上乱传的android调用Webservice方法.   1.写作背景: 笔者想实现android调用webservice,可是网上全是不管对与错乱转载的文章,结果不但不能解决问题,只会让人心烦 ...

  3. VSCode常用插件之vscode-fileheader使用

    更多VSCode插件使用请访问:VSCode常用插件汇总 vscode-fileheader这是一个给js文件(html.css也可以使用,但是没意义!!!)生成头部注释的插件,每次修改js文件之后会 ...

  4. SQLyog怎么导入mysql数据库

    参考链接:https://jingyan.baidu.com/article/647f0115c5ad9f7f2148a8c6.html

  5. 转载:arm neon intrinsic

    转自:https://blog.csdn.net/hemmingway/article/details/44828303/ https://blog.csdn.net/chshplp_liaoping ...

  6. 多项式对数函数 - NTT

    #include <bits/stdc++.h> using namespace std; #define int long long const int N=4000005; // 4 ...

  7. GitBook的使用方式,快速创建网页文档

    环境需求:node npm 得装好 ----------------------------------- 我一开始不知道得先装gitbook-cli 先执行了 npm install gitbook ...

  8. ubuntu Redis安装及配置

    1.安装 1.1 下载压缩包:wget http://download.redis.io/releases/redis-5.0.4.tar.gz1.2 解压:tar xzf redis-5.0.4.t ...

  9. JUC之CountDownLatch和CyclicBarrier的区别 (转)

    CountDownLatch和CyclicBarrier的功能看起来很相似,不易区分,有一种谜之的神秘.本文将通过通俗的例子并结合代码讲解两者的使用方法和区别. CountDownLatch和Cycl ...

  10. Date/Math/String对象的函数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...