#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL pm(LL a,LL n,LL p) {
	LL ret=1;
	n%=(p-1);  //
	for (a%=p;n;n>>=1,a=a*a%p)
		if (n&1) ret=ret*a%p;
	return ret;
}

LL C,k1,b1,k2;
int main() {
	for (int tt=1;~scanf("%lld%lld%lld%lld",&C,&k1,&b1,&k2);tt++) {
		vector<pair<LL,LL> > ans;
		for (LL a=1;a<C;a++) {
			LL b=(C-pm(a,k1+b1,C))%C;
			if (!b) continue;
			if (pm(a,k1,C)!=pm(b,k2,C)) continue;
			ans.push_back(make_pair(a,b));
		}
		sort(ans.begin(),ans.end());

		printf("Case #%d:\n",tt);
		if (ans.size())
			for (auto &x:ans) printf("%lld %lld\n",x.first,x.second);
		else puts("-1");
	}
	return 0;
}