![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6ea2ea98a816b3e8b0a6e5ac8fdd1402.png)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
const int N=2e5+5;
int n,m;
int f[N];
void dfs(int u,int deep){
if(u<10||u>300) return;
if(deep>f[u]) return;
f[u]=deep;
dfs(u-1,deep+1);
dfs(u+1,deep+1);
dfs(u+10,deep+1);
dfs(u-10,deep+1);
dfs(u+100,deep+1);
dfs(u-100,deep+1);
dfs(300,deep+1);
}
void solve(){
cin>>n;
for(int i=1;i<=300;i++){
f[i]=inf;
}
dfs(10,0);
for(int i=1;i<=n;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<f[a]+f[b]+f[c]+f[d]<<endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt=1;
while(tt--) solve();
return 0;
}