#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;

vector<int>E[1000];
int d[1000][1000];
int main() {
	int n;
	while(scanf("%d",&n),n){
		rep(i,n)E[i].clear();
		int s,t,m;scanf("%d%d%d",&s,&t,&m);s--;t--;
		vector<P>v;
		rep(i,m){
			int a,b;scanf("%d%d",&a,&b);a--;b--;
			v.push_back(P(a,b));
			E[a].push_back(b);
		}
		memset(d,0x3f,sizeof(d));
		rep(i,n){
			queue<int>que;
			d[i][i]=0;que.push(i);
			while(!que.empty()){
				int p=que.front();que.pop();
				for(int v:E[p]){
					if(d[i][v]==INF){
						d[i][v]=d[i][p]+1;que.push(v);
					}
				}
			}
		}
		int Min=d[s][t],id=0;
		rep(i,m){
			int a=d[s][v[i].second]+1+d[v[i].first][t];
			if(Min>a){
				Min=a;id=i+1;
			}
		}
		printf("%d %d\n",Min,id);
	}
}