- #include <bits/stdc++.h>
- #define ll long long int
- using namespace std;
-
-
- /*
- ------------------------Input Checker----------------------------------
- */
-
- long long readInt(long long l,long long r,char endd){
- long long x=0;
- int cnt=0;
- int fi=-1;
- bool is_neg=false;
- while(true){
- char g=getchar();
- if(g=='-'){
- assert(fi==-1);
- is_neg=true;
- continue;
- }
- if('0'<=g && g<='9'){
- x*=10;
- x+=g-'0';
- if(cnt==0){
- fi=g-'0';
- }
- cnt++;
- assert(fi!=0 || cnt==1);
- assert(fi!=0 || is_neg==false);
-
- assert(!(cnt>19 || ( cnt==19 && fi>1) ));
- } else if(g==endd){
- if(is_neg){
- x= -x;
- }
-
- if(!(l <= x && x <= r))
- {
- cerr << l << ' ' << r << ' ' << x << '\n';
- assert(1 == 0);
- }
-
- return x;
- } else {
- assert(false);
- }
- }
- }
- string readString(int l,int r,char endd){
- string ret="";
- int cnt=0;
- while(true){
- char g=getchar();
- assert(g!=-1);
- if(g==endd){
- break;
- }
- cnt++;
- ret+=g;
- }
- assert(l<=cnt && cnt<=r);
- return ret;
- }
- long long readIntSp(long long l,long long r){
- return readInt(l,r,' ');
- }
- long long readIntLn(long long l,long long r){
- return readInt(l,r,'\n');
- }
- string readStringLn(int l,int r){
- return readString(l,r,'\n');
- }
- string readStringSp(int l,int r){
- return readString(l,r,' ');
- }
-
-
- /*
- ------------------------Main code starts here----------------------------------
- */
-
- const int MAX_T = 1000;
- const int MAX_N = 1000;
-
- #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
-
- int sum_len=0;
-
- void solve()
- {
- int n = readIntSp(1, MAX_N);
- int a = readIntSp(1, n);
- int b = readIntLn(1, n);
- if(a > b) swap(a, b);
- if(b - a && b - a < 3) {
- if(b - a == 2 || a == 1 || b == n) {
- cout << "1\n";
- } else {
- cout << "2\n";
- }
- } else cout << "0\n";
- }
-
- signed main()
- {
- //fast;
- #ifndef ONLINE_JUDGE
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
-
-
- int t = readIntLn(1, MAX_T);
-
- for(int i=1;i<=t;i++)
- {
- solve();
- }
-
- assert(getchar() == -1);
- }