#include<cstdio>
#define LL long long
using namespace std;
LL extgcd(LL a,LL b,LL &x,LL &y)
{
int d=a;
if(b!=0)
{
d=extgcd(b,a%b,y,x);
y-=(a/b)*x;
}
else
{
x=1;y=0;
}
return d;
}
int main()
{
LL a,b,c,k,res,d,t,x,y,m;
while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&k))
{
if(a==0&&b==0&&c==0&&k==0)
break;
m=(LL)1<<k;
d=extgcd(c,m,x,y);
// printf("%d %d %d %d\n",c,m,x,y);
res=b-a;
if(res%d)
{
printf("FOREVER\n");
continue;
}
else
{
x=x*res/d;
t=m/d;
x=(x%t+t)%t;
printf("%lld\n",x);
}
}
}