#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include<queue>
using namespace std;
int ok=0;
int k;
int f[10][10];
struct node
{
int x,y;
};
node trackk[50][50];
queue <node> qq;
node point,father;
bool cmp(int a,int b)
{
return (a>b);
}
int legal(int r, int c)
{
if ( r>=1 && r<=5 && c>=1 &&a
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include<queue>
using namespace std;
int ok=0;
int k;
int f[10][10];
struct node
{
int x,y;
};
node trackk[50][50];
queue <node> qq;
node point,father;
bool cmp(int a,int b)
{
return (a>b);
}
int legal(int r, int c)
{
if ( r>=1 && r<=5 && c>=1 &&a