F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

������

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13531    Accepted Submission(s): 4049


Problem Description
��������һ���ܾ������Ϸ.������������һ���򵥰汾.��һ��M*N�ķ�������һ�����Ӻ�һ�����˹�,���˹��Ĺ������ǰ������Ƶ�ָ����λ��,ע��,���˹�ֻ�������Ӷ�����������,���������ӱ��Ƶ�һ������(��ͼ2)��ô���ӾͲ����ٱ��ƶ���,������ӱ��Ƶ�һ��ǽ��,��ô����ֻ������ǽ�ƶ�.

���ڸ�������Ľṹ,���ӵ�λ��,���˹���λ�ú�����Ҫ����ȥ��λ��,�����������˹�����Ҫ�ƶ����Ӷ��ٸ�.


 

Input
�������ݵĵ�һ����һ������T(1<=T<=20),�����������ݵ�����.Ȼ����T���������,ÿ��������ݵĵ�һ��������������M,N(2<=M,N<=7),��������Ĵ�С,Ȼ����һ��M��N�еľ���,��������IJ���,����0�����յĵذ�,1����ǽ,2�������ӵ���ʼλ��,3��������Ҫ����ȥ��λ��,4�������˹�����ʼλ��.
 

Output
����ÿ���������,������˹�������Ҫ�ƶ����Ӷ��ٸ���ܰ������Ƶ�ָ��λ��,��������Ƶ�ָ��λ�������-1.
 

Sample Input
1 5 5 0 3 0 0 0 1 0 1 4 0 0 0 1 0 0 1 0 2 0 0 0 0 0 0 0
 

Sample Output
4
 

Author
Ignatius.L & weigang Lee
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.001000(s) query 1, Server time : 2025-08-07 12:19:46, Gzip enabled