#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
namespace treap {
	struct node {
		int prior, sz, dp, add;
		node *l, *r;
		node(int x) {
			prior = (rand() << 15) | rand();
			// sz = 1;
			dp = x;
			l = r = NULL;
			add = 0;
		}
	};

	typedef node * pnode;

	void push(node* T) {
		T->dp += T->add;
		if (T->l)
			T->l->add += T->add;
		if (T->r)
			T->r->add += T->add;
		T->add = 0;
	}

	node* merge(node * L, node * R) {
		if (!L) {
			return R;
		}
		if (!R) {
			return L;
		}
		if (L->prior > R->prior) {
			push(L);
			L->r = merge(L->r, R);
			return L;
		}
		else {

			push(R);
			R->l = merge(L, R->l);
			return R;

		}
	}

	pair<node*,node*> split(pnode T, int value) {
		if (!T) {
			return make_pair(nullptr,nullptr);
		}
		push(T);
		if (T->dp >= value) {
			auto p=split(T->l, value);
			T->l=p.second;
			return make_pair(p.first,T);
		}
		else {

			auto p = split(T->r, value);
			T->r = p.first;
			return make_pair(T, p.second);
		}
	}

	int findBegin(pnode T) {
		push(T);
		if (!T->l)
			return T->dp;
		return findBegin(T->l);
	}

	int findMax(pnode T, int n) {
		if (!T)
			return 0;
		push(T);
		return findMax(T->l, n) + findMax(T->r, n) + (T->dp <= 1e9 ? 1 : 0);
	}


}
#include<random>

vector<int>dfs(const vector<vector<int>>&edges, const int start) {
	vector<int>memo(edges.size(),1e9);
	memo[start]=0;
	queue<int>que;
	que.emplace(start);
	while (!que.empty()) {
		const int now=que.front();
		que.pop();
		for (auto e : edges[now]) {
			if (memo[e] > memo[now] + 1) {
				memo[e]=memo[now]+1;
				que.emplace(e);
			}
		}
	}
	return memo;
}

int main() {
	int N;
	while (cin >> N,N) {


		int S, T; cin >> S >> T;
		S--; T--;
		int M; cin >> M;
		vector<vector<int>>edges(N);
		vector<vector<int>>rev_edges(N);
		map<pair<int, int>, int>mp;
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b;
			a--; b--;
			rev_edges[b].push_back(a);
			edges[a].push_back(b);
			if(mp.find(make_pair(a,b))==mp.end())mp[make_pair(a, b)] = i;
		}
		vector<int>from_ss = dfs(edges, S);
		vector<int>from_ts = dfs(rev_edges, T);

		pair<int, int>answer = make_pair(from_ss[T], -1);
		for (auto m : mp) {
			auto i = m.first.first;
			auto e = m.first.second;
			int sum = 1 + from_ss[e] + from_ts[i];
			answer = min(answer, make_pair(sum,m.second));

		}
		cout << answer.first << " " << answer.second+1 << endl;

	}
	return 0;
}


