#include<iostream>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<bitset>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>

using namespace std;

#define PI 3.14159265359
#define E 2.71828182846
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef map<int,int>mii;
typedef set<int> si;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define DFS_WHITE -1
#define DFS_BLACK 1
#define GRAY 0

vector<vii>adjlist;

int main()
{
    int n,m;
    cin>>n>>m;
    int col[n+1];
    int cont[n+1];
     memset(col,0,sizeof col);
   //memset(cont,0,sizeof cont);
    int arr[m][3];
    for(int i=0;i<m;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
       // cont[arr[i][0]]++;
       // cont[arr[i][1]]++;
        //cont[arr[i][2]]++;
    }
   // sort(cont+1,cont+n+1);
   col[arr[0][0]]=1;
   col[arr[0][1]]=2;
   col[arr[0][2]]=3;
    for(int i=1;i<m;i++)

        if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            col[arr[i][0]]=1;
            col[arr[i][1]]=2;
            col[arr[i][2]]=3;

        }
        else  if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][0]];
            if(k==1){
                col[arr[i][1]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][1]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][1]]=1;
            col[arr[i][2]]=2;}

       }
       else  if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][2]]=2;}
        }
        else  if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][1]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][1]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][1]]=2;}

       }
       else{
            if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                if(abs(k-l)==2)
                    col[arr[i][2]]=2;
                else
                    col[arr[i][2]]=3;
            }
            else if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][1]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][0]]=2;
                else
                    col[arr[i][0]]=3;
            }
            else if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][1]]=2;
                else
                    col[arr[i][1]]=3;
            }
       /*     else if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                int m=col[arr[i][2]];
                if(abs(k-l)==m || abs(k-m)==l || abs(l-m)==k)
                continue;
                else
                {
                   // cout<<"chutiya kat gaya\n";
                   // return 0;
                }
            }
            */

       }

   for(int i=1;i<=n;i++)
    {   if(col[i]!=0)
        cout<<col[i]<<" ";
        else
            cout<<rand()%3<<" ";
        }

    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<bitset>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>

using namespace std;

#define PI 3.14159265359
#define E 2.71828182846
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef map<int,int>mii;
typedef set<int> si;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define DFS_WHITE -1
#define DFS_BLACK 1
#define GRAY 0

vector<vii>adjlist;

int main()
{
    int n,m;
    cin>>n>>m;
    int col[n+1];
    int cont[n+1];
     memset(col,0,sizeof col);
   //memset(cont,0,sizeof cont);
    int arr[m][3];
    for(int i=0;i<m;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
       // cont[arr[i][0]]++;
       // cont[arr[i][1]]++;
        //cont[arr[i][2]]++;
    }
   // sort(cont+1,cont+n+1);
   col[arr[0][0]]=1;
   col[arr[0][1]]=2;
   col[arr[0][2]]=3;
    for(int i=1;i<m;i++)

        if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            col[arr[i][0]]=1;
            col[arr[i][1]]=2;
            col[arr[i][2]]=3;

        }
        else  if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][0]];
            if(k==1){
                col[arr[i][1]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][1]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][1]]=1;
            col[arr[i][2]]=2;}

       }
       else  if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][2]]=2;}
        }
        else  if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
        {
            int l,k=col[arr[i][2]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][1]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][1]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][1]]=2;}

       }
       else{
            if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                if(abs(k-l)==2)
                    col[arr[i][2]]=2;
                else
                    col[arr[i][2]]=3;
            }
            else if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][1]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][0]]=2;
                else
                    col[arr[i][0]]=3;
            }
            else if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][1]]=2;
                else
                    col[arr[i][1]]=3;
            }
       /*     else if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                int m=col[arr[i][2]];
                if(abs(k-l)==m || abs(k-m)==l || abs(l-m)==k)
                continue;
                else
                {
                   // cout<<"chutiya kat gaya\n";
                   // return 0;
                }
            }
            */

       }

   for(int i=1;i<=n;i++)
    {   if(col[i]!=0)
        cout<<col[i]<<" ";
        else
            cout<<rand()%3<<" ";
        }

    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cctype>
#include<cstdio>
#include<bitset>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>

using namespace std;

#define PI 3.14159265359
#define E 2.71828182846
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef map<int,int>mii;
typedef set<int> si;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define DFS_WHITE -1
#define DFS_BLACK 1
#define GRAY 0

vector<vii>adjlist;

int main()
{
    int n,m;
    cin>>n>>m;
    int col[n+1];
    int cont[n+1];
     memset(col,0,sizeof col);
   //memset(cont,0,sizeof cont);
    int arr[m][3];
    for(int i=0;i<m;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
       // cont[arr[i][0]]++;
       // cont[arr[i][1]]++;
        //cont[arr[i][2]]++;
    }
   // sort(cont+1,cont+n+1);
   col[arr[0][0]]=1;
   col[arr[0][1]]=2;
   col[arr[0][2]]=3;
    for(int i=1;i<m;i++)

        if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            col[arr[i][0]]=1;
            col[arr[i][1]]=2;
            col[arr[i][2]]=3;

        }
        else  if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][0]];
            if(k==1){
                col[arr[i][1]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][1]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][1]]=1;
            col[arr[i][2]]=2;}

       }
       else  if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][2]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][2]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][2]]=2;}
        }
        else  if(col[arr[i][0]]==0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
        {
            int l,k=col[arr[i][1]];
            if(k==1){
                col[arr[i][0]]=2;
              col[arr[i][1]]=3;
            }
            else if(k==2){col[arr[i][0]]=1;
            col[arr[i][1]]=3;}

               else if(k==3){col[arr[i][0]]=1;
            col[arr[i][1]]=2;}

       }
       else{
            if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]==0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                if(abs(k-l)==2)
                    col[arr[i][2]]=2;
                else
                    col[arr[i][2]]=3;
            }
            else if(col[arr[i][0]]==0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][1]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][0]]=2;
                else
                    col[arr[i][0]]=3;
            }
            else if(col[arr[i][0]]!=0&&col[arr[i][1]]==0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][2]];
                if(abs(k-l)==2)
                    col[arr[i][1]]=2;
                else
                    col[arr[i][1]]=3;
            }
       /*     else if(col[arr[i][0]]!=0&&col[arr[i][1]]!=0&&col[arr[i][2]]!=0)
            {
                int k=col[arr[i][0]];
                int l=col[arr[i][1]];
                int m=col[arr[i][2]];
                if(abs(k-l)==m || abs(k-m)==l || abs(l-m)==k)
                continue;
                else
                {
                   // cout<<"chutiya kat gaya\n";
                   // return 0;
                }
            }
            */

       }
   for(int i=1;i<=n;i++)
    cout<<col[i]<<" ";

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<fstream>
using namespace std;
int q[2000001]={0};
int main()
{int i,n,m,a,b,c;
      // freopen ("input.txt","r",stdin);
     // freopen ("output.txt","w",stdout);
     cin>>n>>m;
     for(i=0;i<m;i++){
                      cin>>a>>b>>c;
     if(q[a]==0 && q[b]==0 && q[c]==0){
                q[a]=1;q[b]=2;q[c]=3;continue;}
          if(q[a]==1){q[b]=2;q[c]=3;continue;}
          if(q[a]==2){q[b]=1;q[c]=3;continue;}
          if(q[a]==3){q[b]=1;q[c]=2;continue;}
          if(q[b]==1){q[a]=2;q[c]=3;continue;}
          if(q[b]==2){q[a]=1;q[c]=3;continue;}
          if(q[b]==3){q[a]=1;q[a]=2;continue;}
          if(q[c]==1){q[b]=2;q[a]=3;continue;}
          if(q[c]==2){q[b]=1;q[a]=3;continue;}
          if(q[c]==3){q[b]=1;q[a]=2;continue;}
          }
          for(i=1;i<=n;i++)cout<<q[i]<<" ";
    //system("pause");
    return 0;
      }


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<fstream>
using namespace std;
int q[2000001]={0};
int main()
{int i,n,m,a,b,c;
      // freopen ("input.txt","r",stdin);
     // freopen ("output.txt","w",stdout);
     cin>>n>>m;
     for(i=1;i<m;i++){
                      cin>>a>>b>>c;
     if(q[a]==0 && q[b]==0 && q[c]==0){
                q[a]=1;q[b]=2;q[c]=3;}
     else {
          if(q[a]==1){q[b]=2;q[c]=3;continue;}
          if(q[a]==2){q[b]=1;q[c]=3;continue;}
          if(q[a]==3){q[b]=1;q[c]=2;continue;}
          if(q[b]==1){q[a]=2;q[c]=3;continue;}
          if(q[b]==2){q[a]=1;q[c]=3;continue;}
          if(q[b]==3){q[a]=1;q[a]=2;continue;}
          if(q[c]==1){q[b]=2;q[a]=3;continue;}
          if(q[c]==2){q[b]=1;q[a]=3;continue;}
          if(q[c]==3){q[b]=1;q[a]=2;continue;}
          }
          }
          for(i=1;i<=n;i++)cout<<q[i]<<" ";
    //system("pause");
    return 0;
      }


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<fstream>
using namespace std;
int q[1000001]={0};
int main()
{int i,n,m,a,b,c;
      // freopen ("input.txt","r",stdin);
     // freopen ("output.txt","w",stdout);
     cin>>n>>m;
     for(i=0;i<m;i++){
                      cin>>a>>b>>c;
     if(q[a]==0 && q[b]==0 && q[c]==0){
                q[a]=1;q[b]=2;q[c]=3;continue;}
          if(q[a]==1){q[b]=2;q[c]=3;continue;}
          if(q[a]==2){q[b]=1;q[c]=3;continue;}
          if(q[a]==3){q[b]=1;q[c]=2;continue;}
          if(q[b]==1){q[a]=2;q[c]=3;continue;}
          if(q[b]==2){q[a]=1;q[c]=3;continue;}
          if(q[b]==3){q[a]=1;q[c]=2;continue;}
          if(q[c]==1){q[b]=2;q[a]=3;continue;}
          if(q[c]==2){q[b]=1;q[a]=3;continue;}
          if(q[c]==3){q[b]=1;q[a]=2;continue;}
          }
          }
          for(i=1;i<=n;i++)cout<<q[i]<<" ";
    //system("pause");
    return 0;
      }


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define ff first
#define ss second
#define pi pair<lli,lli>
#define pb push_back
#define vi vector<lli>
#define vc vector<char>
#define vp vector<pair<lli,lli>>
#define si set<lli>
#define llmi LLONG_MIN
#define llma LLONG_MAX
#define mod 1000000007

