1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4.  
  5.  
  6. /*
  7. ------------------------Input Checker----------------------------------
  8. */
  9.  
  10. long long readInt(long long l,long long r,char endd){
  11. long long x=0;
  12. int cnt=0;
  13. int fi=-1;
  14. bool is_neg=false;
  15. while(true){
  16. char g=getchar();
  17. if(g=='-'){
  18. assert(fi==-1);
  19. is_neg=true;
  20. continue;
  21. }
  22. if('0'<=g && g<='9'){
  23. x*=10;
  24. x+=g-'0';
  25. if(cnt==0){
  26. fi=g-'0';
  27. }
  28. cnt++;
  29. assert(fi!=0 || cnt==1);
  30. assert(fi!=0 || is_neg==false);
  31.  
  32. assert(!(cnt>19 || ( cnt==19 && fi>1) ));
  33. } else if(g==endd){
  34. if(is_neg){
  35. x= -x;
  36. }
  37.  
  38. if(!(l <= x && x <= r))
  39. {
  40. cerr << l << ' ' << r << ' ' << x << '\n';
  41. assert(1 == 0);
  42. }
  43.  
  44. return x;
  45. } else {
  46. assert(false);
  47. }
  48. }
  49. }
  50. string readString(int l,int r,char endd){
  51. string ret="";
  52. int cnt=0;
  53. while(true){
  54. char g=getchar();
  55. assert(g!=-1);
  56. if(g==endd){
  57. break;
  58. }
  59. cnt++;
  60. ret+=g;
  61. }
  62. assert(l<=cnt && cnt<=r);
  63. return ret;
  64. }
  65. long long readIntSp(long long l,long long r){
  66. return readInt(l,r,' ');
  67. }
  68. long long readIntLn(long long l,long long r){
  69. return readInt(l,r,'\n');
  70. }
  71. string readStringLn(int l,int r){
  72. return readString(l,r,'\n');
  73. }
  74. string readStringSp(int l,int r){
  75. return readString(l,r,' ');
  76. }
  77.  
  78.  
  79. /*
  80. ------------------------Main code starts here----------------------------------
  81. */
  82.  
  83. const int MAX_T = 1000;
  84. const int MAX_N = 1000;
  85.  
  86. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  87.  
  88. int sum_len=0;
  89.  
  90. void solve()
  91. {
  92. int n = readIntSp(1, MAX_N);
  93. int a = readIntSp(1, n);
  94. int b = readIntLn(1, n);
  95. if(a > b) swap(a, b);
  96. if(b - a && b - a < 3) {
  97. if(b - a == 2 || a == 1 || b == n) {
  98. cout << "1\n";
  99. } else {
  100. cout << "2\n";
  101. }
  102. } else cout << "0\n";
  103. }
  104.  
  105. signed main()
  106. {
  107. //fast;
  108. #ifndef ONLINE_JUDGE
  109. //freopen("input.txt", "r", stdin);
  110. //freopen("output.txt", "w", stdout);
  111. #endif
  112.  
  113.  
  114. int t = readIntLn(1, MAX_T);
  115.  
  116. for(int i=1;i<=t;i++)
  117. {
  118. solve();
  119. }
  120.  
  121. assert(getchar() == -1);
  122. }