要么直接到,要么经过一个中间点再到
数据量很小,只有100个数,枚举0—99 把当前点当作中间点 取最小的
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=100+5;
const int INF=0x3f3f3f3f;
int a[maxn],up,down,fast;
int check(int x,int y)
{
if(x==y)return 0;
if(y>=0&&y<=9&&a[y])return 1;
if(y>=10&&a[y/10]&&a[y%10]&&fast)return 3;
return INF;
}
int go(int a,int b)
{
if(a==b)return 0;
int ans1=INF;int ans2=INF;
if(up)
{
if(a<b)ans1=b-a;
else ans1=100-a+b;
}
if(down)
{
if(a<b)ans2=100-b+a;
else ans2=a-b;
}
return min(ans1,ans2);
}
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int ans=INF;
cin>>a[1]>>a[2]>>a[3]>>up>>a[4]>>a[5]>>a[6]>>down>>a[7]>>a[8]>>a[9]>>fast>>a[0];
int x,y;scanf("%d%d",&x,&y);
for(int i=0;i<=99;i++)
{
ans=min(ans,check(x,i)+go(i,y));
}
cout<<(ans==INF?-1:ans)<<endl;
}
}