Here Below I written my Solution of Funny Hand in Two different Languages C++ and Python.
Solution in C++ :
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll t = 1;
cin >> t;
while (t--)
{
ll n, a[2];
cin >> n >> a[0] >> a[1];
sort(a, a + 2);
if (a[1] - a[0] == 1)
{
if (a[0] == 1 || a[1] == n) cout << 1 << "\n";
else cout << 2 << "\n";
}
else if (a[1] - a[0] == 2)
{
cout << 1 << "\n";
}
else
{
cout << 0 << "\n";
}
}
}
Solution in Python3 :
t = int(input())
for i in range(0,t):
a,b,c=map(int,input().split())
minimum = min(b,c)
maximum = max(b,c)
if(minimum == 1 and abs(b-c) == 1):
print(1)
elif(minimum != 1 and abs(b-c) == 1 and maximum != a):
print(2)
elif(abs(b-c) == 1 and maximum == a):
print(1)
elif(abs(b-c) == 2):
print(1)
else:
print(0)