int main(){
    lli t,a,b,c,d;
    cin>>t;
    while(t--){
        cin>>a>>b>>c>>d;
        cout<<max(a+b,c+d)<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a+b,c+d);

    return 0;
}


#include <vits/stdc++.h>
int main ()
{
	int z;
	scanf("%d",&z);
	for(int u=1;u<=z;u++)
	{
	    int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a,d)+min(b,c));
	}
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
	int z;
	scanf("%d",&z);
	for(int u=1;u<=z;u++)
	{
	    int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a,d)+min(b,c));
	}
}


#include <bits/stdc++.h>
int main ()
{
	int z;
	scanf("%d",&z);
	for(int u=1;u<=z;u++)
	{
	    int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a,d)+min(b,c));
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c>>d;
        cout<<max(a+b,c+d)<<'\n';
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
int main ()
{
	int z;
	scanf("%d",&z);
	for(int u=1;u<=z;u++)
	{
	    int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a,d)+min(b,c));
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int t;
	cin>>t;
	while(t--)
	{
		long int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(c>=b)
		cout<<a+b<<endl;
		else
		cout<<c+d<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int t;
	cin>>t;
	while(t--)
	{
		long int a,b,c,d;
		long int sum=0;
		cin>>a>>b>>c>>d;
		sum=a+b+c+d;
		if(sum%2==0)
		cout<<sum/2<<endl;
		else
		{
		    int te=sum/2;
		    te=te+1;
		    cout<<te<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int t;
	cin>>t;
	while(t--)
	{
		long int a,b,c,d;
		cin>>a>>b>>c>>d;
		int te=a+b;
		int tt=c+d;
		cout<<max(te,tt)<<endl;

	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int t;
	cin>>t;
	while(t--)
	{
		long int a,b,c,d;
		cin>>a>>b>>c>>d;
		sum=a+b+c+d;
		if(sum%2==0)
		cout<<sum/2<<endl;
		else
		{
		    int te=sum/2;
		    te=te+1;
		    cout<<te<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max(a+b,c+d)<<endl;
}
return 0;
}


#include<bits/stdc++.h>
#include<fstream>
#include<string>
using namespace std;

#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pi 3.141593
#define fi(i,a,b) for(int i=a;i< b;i++)
#define rept(i,n) fi(i,0,n)
#define ll long long
#define mod 1000000007
#define pb push_back
#define N 10000
#define M 10000
//cout<<"Case #"<<tc<<": ";

int tam(int a,int b)
{
  return a<b;
}

int mat_it(int a)
{
  return 2*a;
}

bool calc(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    if(prime[n]) return false;
    else return true;
}

int main()
{
#ifndef ONLINE_JUDGE
  freopen("pi.txt","r",stdin);
  freopen("oop.txt","w",stdout);
#endif
    ios;
    int t;
    cin>>t;
    while(t--)
    {
      int a[4],i;
      cin>>a[0]>>a[1]>>a[2]>>a[3];
      sort(a,a+4);

      cout<<(a[1] + a[2])<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<fstream>
#include<string>
using namespace std;

#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pi 3.141593
#define fi(i,a,b) for(int i=a;i< b;i++)
#define rept(i,n) fi(i,0,n)
#define ll long long
#define mod 1000000007
#define pb push_back
#define N 10000
#define M 10000
//cout<<"Case #"<<tc<<": ";

int tam(int a,int b)
{
  return a<b;
}

int mat_it(int a)
{
  return 2*a;
}

bool calc(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    if(prime[n]) return false;
    else return true;
}

int main()
{
#ifndef ONLINE_JUDGE
  freopen("pi.txt","r",stdin);
  freopen("oop.txt","w",stdout);
#endif
    ios;
    int t;
    cin>>t;
    while(t--)
    {
      int a[4],i,b[3];
      cin>>a[0]>>a[1]>>a[2]>>a[3];
      sort(a,a+4);
      b[0] = a[0] + a[1];
      b[1] = a[1] + a[2];
      b[2] = a[2] + a[3];

      sort(b,b+3);
      cout<<b[1]<<endl;

    }
    return 0;
  }


#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

int main()
{
	int t;
	cin >> t;
	stringstream ss;
	for (int i = 0; i < t; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		ss << max(a + b, c + d) << "\n";
	}
	cout << ss.str();
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a + b, c + d);
}


#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << max(a + b, c + d) << "\n";
	}
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << max(a + b, c + d);
	}
}


#include<bits/stdc++.h>
#define   sc(x) scanf("%d",&x)
using namespace std;
#define   scll(x) scanf("%lld",&x)
#define   fr(i,n) for(int i=0;i<n;i++)
#define   Fr(i,x,y) for(int i=x;i<=y;i++)
#define   pf printf
#define   pb  push_back
#define   mp make_pair
#define   nl endl
#define   um unordered_map<int,int>
#define   dug(x) cout<<x<<" "
#define   vi vector<int>
#define   vlli vector<lli>
#define   sot(v) v.begin(), v.end()
typedef  long long int lli;
typedef  long long  ll;

void solve(){
lli a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min((a+b),(d+c));
//4 3
//2 4 16 18 21 27 36 53 82 91 92 95

}

int main(){
int t;
sc(t);
while(t--){
    solve();
}

}


#include<bits/stdc++.h>
#define   sc(x) scanf("%d",&x)
using namespace std;
#define   scll(x) scanf("%lld",&x)
#define   fr(i,n) for(int i=0;i<n;i++)
#define   Fr(i,x,y) for(int i=x;i<=y;i++)
#define   pf printf
#define   pb  push_back
#define   mp make_pair
#define   nl endl
#define   um unordered_map<int,int>
#define   dug(x) cout<<x<<" "
#define   vi vector<int>
#define   vlli vector<lli>
#define   sot(v) v.begin(), v.end()
typedef  long long int lli;
typedef  long long  ll;

void solve(){
lli a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min((a+b),(d+c))<<nl;
//4 3
//2 4 16 18 21 27 36 53 82 91 92 95

}

int main(){
int t;
sc(t);
while(t--){
    solve();
}

}


#include<bits/stdc++.h>
#define   sc(x) scanf("%d",&x)
using namespace std;
#define   scll(x) scanf("%lld",&x)
#define   fr(i,n) for(int i=0;i<n;i++)
#define   Fr(i,x,y) for(int i=x;i<=y;i++)
#define   pf printf
#define   pb  push_back
#define   mp make_pair
#define   nl endl
#define   um unordered_map<int,int>
#define   dug(x) cout<<x<<" "
#define   vi vector<int>
#define   vlli vector<lli>
#define   sot(v) v.begin(), v.end()
typedef  long long int lli;
typedef  long long  ll;

void solve(){
lli a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max((a+b),(d+c))<<nl;
//4 3
//2 4 16 18 21 27 36 53 82 91 92 95

}

int main(){
int t;
sc(t);
while(t--){
    solve();
}

}


#include<bits/stdc++.h>
#define   sc(x) scanf("%d",&x)
using namespace std;
#define   scll(x) scanf("%lld",&x)
#define   fr(i,n) for(int i=0;i<n;i++)
#define   Fr(i,x,y) for(int i=x;i<=y;i++)
#define   pf printf
#define   pb  push_back
#define   mp make_pair
#define   nl endl
#define   um unordered_map<int,int>
#define   dug(x) cout<<x<<" "
#define   vi vector<int>
#define   vlli vector<lli>
#define   sot(v) v.begin(), v.end()
typedef  long long int lli;
typedef  long long  ll;

void solve(){
lli a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min((a+b),(a+c))<<nl;
//4 3
//2 4 16 18 21 27 36 53 82 91 92 95

}

int main(){
int t;
sc(t);
while(t--){
    solve();
}

}


//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 3000009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll t,n,l,i,j;
     cin>>t;
     while(t--)
     {
         ll a,b,c,d,s;
         cin>>a>>b>>c>>d;
          s=a+c+a+b+d+c;
          l=s/3;
         cout<<l<<endl;
     }
}


//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 3000009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll t,n,l,i,j;
     cin>>t;
     while(t--)
     {
         ll a,b,c,d,s;
         cin>>a>>b>>c>>d;
          s=50*(a+c)+(a+b)*50+(d+c)*50;
          l=s/150;
         cout<<l<<endl;
     }
}


