    // Codeforces.cpp : This file contains the 'main' function. Program execution begins and ends there.
    //
     
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <map>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
     
     
     
     
    int main()
    {
        int t,l,r,L,R; 
        vector < pair < int, int > > v;
        cin >> t;
        while (t--)
        {
            v.clear();
            cin >> l >> r >> L >> R;
            v.push_back(make_pair(l, r));
            v.push_back(make_pair(L, R));
            sort(v.begin(), v.end());
            if (v[1].first > v[0].second) {
                cout << 1 << endl;
                continue;
            }
            int locked = min(v[1].second,v[0].second) - v[1].first;
            if (v[1].first > v[0].first)locked++;
            if (v[0].second > v[1].second || v[0].second < v[1].second)locked++;
            cout << locked << endl;
        }
        return 0;
    }