#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
const long long mod=9973;
long long gcd(long long a,long long b){
if(!b) return a;
return gcd(b,a%b);
}
void exgcd(long long a,long long &x,long long b,long long &y){
if(!b){
x=1;
y=0;
}
else{
exgcd(b,y,a%b,x);
y-=x*(a/b);
}
}
int main(){
long long A,B,C,K,L,x,y,a,b,c;
while(cin>>A>>B>>C>>K){
if(A==0&&B==0&&C==0&&K==0) break;
L=(long long)1<<K;
a=C;
b=L;
c=B-A;
long long temp=gcd(a,b);
if(c%temp)
cout<<"FOREVER"<<endl;
else{
exgcd(a,x,b,y);
x=x*(c/temp);
x%=b/temp;
while(x<0) {x+=b/temp;}
cout<<x<<endl;
}
}
return 0;
}