将两点从四个方向相连的距离分别计算,求最小值即可
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<cctype>
#define IOS std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define pi acos(-1);
#include<map>
using namespace std;
typedef struct node{
}node;
typedef long long ll;
void ccin(){
}
void work(){
}
int main(){
IOS;
ccin();
work();
int t;cin>>t;
while(t--){
int w,d,h,a,b,f,g;
cin>>w>>d>>h;
cin>>a>>b>>f>>g;
int ans=h+min(b+g,2*d-b-g)+abs(a-f);
ans=min(ans,h+min(a+f,2*w-a-f)+abs(b-g));
cout<<ans<<endl;
}
return 0;
}