/*
n=2^k给你三个数满足(a+c*t)%n=b,q求t,
即c*t+x*n==b-a, (式子1)
可以发现满足扩展欧几里德的定理,
则x*c+n*y=d; (式子2)
if((b-a+n)%n % d !=0) ,无解。。
else t=(x/d)*(b-a);
*/
#include"stdio.h"
#include"string.h"
typedef long long LL;
//typedef __int64 LL;
LL x,y,d;
void exgcd(LL a,LL b)
{
if(b==0)
{
x=1;y=0;d=a;
}
else
{
exgcd(b,a%b);
LL t=x;
x=y;
y=t-(a/b)*y;
}
}
int main()
{
LL a,b,c,k;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k)!=-1)
{
if(a==0&&b==0&&c==0&&k==0)break;
if(a==b)
{
printf("0\n");
continue;
}
LL n=1;
for(int i=0;i<k;i++)
n*=2;
LL ans=(b-a+n)%n;
exgcd(c,n);
if(ans%d)
printf("FOREVER\n");
else
{
ans/=d;
c/=d;
n/=d;
x=x*ans;
x%=n;
if(x<0)x=(x+n)%n;
printf("%I64d\n",x);
}
}
return 0;
}