Help me in solving TWORANGES problem

My issue

I do not understand what’s wrong with this approach, I have clearly found the max possible range and subtracted the part in which the two ranges do not overlap, but it fails to pass one subtask, which I can’t understand why , I have even tried a few edge test cases but still, it is showing the wrong answer

My code

#include <iostream>
using namespace std;

int main() {
    int T;
    cin >> T; // Read the number of test cases

    while (T--) {
        int A, B, C, D;
        cin >> A >> B >> C >> D; // Read the range values

        int m = min(A, C);
        int n = max(B, D);
        int output = n - m + 1;

        if (B < C) {
            output = output -  (C - B - 1);

        cout << output << endl;

    return 0;

Problem Link: TWORANGES Problem - CodeChef

it fails for the input
6 7 1 3
just add a condition for (D<A) like you did for B,C and it should work fine.