#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fpow(ll a, ll b, ll m)
{
    ll r = 1;
    for (; b; b >>= 1, a = a * a % m)
        if (b & 1)
            r = r * a % m;
    return r;
}
int main()
{
    ll c, k1, k2, b1;
    for (int t = 1; ~scanf("%lld%lld%lld%lld", &c, &k1, &b1, &k2); t++)
    {
        printf("Case #%d:\n", t);
        bool flag = 0;
        for (ll i = 1, a, b; i < c; i++)
            if (fpow(a = i, k1, c) == fpow(b = c - fpow(a, k1 + b1, c), k2, c))
                printf("%lld %lld\n", a, b), flag = true;
        if (!flag)
            puts("-1");
    }
    return 0;
}