#include <iostream>
#include <cstdio>
typedef long long LL;
using namespace std;
LL exp(LL a, LL b)
{
LL res = 1;
while (b)
{
if (b & 1)
res *= a;
a *= a;
b >>= 1;
}
return res;
}
LL exgcd(LL a, LL b, LL &x, LL &y)
{
if (!b)
{
x = 1, y = 0;
return a;
}
LL res = exgcd(b, a%b, y, x);
y -= a/b * x;
return res;
}
int main()
{
LL a, b, c, k, x, y;
while (scanf("%lld%lld%lld%lld", &a, &b, &c, &k) && a+b+c+k)
{
LL p = exp(2, k);
LL gcd = exgcd(c, p, x, y);
// printf("%lld*%lld + %lld*%lld = %lld\n", c, x, p, y, gcd);
if ((b-a)%gcd)
puts("FOREVER");
else
{
x *= (b-a) / gcd;
p /= gcd;
printf("%lld\n", (x%p+p)%p);
}
}
return 0;
}