#include<bits/stdc++.h>
using namespace std;
void solve() {
   int n,a,b,c,d;
   cin>>n>>a>>b>>c>>d;
   cout<<(a+b+c-d-n)/2<<endl;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
     int t;
     cin>>t;
     while(t--)
     {
    solve();
     }
    return 0;
}