//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 3000009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll t,n,l,i,j;
     cin>>t;
     while(t--)
     {
         ll a,b,c,d,s;
         cin>>a>>b>>c>>d;
          l=max(a+b,c+d);
         cout<<l<<endl;
     }
}


//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 3000009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll t,n,l,i,j;
     cin>>t;
     while(t--)
     {
         ll a,b,c,d,s;
         cin>>a>>b>>c>>d;
          s=a+b+c+d;
         if(s%2==0)
            l=s/2;
         else l=s/2+1;
         cout<<l<<endl;
     }
}


#include<bits/stdc++.h>
#define ll long long
#define vc vector
#define ff first
#define ss second
#define _ << " " <<
#define pb push_back
#define mp make_pair
#define MX moveX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
#define MY moveY[] = {0, 1, 0, -1, -1, 1, 1, -1};
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NB Numbers[10] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
// memory, runtime avj baiwal zarimdaa zugeerl hariugaa hewleed zui togtloo harj bai

using namespace std;

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	FAST
	int i, j, n, m, s, k, p, x, y, t, ans, a, b, c, d;

	cin >> t;

	while(t --) {
		cin >> a >> b >> c >> d;
		k = a + b;
		s = d + c;
		m = b + d;
		k = min(k, s);
		if(m >= k) {
			cout << m << endl;
		}else cout << min(a+b, d+c);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vc vector
#define ff first
#define ss second
#define _ << " " <<
#define pb push_back
#define mp make_pair
#define MX moveX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
#define MY moveY[] = {0, 1, 0, -1, -1, 1, 1, -1};
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NB Numbers[10] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
// memory, runtime avj baiwal zarimdaa zugeerl hariugaa hewleed zui togtloo harj bai

using namespace std;

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	FAST
	int i, j, n, m, s, k, p, x, y, t, ans, a, b, c, d;

	cin >> t;

	while(t --) {
		cin >> a >> b >> c >> d;
		cout << max(a,d) + min(b,c) << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vc vector
#define ff first
#define ss second
#define _ << " " <<
#define pb push_back
#define mp make_pair
#define MX moveX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
#define MY moveY[] = {0, 1, 0, -1, -1, 1, 1, -1};
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NB Numbers[10] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
// memory, runtime avj baiwal zarimdaa zugeerl hariugaa hewleed zui togtloo harj bai

using namespace std;

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	FAST
	int i, j, n, m, s, k, p, x, y, t, ans, a, b, c, d;

	cin >> t;

	while(t --) {
		cin >> a >> b >> c >> d;
		k = a + b;
		s = d + c;
		m = b + d;
		k = min(k, s);
		if(m >= k) {
			cout << m << endl;
		}else cout << max(a+b, d+c);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vc vector
#define ff first
#define ss second
#define _ << " " <<
#define pb push_back
#define mp make_pair
#define MX moveX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
#define MY moveY[] = {0, 1, 0, -1, -1, 1, 1, -1};
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NB Numbers[10] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
// memory, runtime avj baiwal zarimdaa zugeerl hariugaa hewleed zui togtloo harj bai

using namespace std;

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	FAST
	int i, j, n, m, s, k, p, x, y, t, ans, a, b, c, d;

	cin >> t;

	while(t --) {
		cin >> a >> b >> c >> d;
		cout << max(a+b, c+d) << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int q;
    cin>>q;
    for(int m=0; m<q; m++)
    {
        int a, b, c, d; cin>>a>>b>>c>>d;
        cout<<max(a+b, c+d)<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int q;
    cin>>t;
    for(int m=0; m<q; m++)
    {
        int a, b, c, d; cin>>a>>b>>c>>d;
        cout<<(a+b+c+d)/2<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int q;
    cin>>q;
    for(int m=0; m<q; m++)
    {
        int a, b, c, d; cin>>a>>b>>c>>d;
        cout<<(a+b+c+d+1)/2<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int q;
    cin>>q;
    for(int m=0; m<q; m++)
    {
        int a, b, c, d; cin>>a>>b>>c>>d;
        cout<<a+b<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int q;
    cin>>q;
    for(int m=0; m<q; m++)
    {
        int a, b, c, d; cin>>a>>b>>c>>d;
        cout<<(a+b+c+d)/2<<endl;
    }

    return 0;
}


            #include<bits/stdc++.h>
            using namespace std;
            #define gc getchar_unlocked
            #define fo(i,n) for(i=0;i<n;i++)
            #define ll long long
            #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
            #define si(x)	scanf("%d",&x)
            #define sl(n)	scanf("%lld",&x)
            #define ss(s)	scanf("%s",s)
            #define pi(x)	printf("%d\n",x)
            #define pl(x)	printf("%lld\n",x)
            #define ps(s)	printf("%s\n",s)
            #define deb(x) cout << #x << "=" << x << endl
            #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
            #define pb push_back
            #define mp make_pair
            #define F first
            #define S second
            #define all(x) x.begin(), x.end()
            #define clr(x) memset(x, 0, sizeof(x))
            #define sortall(x) sort(all(x))
            #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
            #define PI 3.1415926535897932384626
            typedef pair<int, int>	pii;
            typedef pair<ll, ll>	pl;
            typedef vector<int>		vi;
            typedef vector<ll>		vl;
            typedef vector<pii>		vpii;
            typedef vector<pl>		vpl;
            typedef vector<vi>		vvi;
            typedef vector<vl>		vvl;
            mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
            int rng(int lim) {
                uniform_int_distribution<int> uid(0,lim-1);
                return uid(rang);
            }
            int mpow(int base, int exp);
            void ipgraph(int n, int m);
            void dfs(int u, int par);

            const int mod = 1'000'000'007;
            const int N = 3e5, M = N;
            //=======================

            vi g[N];
            int a[N];

            void solve() {
            int a,b,c,d;cin>>a>>b>>d>>d;
            cout<<max(a+b,c+d)<<endl;

            }

            int main() {
                ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
                srand(chrono::high_resolution_clock::now().time_since_epoch().count());

                int t = 1;
                cin>>t;
                while(t--) {
                  solve();
                }

                return 0;
            }

            int mpow(int base, int exp) {
              base %= mod;
              int result = 1;
              while (exp > 0) {
                if (exp & 1) result = ((ll)result * base) % mod;
                base = ((ll)base * base) % mod;
                exp >>= 1;
              }
              return result;
            }

            void ipgraph(int n, int m){
                int i, u, v;
                while(m--){
                    cin>>u>>v;
                u--, v--;
                    g[u].pb(v);
                    g[v].pb(u);
                }
            }

            void dfs(int u, int par){
                for(int v:g[u]){
                    if (v == par) continue;
                    dfs(v, u);
                }
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define gc getchar_unlocked
            #define fo(i,n) for(i=0;i<n;i++)
            #define ll long long
            #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
            #define si(x)	scanf("%d",&x)
            #define sl(n)	scanf("%lld",&x)
            #define ss(s)	scanf("%s",s)
            #define pi(x)	printf("%d\n",x)
            #define pl(x)	printf("%lld\n",x)
            #define ps(s)	printf("%s\n",s)
            #define deb(x) cout << #x << "=" << x << endl
            #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
            #define pb push_back
            #define mp make_pair
            #define F first
            #define S second
            #define all(x) x.begin(), x.end()
            #define clr(x) memset(x, 0, sizeof(x))
            #define sortall(x) sort(all(x))
            #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
            #define PI 3.1415926535897932384626
            typedef pair<int, int>	pii;
            typedef pair<ll, ll>	pl;
            typedef vector<int>		vi;
            typedef vector<ll>		vl;
            typedef vector<pii>		vpii;
            typedef vector<pl>		vpl;
            typedef vector<vi>		vvi;
            typedef vector<vl>		vvl;
            mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
            int rng(int lim) {
                uniform_int_distribution<int> uid(0,lim-1);
                return uid(rang);
            }
            int mpow(int base, int exp);
            void ipgraph(int n, int m);
            void dfs(int u, int par);

            const int mod = 1'000'000'007;
            const int N = 3e5, M = N;
            //=======================

            vi g[N];
            int a[N];

            void solve() {
            int a,b,c,d;cin>>a>>b>>c>>d;
            cout<<max(a+b,c+d)<<endl;

            }

            int main() {
                ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
                srand(chrono::high_resolution_clock::now().time_since_epoch().count());

                int t = 1;
                cin>>t;
                while(t--) {
                  solve();
                }

                return 0;
            }

            int mpow(int base, int exp) {
              base %= mod;
              int result = 1;
              while (exp > 0) {
                if (exp & 1) result = ((ll)result * base) % mod;
                base = ((ll)base * base) % mod;
                exp >>= 1;
              }
              return result;
            }

            void ipgraph(int n, int m){
                int i, u, v;
                while(m--){
                    cin>>u>>v;
                u--, v--;
                    g[u].pb(v);
                    g[v].pb(u);
                }
            }

            void dfs(int u, int par){
                for(int v:g[u]){
                    if (v == par) continue;
                    dfs(v, u);
                }
            }


            #include<bits/stdc++.h>
            using namespace std;
            #define gc getchar_unlocked
            #define fo(i,n) for(i=0;i<n;i++)
            #define ll long long
            #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
            #define si(x)	scanf("%d",&x)
            #define sl(n)	scanf("%lld",&x)
            #define ss(s)	scanf("%s",s)
            #define pi(x)	printf("%d\n",x)
            #define pl(x)	printf("%lld\n",x)
            #define ps(s)	printf("%s\n",s)
            #define deb(x) cout << #x << "=" << x << endl
            #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
            #define pb push_back
            #define mp make_pair
            #define F first
            #define S second
            #define all(x) x.begin(), x.end()
            #define clr(x) memset(x, 0, sizeof(x))
            #define sortall(x) sort(all(x))
            #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
            #define PI 3.1415926535897932384626
            typedef pair<int, int>	pii;
            typedef pair<ll, ll>	pl;
            typedef vector<int>		vi;
            typedef vector<ll>		vl;
            typedef vector<pii>		vpii;
            typedef vector<pl>		vpl;
            typedef vector<vi>		vvi;
            typedef vector<vl>		vvl;
            mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
            int rng(int lim) {
                uniform_int_distribution<int> uid(0,lim-1);
                return uid(rang);
            }
            int mpow(int base, int exp);
            void ipgraph(int n, int m);
            void dfs(int u, int par);

            const int mod = 1'000'000'007;
            const int N = 3e5, M = N;
            //=======================

            vi g[N];
            int a[N];

            void solve() {
            int a,b,c,d;cin>>a>>b>>d>>d;
            if(a+b+c+d==0){cout<<0<<endl;return;}cout<<max(a+b,c+d)<<endl;

            }

            int main() {
                ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
                srand(chrono::high_resolution_clock::now().time_since_epoch().count());

                int t = 1;
                cin>>t;
                while(t--) {
                  solve();
                }

                return 0;
            }

            int mpow(int base, int exp) {
              base %= mod;
              int result = 1;
              while (exp > 0) {
                if (exp & 1) result = ((ll)result * base) % mod;
                base = ((ll)base * base) % mod;
                exp >>= 1;
              }
              return result;
            }

            void ipgraph(int n, int m){
                int i, u, v;
                while(m--){
                    cin>>u>>v;
                u--, v--;
                    g[u].pb(v);
                    g[v].pb(u);
                }
            }

            void dfs(int u, int par){
                for(int v:g[u]){
                    if (v == par) continue;
                    dfs(v, u);
                }
            }


//Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
    fasthoja;
    ll t; cin>>t;
    while(t--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        cout << a+b << "\n";
    }//end of test case loop
    return 0;
}


//Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
    fasthoja;
    ll t; cin>>t;
    while(t--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        // cout << a+b << "\n";
        // ll ans = abs( a-b ) + abs(c-d);
        // ll ans = min( a+b, a+c );
        // ll ans = ceil(( a+b+c+d ) / 2.0);
        ll ans = max( a+b, c+d );
        cout << ans << "\n";
    }//end of test case loop
    return 0;
}


//Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
    fasthoja;
    ll t; cin>>t;
    while(t--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        // cout << a+b << "\n";
        // ll ans = abs( a-b ) + abs(c-d);
        ll ans = min( a+b, a+c );
        cout << ans << "\n";
    }//end of test case loop
    return 0;
}


//Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
    fasthoja;
    ll t; cin>>t;
    while(t--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        // cout << a+b << "\n";
        ll ans = abs( a-b ) + abs(c-d);
        cout << ans + 1 << "\n";
    }//end of test case loop
    return 0;
}


//Coded By Vishal Mourya - The Legendary Coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(var,a,b) for(ll var = a ; var < b ; var++ )
#define fr(var,a,b) for(ll var = a ; var > b ; var-- )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(void){
    fasthoja;
    ll t; cin>>t;
    while(t--){
        ll a,b,c,d; cin >> a >> b >> c >> d;
        // cout << a+b << "\n";
        // ll ans = abs( a-b ) + abs(c-d);
        // ll ans = min( a+b, a+c );
        ll ans = ceil(( a+b+c+d ) / 2.0);
        cout << ans << "\n";
    }//end of test case loop
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
        long a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<a+b<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
        long a,b,c,d;
        cin>>a>>b>>c>>d;
        long x=min(a,c);
        long y=max(b,d);
        cout<<x+y<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
        long a,b,c,d;
        cin>>a>>b>>c>>d;
        long x=min(b,c);
        long y=max(a,d);
        cout<<x+y<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
        long a,b,c,d;
        cin>>a>>b>>c>>d;
        long x=a+b;
        long y=c+d;
        cout<<max(x,y)<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
        long a,b,c,d;
        cin>>a>>b>>c>>d;
        long x=a+c;
        long y=b+d;
        if(y&1) cout<<x<<endl;
        else cout<<x-1<<endl;
    }
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define up(s) transform(string s.begin(),string s.end(),string s.begin(), ::toupper)
#define PI 3.1415926535897932384626
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<string>  vs;
typedef map<ll,ll>      mpll;
typedef map<int,int>    mpii;
typedef map<string,ll>  mpsl;
typedef multiset<int>   si;
typedef multiset<ll>    sl;
typedef multiset<string>ss;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	// your code goes here
	int test;
	cin>>test;
	while(test--)
	{
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;

	    cout<<a+b<<"\n";
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define up(s) transform(string s.begin(),string s.end(),string s.begin(), ::toupper)
#define PI 3.1415926535897932384626
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<string>  vs;
typedef map<ll,ll>      mpll;
typedef map<int,int>    mpii;
typedef map<string,ll>  mpsl;
typedef multiset<int>   si;
typedef multiset<ll>    sl;
typedef multiset<string>ss;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	// your code goes here
	int test;
	cin>>test;
	while(test--)
	{
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    if(a==d && b==c)cout<<a+b<<"\n";
	    else
	    {
    	    int ar[3];
    	    ar[0]=a+1+c;
    	    ar[1]=a+b;
    	    ar[2]=c+d;
    	    sort(ar,ar+3);
    	    cout<<ar[1]<<"\n";
	    }
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define up(s) transform(string s.begin(),string s.end(),string s.begin(), ::toupper)
#define PI 3.1415926535897932384626
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<string>  vs;
typedef map<ll,ll>      mpll;
typedef map<int,int>    mpii;
typedef map<string,ll>  mpsl;
typedef multiset<int>   si;
typedef multiset<ll>    sl;
typedef multiset<string>ss;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	// your code goes here
	int test;
	cin>>test;
	while(test--)
	{
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    int mi=min(a+b,a+c);
	    cout<<mi<<"\n";
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define up(s) transform(string s.begin(),string s.end(),string s.begin(), ::toupper)
#define PI 3.1415926535897932384626
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<string>  vs;
typedef map<ll,ll>      mpll;
typedef map<int,int>    mpii;
typedef map<string,ll>  mpsl;
typedef multiset<int>   si;
typedef multiset<ll>    sl;
typedef multiset<string>ss;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	// your code goes here
	int test;
	cin>>test;
	while(test--)
	{
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    if(a==d)cout<<a+b<<"\n";
	    else
	    {
    	    int ar[3];
    	    ar[0]=a+1+c;
    	    ar[1]=a+b;
    	    ar[2]=c+d;
    	    sort(ar,ar+3);
    	    cout<<ar[1]<<"\n";
	    }
	}
	return 0;
}


/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    for0(i,n)   for(int (i)=0; (i) < (n); (i)++)
#define    sp          fixed << setprecision
#define    all(x)      x.begin(),x.end()
#define    power(n,p)  pow_mod(n, p, (1LL<<62))
#define    yes         printf("YES\n")
#define    no          printf("NO\n")

// ===================== DEBUG  ==========================
#ifdef dhimanpc
template<typename T>void showSTL(T H);template<typename T,typename V>void showSTL(pair<T,V> H);
template<typename T>void showSTL(priority_queue<T> H);template<typename T>void showSTL(stack<T> H);
template<typename T,typename V>void showSTL(map<T,V> H);
template<typename T,typename V>void showSTL(multimap<T,V> H);template<typename T>void showSTL(vector<T> H);
template<typename T>void showSTL(set<T> H);template<typename T>void showSTL(multiset<T> H);
template<typename T>void showSTL(list<T> H);void showSTL(char *H);
template<typename T>void showSTL(deque<T> H);template<typename T>void showSTL(queue<T> H);
template<typename T>void showSTL(T H){stringstream ss;ss<<H;cerr<<ss.str();}
template<typename T,typename V>void showSTL(pair<T,V> H){cerr<<"(";showSTL(H.first);cerr<<"=>";showSTL(H.second);cerr<<")";}
template<typename T>void showSTL(priority_queue<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}cerr<<endl;}
template<typename T>void showSTL(stack<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}}
template<typename T,typename V>void showSTL(map<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T,typename V>void showSTL(multimap<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T>void showSTL(vector<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(set<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(multiset<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(list<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
void showSTL(char *H){for(int i=0;i<strlen(H);i++){showSTL(H[i]);};}
template<typename T>void showSTL(deque<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(queue<T> H){cerr<<"[ ";while(!H.empty()){showSTL(H.front());cerr<<' ';H.pop();}cerr<<"]";}
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM)
{cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << "):";
cerr<<" "<<args[idx]<<" = ";showSTL(H);dbg_out(args,idx+1,LINE_NUM, T...);}
#define    debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define    in_file freopen("input.c", "r", stdin)
#define    out_file freopen("output.c", "w", stdout)
#define    fast        0
#else
#define    debug(...)  0
#define    in_file     0
#define    out_file    0
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

void dhimanda();
// ===================== Main function ==========================
int main()
{
    //in_file;
    //out_file;
    //fast;
    int t=1;
    scanf("%d" , &t);
    forr(i,1,t){
        //printf("Case %d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    int a,b,c,d;
    cin >> a >> b >> c  >> d;
    cout << (a+c) - (d-1) << endl;
}

// Contact : chessdhiman@gmail.com


/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    for0(i,n)   for(int (i)=0; (i) < (n); (i)++)
#define    sp          fixed << setprecision
#define    all(x)      x.begin(),x.end()
#define    power(n,p)  pow_mod(n, p, (1LL<<62))
#define    yes         printf("YES\n")
#define    no          printf("NO\n")

// ===================== DEBUG  ==========================
#ifdef dhimanpc
template<typename T>void showSTL(T H);template<typename T,typename V>void showSTL(pair<T,V> H);
template<typename T>void showSTL(priority_queue<T> H);template<typename T>void showSTL(stack<T> H);
template<typename T,typename V>void showSTL(map<T,V> H);
template<typename T,typename V>void showSTL(multimap<T,V> H);template<typename T>void showSTL(vector<T> H);
template<typename T>void showSTL(set<T> H);template<typename T>void showSTL(multiset<T> H);
template<typename T>void showSTL(list<T> H);void showSTL(char *H);
template<typename T>void showSTL(deque<T> H);template<typename T>void showSTL(queue<T> H);
template<typename T>void showSTL(T H){stringstream ss;ss<<H;cerr<<ss.str();}
template<typename T,typename V>void showSTL(pair<T,V> H){cerr<<"(";showSTL(H.first);cerr<<"=>";showSTL(H.second);cerr<<")";}
template<typename T>void showSTL(priority_queue<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}cerr<<endl;}
template<typename T>void showSTL(stack<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}}
template<typename T,typename V>void showSTL(map<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T,typename V>void showSTL(multimap<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T>void showSTL(vector<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(set<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(multiset<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(list<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
void showSTL(char *H){for(int i=0;i<strlen(H);i++){showSTL(H[i]);};}
template<typename T>void showSTL(deque<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(queue<T> H){cerr<<"[ ";while(!H.empty()){showSTL(H.front());cerr<<' ';H.pop();}cerr<<"]";}
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM)
{cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << "):";
cerr<<" "<<args[idx]<<" = ";showSTL(H);dbg_out(args,idx+1,LINE_NUM, T...);}
#define    debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define    in_file freopen("input.c", "r", stdin)
#define    out_file freopen("output.c", "w", stdout)
#define    fast        0
#else
#define    debug(...)  0
#define    in_file     0
#define    out_file    0
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

void dhimanda();
// ===================== Main function ==========================
int main()
{
    //in_file;
    //out_file;
    //fast;
    int t=1;
    scanf("%d" , &t);
    forr(i,1,t){
        //printf("Case %d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(b==c) cout << c+d << endl;
    else cout << c+d+1 << endl;
}

// Contact : chessdhiman@gmail.com


/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    for0(i,n)   for(int (i)=0; (i) < (n); (i)++)
#define    sp          fixed << setprecision
#define    all(x)      x.begin(),x.end()
#define    power(n,p)  pow_mod(n, p, (1LL<<62))
#define    yes         printf("YES\n")
#define    no          printf("NO\n")

// ===================== DEBUG  ==========================
#ifdef dhimanpc
template<typename T>void showSTL(T H);template<typename T,typename V>void showSTL(pair<T,V> H);
template<typename T>void showSTL(priority_queue<T> H);template<typename T>void showSTL(stack<T> H);
template<typename T,typename V>void showSTL(map<T,V> H);
template<typename T,typename V>void showSTL(multimap<T,V> H);template<typename T>void showSTL(vector<T> H);
template<typename T>void showSTL(set<T> H);template<typename T>void showSTL(multiset<T> H);
template<typename T>void showSTL(list<T> H);void showSTL(char *H);
template<typename T>void showSTL(deque<T> H);template<typename T>void showSTL(queue<T> H);
template<typename T>void showSTL(T H){stringstream ss;ss<<H;cerr<<ss.str();}
template<typename T,typename V>void showSTL(pair<T,V> H){cerr<<"(";showSTL(H.first);cerr<<"=>";showSTL(H.second);cerr<<")";}
template<typename T>void showSTL(priority_queue<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}cerr<<endl;}
template<typename T>void showSTL(stack<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}}
template<typename T,typename V>void showSTL(map<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T,typename V>void showSTL(multimap<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T>void showSTL(vector<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(set<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(multiset<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(list<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
void showSTL(char *H){for(int i=0;i<strlen(H);i++){showSTL(H[i]);};}
template<typename T>void showSTL(deque<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(queue<T> H){cerr<<"[ ";while(!H.empty()){showSTL(H.front());cerr<<' ';H.pop();}cerr<<"]";}
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM)
{cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << "):";
cerr<<" "<<args[idx]<<" = ";showSTL(H);dbg_out(args,idx+1,LINE_NUM, T...);}
#define    debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define    in_file freopen("input.c", "r", stdin)
#define    out_file freopen("output.c", "w", stdout)
#define    fast        0
#else
#define    debug(...)  0
#define    in_file     0
#define    out_file    0
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

void dhimanda();
// ===================== Main function ==========================
int main()
{
    //in_file;
    //out_file;
    //fast;
    int t=1;
    scanf("%d" , &t);
    forr(i,1,t){
        //printf("Case %d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << a+b << endl;
}

// Contact : chessdhiman@gmail.com


#include <iostream>
using namespace std;
int main()
{
    int t;
    cin >> t ;
    while(t--) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        cout << max(a+b,c+d) << endl;
    }
    return 0;
}


/// Coded by Dhiman Sarker Bappi (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define    F           first
#define    S           second
#define    pb          push_back
#define    popb        pop_back
#define    pf          push_front
#define    popf        pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi          2*acos(0)
#define    elif        else if
#define    ll          long long
#define    nl          '\n'
#define    endl        '\n'
#define    forr(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define    for0(i,n)   for(int (i)=0; (i) < (n); (i)++)
#define    sp          fixed << setprecision
#define    all(x)      x.begin(),x.end()
#define    power(n,p)  pow_mod(n, p, (1LL<<62))
#define    yes         printf("YES\n")
#define    no          printf("NO\n")

// ===================== DEBUG  ==========================
#ifdef dhimanpc
template<typename T>void showSTL(T H);template<typename T,typename V>void showSTL(pair<T,V> H);
template<typename T>void showSTL(priority_queue<T> H);template<typename T>void showSTL(stack<T> H);
template<typename T,typename V>void showSTL(map<T,V> H);
template<typename T,typename V>void showSTL(multimap<T,V> H);template<typename T>void showSTL(vector<T> H);
template<typename T>void showSTL(set<T> H);template<typename T>void showSTL(multiset<T> H);
template<typename T>void showSTL(list<T> H);void showSTL(char *H);
template<typename T>void showSTL(deque<T> H);template<typename T>void showSTL(queue<T> H);
template<typename T>void showSTL(T H){stringstream ss;ss<<H;cerr<<ss.str();}
template<typename T,typename V>void showSTL(pair<T,V> H){cerr<<"(";showSTL(H.first);cerr<<"=>";showSTL(H.second);cerr<<")";}
template<typename T>void showSTL(priority_queue<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}cerr<<endl;}
template<typename T>void showSTL(stack<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}}
template<typename T,typename V>void showSTL(map<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T,typename V>void showSTL(multimap<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T>void showSTL(vector<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(set<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(multiset<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(list<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
void showSTL(char *H){for(int i=0;i<strlen(H);i++){showSTL(H[i]);};}
template<typename T>void showSTL(deque<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(queue<T> H){cerr<<"[ ";while(!H.empty()){showSTL(H.front());cerr<<' ';H.pop();}cerr<<"]";}
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM)
{cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << "):";
cerr<<" "<<args[idx]<<" = ";showSTL(H);dbg_out(args,idx+1,LINE_NUM, T...);}
#define    debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define    in_file freopen("input.c", "r", stdin)
#define    out_file freopen("output.c", "w", stdout)
#define    fast        0
#else
#define    debug(...)  0
#define    in_file     0
#define    out_file    0
#define    fast        ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
// ===================== custom function ==========================
ll pow_mod(ll nn, ll pp, ll mm) { ll res = 1; while(pp > 0) { if(pp&1) res = (res * nn) % mm; pp = pp >> 1; nn = (nn * nn) % mm; } return res; }

void dhimanda();
// ===================== Main function ==========================
int main()
{
    //in_file;
    //out_file;
    //fast;
    int t=1;
    scanf("%d" , &t);
    forr(i,1,t){
        //printf("Case %d: ", i);
        dhimanda();
    }
    return 0;
}
void dhimanda(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x  = a+c;
    if(b==c and a==d) cout << x << endl;
    else cout << x - 1 << endl;
}

// Contact : chessdhiman@gmail.com


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a + c + abs(a - b) + abs(c - d) + 1) / 2 << '\n';
}

int main(){
    speed();
    int t = 1;
    cin >> t;
    while(t--)solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a + b + c + d + 1) / 2 << '\n';
}

int main(){
    speed();
    int t = 1;
    cin >> t;
    while(t--)solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    // a +      b+
    // c +      d+
    //
    cout << abs(a - b) + abs(c - d) + 1 << '\n';
}

int main(){
    speed();
    int t = 1;
    cin >> t;
    while(t--)solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    // a +      b+
    // c +      d+
    //
    cout << max(a + b, c + d) << '\n';
}

int main(){
    speed();
    int t = 1;
    cin >> t;
    while(t--)solve();
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    while(t-->0){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int m1=a+b;
        int m2=c+d;
        if(m1>m2){
            cout<<m1;
        }
        else{
            cout<<m2;
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t-->0){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int m1=a+b;
        int m2=c+d;
        if(m1>m2){
            cout<<m1;
        }
        else{
            cout<<m2;
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
typedef       long long int      ll;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD                1000000007
#define       inf                ll(1e18)
#define       PI                 acos(-1.0)
#define       eps                1e-9
int main(void)
{
   optimize
   ll t,a,b,c,d;
   cin>>t;
   while(t--)
   {
      cin>>a>>b>>c>>d;
      cout<<a+b<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
typedef       long long int      ll;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD                1000000007
#define       inf                ll(1e18)
#define       PI                 acos(-1.0)
#define       eps                1e-9
int main(void)
{
   optimize
   ll t,a,b,c,d;
   cin>>t;
   while(t--)
   {
      cin>>a>>b>>c>>d;
      cout<<min(a+b,a+c)<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
typedef       long long int      ll;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD                1000000007
#define       inf                ll(1e18)
#define       PI                 acos(-1.0)
#define       eps                1e-9
int main(void)
{
   optimize
   ll t,a,b,c,d;
   cin>>t;
   while(t--)
   {
      cin>>a>>b>>c>>d;
      cout<<max(a+b,c+d)<<endl;
   }
   return 0;
}


#include<bits/stdc++.h>
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
typedef       long long int      ll;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD                1000000007
#define       inf                ll(1e18)
#define       PI                 acos(-1.0)
#define       eps                1e-9
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return ((a%m)+m)%m; else if(a<m) return a; else return (a%m); }

bool cmp(pair<int,int>a, pair<int,int>b)
{
   if(a.first==b.first)
      return a.second<b.second;
   else
      return a.first<b.first;
}
int main(void)
{
   optimize
   ll t,n,m,k,x,y,a,b,c,d;
   vector<ll> v,v1,v2;
   vector< pair<ll,ll> > p,p1,p2;
   set<ll> st;
   map<ll,ll> mp;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair<ll,ll> > > plpq;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>a>>b>>c>>d;
      if(a+c==b+d)
         cout<<a+c<<endl;
      else
      {
         cout<<a+b<<endl;
      }
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 1000000000
#define mod 1000000007
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
	speedup
	int t=1;
	cin>>t;
	while(t--){
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    cout<<min(a+b,c+d)<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 1000000000
#define mod 1000000007
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
	speedup
	int t=1;
	cin>>t;
	while(t--){
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    cout<<a+b<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 1000000000
#define mod 1000000007
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
	speedup
	int t=1;
	cin>>t;
	while(t--){
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    cout<<max(a+b,c+d)<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 1000000000
#define mod 1000000007
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
	speedup
	int t=1;
	cin>>t;
	while(t--){
	    int a,b,c,d;
	    cin>>a>>b>>c>>d;
	    cout<<((a+b+c+d)+1)/2<<endl;
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
const double PI=acos(-1.0);
typedef unsigned long long ull;
typedef long long ll;
using namespace __gnu_pbds;
ll power(ll n,ll y){
    if(y==0)
        return 0;
    else if(y==1)
        return n;
    ll r=power(n,y/2);
    if(y%2==0)
        return r*r;
    else
        return r*r*n;
}
ll lcm(ll a,ll b){
    return max(a,b)/__gcd(a,b)*min(a,b);
}
#define swapG(x,y) if(x<y) swap(x,y)
#define swapS(x,y) if(x>y) swap(x,y)
#define endl '\n'
#define all(v) ((v).begin()), ((v).end())
#define allR(v) ((v).rbegin()), ((v).rend())
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void A(){
    int n,x;
    cin>>n;
    cin>>x;
    vector <int>a(n);
    vector <int>b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    sort(allR(b));
    bool check=true;
    for(int i=0;i<n;i++){
        if(a[i]+b[i]>x) {
            check=0;
            break;
        }
    }
    if(check) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
void B(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans1=a+b;
    ll ans2=c+d;
    cout<<max(ans1,ans2)<<endl;
}
int main()
{
    int t;cin>>t;
    while(t--){
        B();
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    cout<<"a";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define all v.begin(),v.end()
#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int main()
{
	fastio

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin >> T;

	while (T-- > 0)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		std::vector<int> v;

		v.pb(a + b);
		v.pb(c + d);
		v.pb(b + c);

		sort(all);

		cout << v[1] << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define all v.begin(),v.end()
#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int main()
{
	fastio

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin >> T;

	while (T-- > 0)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		cout << a + b << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define all v.begin(),v.end()
#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int main()
{
	fastio

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin >> T;

	while (T-- > 0)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		std::vector<int> v;

		v.pb(a + b);
		v.pb(c + d);
		v.pb(a + 1 + c);

		sort(v.begin(), v.end(), greater<>());

		cout << v[1] << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define all v.begin(),v.end()
#define mod 1000000007
#define ps(x,y) fixed << setprecision(y) << x
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int main()
{
	fastio

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin >> T;

	while (T-- > 0)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		std::vector<int> v;

		v.pb(a + b);
		v.pb(c + d);
		v.pb(b + c);

		sort(v.begin(), v.end(), greater<>());

		cout << v[1] << '\n';
	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int p,q;
        cin>>p>>q;
        if(p%q!=0)
            cout<<p<<endl;
        else
        {
            for(int i=q-1;i>=q/2;i--)
            {
                if(p%i==0)
                {
                    cout<<i<<endl;
                    break;
                }
            }
        }

    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;

        if((a+b)>=(c+d))
            cout<<a+b<<endl;
        else
            cout<<c+d<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;

        if((a+b)>=(c+d))
            cout<<a+b<<endl;;
        else
            cout<<c+d<<endl;
    }
    return 0;
}


#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
typedef long long ld;
typedef long long ll;
struct pt{
    ld x;
    ld y;
};
ll pow(ll a, ll b){
    if(b == 0) return 1;
    ll c = pow(a , b / 2);
    c = c * c;
    if(b%2) c *= a;
    return c;
}
ll min(ll a , ll b){
    return a < b ? a : b;
}
ll solve(){

    ll a , b , c , n, m , d;
    cin >> a >> b >> c >> d;
    cout << a+ b << endl;

    return 0;
}

int main(){
    int t;
    cin >> t;
    while (t --) {
        solve();
    }
}


#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
typedef long long ld;
typedef long long ll;
struct pt{
    ld x;
    ld y;
};
ll pow(ll a, ll b){
    if(b == 0) return 1;
    ll c = pow(a , b / 2);
    c = c * c;
    if(b%2) c *= a;
    return c;
}
ll min(ll a , ll b){
    return a < b ? a : b;
}
ll solve(){

    ll a , b , c , n, m , d;
    cin >> a >> b >> c >> d;
    ll v[3];
    v[0] = a + c + 1;
    v[1] = a + b;
    v[2] = d + c;
    sort(v , v + 3);
    cout << v[1] << endl;

    return 0;
}

int main(){
    int t;
    cin >> t;
    while (t --) {
        solve();
    }
}


#include<iostream>
#include<math.h>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long ld;
typedef long long ll;
struct pt{
    ld x;
    ld y;
};
ll pow(ll a, ll b){
    if(b == 0) return 1;
    ll c = pow(a , b / 2);
    c = c * c;
    if(b%2) c *= a;
    return c;
}
ll min(ll a , ll b){
    return a < b ? a : b;
}
ll solve(){

    ll a , b , c , n, m , d;
    cin >> a >> b >> c >> d;
    ll v[3];
    v[0] = a + c + 1;
    v[1] = a + b;
    v[2] = d + c;
    sort(v , v + 3);
    cout << v[1] << endl;

    return 0;
}

int main(){
    int t;
    cin >> t;
    while (t --) {
        solve();
    }
}


#include<bits/stdc++.h>
#define maxn
#define rg register
#define ll long long
using namespace std;
inline void read(int &x){
	int f=1;x=0;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	x*=f;
}
signed main(){
	rg int T,a,b,c,d;
	read(T);
	while (T--){
		read(a);read(b);read(c);read(d);
		printf("%d\n",min(a+b,c+d));
	}
	return 0;
}


#include<bits/stdc++.h>
#define maxn
#define rg register
#define ll long long
using namespace std;
inline void read(int &x){
	int f=1;x=0;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	x*=f;
}
signed main(){
	rg int T,a,b,c,d;
	read(T);
	while (T--){
		read(a);read(b);read(c);read(d);
		printf("%d\n",max(a+b,c+d));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 200100
int t,a,b,c,d;
int main()
{
	cin>>t;
	while(t--) {
		cin>>a>>b>>c>>d;
		cout<<max(a + b,c + d);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 200100
int t,a,b,c,d;
int main()
{
	cin>>t;
	while(t--) {
		cin>>a>>b>>c>>d;
		cout<<max(a + b,c + d)<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
signed main(){
	int T=read();
	while(T--){
		printf("%d\n",read()+read());
		read();read();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
signed main(){
	int T=read();
	while(T--){
		int a=read(),b=read(),c=read(),d=read();
		printf("%d\n",b+c-d-a+1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
signed main(){
	int T=read();
	while(T--){
		int a=read(),b=read(),c=read(),d=read();
		printf("%d\n",max(a+b,c+d));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t
	scanf("%d",&t);
	int a,b,c,d;
	while(t--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a+b,c+d));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    for(int step=1;step<=t;step++)
    {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        printf("%d\n",max(a+b,c+d));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	int a,b,c,d;
	while(t--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",max(a+b,c+d));
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

    int t,a,b,c,d;
    cin >> t;
    for (int i = 0 ; i < t ; i++) {
        cin >> a >> b >> c >> d;
        cout << max(a+b, c+d);
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
pair<string,int> find(int ind) {
	if(done) {
		return mp(string(),0);
	}
	if(ind>=sz(tokens)) {
		cout<<"Error occurred"<<endl;
		done = true;
	}
	if(tokens[ind]=="int") return pair<string,int>(tokens[ind],ind+1);
	else {
		string ret = "pair<";
		pair<string,int> p = find(ind+1);
		pair<string,int> p2 = find(ind+2);
		ret+=p.fi+","+p2.fi+">";
		return mp(ret,p2.se);
	}
}
int main() {
	int n=  nextInt();
	int c=  0;
	while(c<n) {
		string n = next();
		if(n=="int") {
			c++;
		}
		tokens.pb(n);
	}
	pair<string,int> p = find(0);
	if(!done&&p.se==sz(tokens)) cout<<p.fi<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
string ret;
int find(int ind) {
	if (ind >= sz(tokens)) {
		done = true;
	}
	if (done) {
		return 0;
	}
	if (tokens[ind] == "int") {
		ret += "int";
		return ind + 1;
	} else {
		ret += "pair<";
		int p = find(ind + 1);
		ret += ",";
		int p2 = find(p);
		ret += ">";
		return p2;
	}
}
int main() {
	int n = nextInt();
	int c = 0;
	while (c < n) {
		string n = next();
		if (n == "int") {
			c++;
		}
		tokens.pb(n);
	}
	string s = next();
	if (find(0) == sz(tokens) && !done&&!sz(s)) {
		cout << ret << endl;
	} else {
		cout << "Error occurred" << endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
string bro() {
	int n = nextInt();
	int c = 1, c2 = 0;
	string s, sep;
	string ret;
	while (c2 < n) {
		if ((s = next()) == "pair") {
			sep = "<";
			c++;
		} else {
			if (sep == "<")
				sep = ",";
			else
				sep = ">,";
			c--;
			c2++;
		}
		if (c < 0) {
			return "Error occurred";
		}
		ret += s;
		ret += sep;
	}
	if (c)
		return "Error occurred";
	return ret.substr(0, ret.size() - 1);
}

int main() {
	cout << bro() << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
pair<string, int> find(int ind) {
	if (ind >= sz(tokens)) {
		done = true;
	}
	if (done) {
		return mp(string(), 0);
	}
	if (tokens[ind] == "int")
		return pair<string, int>(tokens[ind], ind + 1);
	else {
		string ret = "pair<";
		pair<string, int> p = find(ind + 1);
		pair<string, int> p2 = find(p.se);
		ret += p.fi + "," + p2.fi + ">";
		return mp(ret, p2.se);
	}
}
int main() {
	int n = nextInt();
	int c = 0;
	while (c < n) {
		string n = next();
		if (n == "int") {
			c++;
		}
		tokens.pb(n);
	}
	pair<string, int> p = find(0);
	if (!done&&p.se==sz(tokens)) {
		cout << p.fi<<endl;
	}
	else {
		cout<<"Error occurred"<<endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
string ret;
int find(int ind) {
	if (ind >= sz(tokens)) {
		done = true;
	}
	if (done) {
		return 0;
	}
	if (tokens[ind] == "int") {
		ret += "int";
		return ind + 1;
	} else {
		ret += "pair<";
		int p = find(ind + 1);
		ret += ",";
		int p2 = find(p);
		ret += ">";
		return p2;
	}
}
int main() {
	int n = nextInt();
	int c = 0;
	while (c < n) {
		string n = next();
		if (n == "int") {
			c++;
		}
		tokens.pb(n);
	}
	if (find(0) == sz(tokens) && !done&&!cin) {
		cout << ret << endl;
	} else {
		cout << "Error occurred" << endl;
	}
}