int main()
{
    int kase,F,T,d[10009],u,i;
    sieve(10002);
    scanf("%d",&kase);
    while(kase--)
    {
      scanf("%d %d",&F,&T);
      bool vis[10009]={0};
      q.push(F);
      d[F]=0;
      vis[F]=1;
      while(!q.empty())
      {
        u=q.front();
        q.pop();
        for(i=0;i<c;i++)
        {
         if(!vis[a[i]])
          if(check(u,a[i]))
          d[a[i]]=d[u]+1,q.push(a[i]),vis[a[i]]=1;
        }
      }
      if(vis[T])
       printf("%d\n",d[T]);
      else
       printf("Impossible\n");
    }
    return 0;
}
void bfs(long start)
{
	long i,next,u;
	d[start]=0;
	vis[start]=1;
	q.push(start);
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(i=0;i<gr[u].size();i++)
		{
			next=gr[u][i];
			if(!vis[next])
			{
				q.push(next);
				vis[next]=1;
				d[next]=d[u]+1;
			}
		}
	}
}
long bfs(long start)
{
    long i,u,next,count=0;
    vis[start]=true;
    q.push(start);
    while(!q.empty())
    {
		count++;
		u=q.front();
        q.pop();
        for(i=0; i<gr[u].size(); i++)
        {
            next=gr[u][i];
            if(vis[next]==false)
            {
				
                q.push(next);
                vis[next]=true;
            }    
        }
    }
	
    return count;
}