## Table of Contents

**Chef and Races Codechef Solution**

The National Championships are starting soon. There are 4 race categories, numbered from 1 to 4, that Chef is interested in. Chef is participating in exactly 2 of these categories.

Chef has an arch-rival who is, unfortunately, the only person participating who is better than Chef, i.e, Chef can’t defeat the arch-rival in any of the four race categories but can defeat anyone else. Chef’s arch-rival is also participating in exactly 2 of the four categories.

Chef hopes to not fall into the same categories as that of the arch-rival. Given X,Y,A,B where X,Y are the races that Chef participates in, and A,B are the races that Chef’s arch-rival participates in, find the maximum number of gold medals (first place) that Chef can win.

**Input Format**

- The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows.
- Each testcase consists of a single line containing four space-separated integers — the values of X,Y,A, and B respectively.

**Output Format**

For each testcase, print a single line containing one integer — the maximum number of gold medals that Chef can win.

**Constraints**

- 1≤T≤144
- 1≤X,Y,A,B≤4
- X≠Y
- A≠B

**Subtasks****Subtask #1 (100 points):** Original constraints

**Sample Input 1**

3

4 3 1 2

4 2 1 2

2 1 1 2

**Sample Output 1**

2

1

0

**Explanation**

- Test case 1: Chef participates in the races 4,3, whereas Chef’s rival participates in 1,2. As Chef’s only rival does not participate in any of the races that Chef takes part in, Chef can win the gold medal in both of the races, thus the answer is 2.
- Test case 2: Chef participates in the races 4,2, whereas Chef’s rival participates in 1,2. Chef cannot win race 2 as Chef will be beaten by the arch-rival, however Chef can win the gold medal for race 4. Thus the answer is 1.
- Test case 3: Chef participates in the races 2,1, whereas Chef’s rival participates in 1,2. Chef will be beaten by the arch-rival in both races, thus the answer is 0.

**SOLUTION**

**Program:** **Chef and Races Codechef Solution** in Python

```
t = int(input())
for i in range(t):
x,y,a,b = map(int,input().split(" "))
z = 0
if x==a:
z+=1
if x==b:
z+=1
if y == a:
z+=1
if y == b:
z+=1
print(abs(z-2))
```

**Program:** **Chef and Races Codechef Solution** in C++

```
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int x,y,a,b;
cin>>x>>y>>a>>b;
int cnt=2;
if(x==a || y==a)cnt--;
if(x==b || y==b)cnt--;
cout<<cnt<<endl;
}
return 0;
}
```

**Program:** **Chef and Races Codechef Solution** in Java

```
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int x = sc.nextInt();
int y = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int count = 0;
if(a!=x && b!=x ){
count++;
}
if(a!=y && b!=y){
count++;
}
System.out.println(count);
}
}
}
```

**Related:**

*Perfect Imperfections 2 Codechef Solution**Kostomuksha and AESC MSU Codechef Solution**Minimum Longest Substring Codechef Solution**Same Parity Swaps in Binary Strings Codechef Solution**Missing Numbers Codechef Solution**The Rating Dilemma Codechef Solution**Chef and Races Codechef Solution**The Three Topics Codechef Solution**Increase IQ Codechef Solution*