#include <iostream>
using namespace std;

int main() {
    string flags, a, b;
    cin >> flags >> a >> b;

    bool forward1 = false, forward2 = false, backward1 = false, backward2 = false;
    int i, end;
    for(i = 0, end = flags.length() - a.length(); i <= end; ++i) {
        forward1 = true;
        for(int j = 0, end = a.length(); j < end; ++j) {
            if(a[j] != flags[i + j]) {
                forward1 = false;
                break;
            }
        }

        if(forward1) {
            i = i + a.length();
            break;
        }
    }

    if(forward1) for(end = flags.length() - b.length(); i <= end; ++i) {
        forward2 = true;
        for(int j = 0, end = b.length(); j < end; ++j) {
            if(b[j] != flags[i + j]) {
                forward2 = false;
                break;
            }
        }

        if(forward2) break;
    }

    for(i = flags.length() - 1, end = a.length() - 1; i >= end; --i) {
        backward1 = true;
        for(int j = 0, end = a.length(); j < end; ++j) {
            if(a[j] != flags[i - j]) {
                backward1 = false;
                break;
            }
        }

        if(backward1) {
            i = i - a.length();
            break;
        }
    }

    for(end = b.length() - 1; i >= end; --i) {
        backward2 = true;
        for(int j = 0, end = b.length(); j < end; ++j) {
            if(b[j] != flags[i - j]) {
                backward2 = false;
                break;
            }
        }

        if(backward2) break;
    }

    bool forward = forward1 && forward2;
    bool backward = backward1 && backward2;

    if(forward && backward) cout << "both\n";
    else if(forward) cout << "forward\n";
    else if(backward) cout << "backward\n";
    else cout << "fantasy\n";

    // cout << forward1 << forward2 << backward1 << backward2;
}


#include <iostream>
using namespace std;

int main() {
    string flags, a, b;
    cin >> flags >> a >> b;

    bool forward, backward;
    for(int i = 0, end = flags.length() - a.length(); i <= end; ++i) {
        forward = true;
        for(int j = 0, end = a.length(); j < end; ++j) {
            if(a[j] != flags[i + j]) {
                forward = false;
                break;
            }
        }

        if(forward) break;
    }

    for(int i = flags.length() - 1, end = flags.length() - b.length(); i >= end; --i) {
        backward = true;
        for(int j = 0, end = b.length(); j < end; ++j) {
            if(b[j] != flags[i - j]) {
                backward = false;
                break;
            }
        }

        if(forward) break;
    }

    if(forward && backward) cout << "both\n";
    else if(forward) cout << "forward\n";
    else if(backward) cout << "backward\n";
    else cout << "fantasy\n";
}


#include <iostream>
using namespace std;

int main() {
    string flags, a, b;
    cin >> flags >> a >> b;

    bool forward1 = false, forward2 = false, backward1 = false, backward2 = false;
    int i, end;
    for(i = 0, end = flags.length() - a.length(); i <= end; ++i) {
        forward1 = true;
        for(int j = 0, end = a.length(); j < end; ++j) {
            if(a[j] != flags[i + j]) {
                forward1 = false;
                break;
            }
        }

        if(forward1) {
            i = i + a.length();
            break;
        }
    }

    if(forward1) for(end = flags.length() - b.length(); i <= end; ++i) {
        forward2 = true;
        for(int j = 0, end = b.length(); j < end; ++j) {
            if(b[j] != flags[i + j]) {
                forward2 = false;
                break;
            }
        }

        if(forward2) break;
    }

    for(i = flags.length() - 1, end = flags.length() - a.length(); i >= end; --i) {
        backward1 = true;
        for(int j = 0, end = a.length(); j < end; ++j) {
            if(a[j] != flags[i - j]) {
                backward1 = false;
                break;
            }
        }

        if(backward1) {
            i = i - a.length();
            break;
        }
    }

    if(backward1) for(end = b.length() - 1; i >= end; --i) {
        backward2 = true;
        for(int j = 0, end = b.length(); j < end; ++j) {
            if(b[j] != flags[i - j]) {
                backward2 = false;
                break;
            }
        }

        if(backward2) break;
    }

    bool forward = forward1 && forward2;
    bool backward = backward1 && backward2;

    if(forward && backward) cout << "both\n";
    else if(forward) cout << "forward\n";
    else if(backward) cout << "backward\n";
    else cout << "fantasy\n";

    // cout << forward1 << forward2 << backward1 << backward2;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
int main()
{
    IOS;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
string s,t;
bool check(string s1,string s2)
{
    int j=0;
    int i=0;
    int l=s.length();
    bool ok=false;
    for(i=0;i<l;i++)
    {
        if(s[i]==s1[j]){
            j++;
            if(j==s1.length()){
                ok=true;
                break;
            }
        }
    }
    if(ok==0)return 0;
    j=0;
    i++;
//    cout<<"i = "<<i<<endl;
    while(i<l)
    {
        if(s[i]==s2[j]){
            j++;
            if(j==s2.length())return true;
        }
        i++;
    }
    return false;
}
int main()
{
    IOS;
    while(1)
    {
        string s1,s2;
        cin>>s>>s1>>s2;
        t=s;
        reverse(t.begin(),t.end());
        if(check(s1,s2)){
            s=t;
            if(check(s1,s2))cout<<"both"<<endl;
            else cout<<"forward"<<endl;
        }
        else{
            s=t;
            if(check(s1,s2))cout<<"backward"<<endl;
            else cout<<"fantasy"<<endl;
        }
        break;
    }
}

/*
asfe
fs
a
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
bool check(string s,string s1,string s2)
{
    int j=0;
    int i=0;
    int l=s.length();
    bool ok=false;
    for(i=0;i<l;i++)
    {
        if(s[i]==s1[j]){
            j++;
            if(j==s1.length()){
                ok=true;
                break;
            }
        }
    }
    if(ok==0)return 0;
    j=0;
    i=0;
    while(i<l)
    {
        if(s[i]==s2[j]){
            j++;
            if(j==s2.length())return true;
        }
        i++;
    }
    return false;
}
int main()
{
    IOS;
    string s1,s2,s;
    cin>>s>>s1>>s2;
    string t=s;
    reverse(t.begin(),t.end());
    if(check(s,s1,s2)){
        if(check(t,s1,s2))cout<<"both"<<endl;
        else cout<<"forward"<<endl;
    }
    else if(check(t,s1,s2))cout<<"backward"<<endl;
    else cout<<"fantasy"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
bool check(string s,string s1,string s2)
{
    int j=0;
    int i=0;
    int l=s.length();
    bool ok=false;
    for(i=0;i<l;i++)
    {
        if(s[i]==s1[j]){
            j++;
            if(j==s1.length()){
                ok=true;
                break;
            }
        }
    }
    if(ok==0)return 0;
    j=0;
    while(i<l)
    {
        if(s[i]==s2[j]){
            j++;
            if(j==s2.length())return true;
        }
        i++;
    }
    return false;
}
int main()
{
    IOS;
    string s1,s2,s;
    cin>>s>>s1>>s2;
    string t=s;
    reverse(t.begin(),t.end());
    if(check(s,s1,s2)){
        if(check(t,s1,s2))cout<<"both"<<endl;
        else cout<<"forward"<<endl;
    }
    else if(check(t,s1,s2))cout<<"backward"<<endl;
    else cout<<"fantasy"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
int main()
{
    string s,s1,s2;
    bool fo=0,ba=0;
    cin>>s>>s1>>s2;
    if(s.find(s1)!=string::npos&&s.find(s2,s.find(s1)+s1.length())!=string::npos)fo=1;
    reverse(s.begin(),s.end());
    if(s.find(s1)!=string::npos&&s.find(s2,s.find(s1)+s1.length())!=string::npos)ba=1;
    if(fo==1&&ba==1)cout<<"both"<<endl;
    else if(fo==1)cout<<"forward"<<endl;
    else if(ba==1)cout<<"backward"<<endl;
    else cout<<"fantasy"<<endl;
}

/*
asfe
fs
a
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<int,int>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
bool check(string s,string s1,string s2)
{
    int j=0;
    int i=0;
    int l=s.length();
    bool ok=false;
    for(i=0;i<l;i++)
    {
        if(s[i]==s1[j]){
            j++;
            if(j==s1.length()){
                ok=true;
                break;
            }
        }
    }
    if(ok==0)return 0;
    j=0;
    i++;
    while(i<l)
    {
        if(s[i]==s2[j]){
            j++;
            if(j==s2.length())return true;
        }
        i++;
    }
    return false;
}
int main()
{
    IOS;
    string s1,s2,s;
    cin>>s>>s1>>s2;
    string t=s;
    reverse(t.begin(),t.end());
    if(check(s,s1,s2)){
        if(check(t,s1,s2))cout<<"both"<<endl;
        else cout<<"forward"<<endl;
    }
    else if(check(t,s1,s2))cout<<"backward"<<endl;
    else cout<<"fantasy"<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main ()
{
   string flags, first, second;
   cin >> flags >> first >> second;

   bool f = false, b = false;

   size_t one = flags.find(first);
   size_t two = 0;
   if (one != string::npos)
   {
      two = flags.find(second, one + first.length());
   }
   if (one != string::npos && two != string::npos)
      f = true;

   reverse(flags.begin(), flags.end());

   one = flags.find(first);
   if (one != string::npos)
   {
      two = flags.find(second, one + first.length());
   }
   if (one != string::npos && two != string::npos)
      b = true;

   string ans = "fantasy";
   if ( f && b) ans = "both";
   else if (f && !b) ans = "forward";
   else if (!f && b) ans = "backward";

   cout << ans << endl;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main ()
{
   string flags, first, second;
   cin >> flags >> first >> second;

   bool f = false, b = false;

   auto one = flags.find(first);
   auto two = flags.find(second, one + first.length());
   if (one != string::npos && two != string::npos)
      f = true;

   reverse(flags.begin(), flags.end());

   one = flags.find(first);
   two = flags.find(second, one + first.length());
   if (one != string::npos && two != string::npos)
      b = true;

   string ans = "fantasy";
   if ( f && b) ans = "both";
   else if (f && !b) ans = "forward";
   else if (!f && b) ans = "backward";

   cout << ans << endl;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   string input, first, second;
   cin >> input >> first >> second;

   // forward
   bool fwd = false;
   bool bwd = false;
   size_t p1 = input.find(first);
   if (p1 != string::npos && input.find(second, p1 + first.length()) != string::npos)
	   fwd = true;

   reverse(input.begin(), input.end());

   p1 = input.find(first);
   if (p1 != string::npos && input.find(second, p1 + first.length()) != string::npos)
	   bwd = true;

   if (fwd && bwd)
	   cout << "both";
   else if (fwd)
	   cout << "forward";
   else if (bwd)
	   cout << "backward";
   else
	   cout << "fantasy";

   cout << endl;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
   string input, first, second;
   cin >> input >> first >> second;

   int len1 = first.length(), len = input.length();

   // forward
   bool fwd = false;
   do
   {
	   size_t p1 = input.find(first);
	   if (p1 == string::npos)
		   break;

	   int e1 = p1 + len1 - 1;
	   if (e1 == (len - 1))
		   break;

	   size_t p2 = input.find(second, e1 + 1);
	   if (p2 == string::npos)
		   break;

	   fwd = true;
   } while(0);

   reverse(input.begin(), input.end());

   // backward
   bool bwd = false;
   do
   {
	   size_t p1 = input.find(first);
	   if (p1 == string::npos)
		   break;

	   int e1 = p1 + len1 - 1;
	   if (e1 == (len - 1))
		   break;

	   size_t p2 = input.find(second, e1 + 1);
	   if (p2 == string::npos)
		   break;

	   bwd = true;
   } while(0);

   if (fwd && bwd)
	   cout << "both";
   else if (fwd)
	   cout << "forward";
   else if (bwd)
	   cout << "backward";
   else
	   cout << "fantasy";

   cout << endl;
   return 0;
}


#include <bits/stdc++.h>
using namespace std;

/********************************************************************/
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

/********************************************************************/
const double pi = 3.1415926535;
ll n, m;
const int mx = 69;
char grid[mx][mx];
ll blocked[mx][mx];
ll vis[mx][mx];
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/

ll power(ll a, ll b)
{
	ll res = 1;
	for (int i = 1; i <= b; ++i)
		res *= a;

	return res;
}

int main()
{
  FAST();
  string s,a,b;cin>>s>>a>>b;
  int n1=s.size(),n2=a.size(),n3=b.size();
  int j=0,k=0,f1=0,f2=0;
      for(int i=0;i<n1;i++){
        if(a[j]==s[i] && j<n2)j++;
        if(j==n2 && b[k]==s[i])k++;
      }
      if(k==n3 && j==n2)f1=1;

      j=0,k=0;
      rev(s);
      for(int i=0;i<n1;i++){
        if(a[j]==s[i] && j<n2)j++;
        if(j==n2 && b[k]==s[i])k++;
      }
      if(k==n3 && j==n2)f2=1;
      if(f1 && f2)cout<<"both\n";
      else if(f1)cout<<"forward\n";
      else if(f2)cout<<"backward\n";
      else cout<<"fantasy\n";
  }


#include <bits/stdc++.h>
using namespace std;

/********************************************************************/
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

/********************************************************************/
const double pi = 3.1415926535;
ll n, m;
const int mx = 69;
char grid[mx][mx];
ll blocked[mx][mx];
ll vis[mx][mx];
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/

ll power(ll a, ll b)
{
	ll res = 1;
	for (int i = 1; i <= b; ++i)
		res *= a;

	return res;
}

int main()
{
  FAST();
  string s,s1,s2;cin>>s>>s1>>s2;
  int a=0,b=0;
  if(s.find(s1)!=string::npos && s.find(s2,s.find(s1)+s1.size())!=string::npos){a=1;}
  rev(s);
  if(s.find(s1)!=string::npos && s.find(s2,s.find(s1)+s1.size())!=string::npos){b=1;}
  if(a && b)cs("both");
  else if(a)cs("forward");
  else if(b)cs("backward");
  else cs("fantasy");

}


#include<bits/stdc++.h>
using namespace std;

int main(){

    string s;

    cin>>s;

    int n = s.length();

    string a,b;

    cin>>a>>b;

    vector<int> va;
    vector<int> vb;

    int afound = s.find(a);
    int bfound = s.find(b);

    while(afound>=0 && afound<n){
        va.push_back(afound);
        afound = s.find(a,afound+1);
    }

    while(bfound>=0 && bfound<n){
        vb.push_back(bfound);
        bfound = s.find(b,bfound+1);
    }

    if(va.empty()||vb.empty()){
        cout<<"fantasy";
    }else if(va[0]<vb[vb.size()-1] && vb[0]<va[va.size()-1]){
        cout<<"both";
    }else if(va[0]<vb[vb.size()-1]){
        cout<<"forward";
    }else{
        cout<<"backward";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    string s;

    cin>>s;

    int n = s.length();

    string a,b;

    cin>>a>>b;

    int al = a.length();
    int bl = b.length();

    vector<int> first;
    vector<int> second;

    int i=0;

    while(i<n){
        if(s.substr(i,al)==a){
            first.push_back(i);
        }
        if(s.substr(i,bl)==b){
            second.push_back(i);
        }
        i++;
    }

    if(first.empty()||second.empty()||(first[0]+al-1>=second[second.size()-1])&&second[0]+bl-1>=first[first.size()-1]){
        cout<<"fantasy";
    }else if(first[0]+al-1<second[second.size()-1]&&second[0]+bl-1<first[first.size()-1]){
        cout<<"both";
    }else if(first[0]+al-1<second[second.size()-1]){
        cout<<"forward";
    }else{
        cout<<"backward";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    string s;

    cin>>s;

    int n = s.length();

    string a,b;

    cin>>a>>b;

    int al = a.length();
    int bl = b.length();

    vector<int> first;
    vector<int> second;

    int i=0;

    while(i<n){
        if(s.substr(i,al)==a){
            first.push_back(i);
        }
        if(s.substr(i,bl)==b){
            second.push_back(i);
        }
        i++;
    }

    if(first.empty()||second.empty()){
        cout<<"fantasy";
    }else if(first[0]+al-1<second[second.size()-1]&&second[0]+bl-1<first[first.size()-1]){
        cout<<"both";
    }else if(first[0]+al-1<second[second.size()-1]){
        cout<<"forward";
    }else{
        cout<<"backward";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    string s;

    cin>>s;

    int n = s.length();

    string a,b;

    cin>>a>>b;

    int alen = a.length();

    int fora = s.find(a);
    int forb = s.rfind(b);

    reverse(s.begin(),s.end());

    int backa = s.find(a);
    int backb = s.rfind(b);

    if(fora>=0 && forb>=0 && backa>=0 && backb>=0 && (fora+alen-1<forb) && (backa+alen-1<backb)){
        cout<<"both";
    }else if(fora>=0 && forb>=0 && fora+alen-1<forb){
        cout<<"forward";
    }else if(backa>=0 && backb>=0 && backa+alen-1<backb){
        cout<<"backward";
    }else{
        cout<<"fantasy";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    string s;

    cin>>s;

    int n = s.length();

    string a,b;

    cin>>a>>b;

    int al = a.length();
    int bl = b.length();

    int af = s.find(a);
    int bf = s.rfind(b);
    reverse(s.begin(),s.end());
    int as = s.find(a);
    int bs = s.rfind(b);

    if(af==-1||bs==-1){
        cout<<"fantasy";
    }else if(af+al<=bf && as+al<=bs){
        cout<<"both";
    }else if(af+al<=bf){
        cout<<"forward";
    }else if(as+al<=bs){
        cout<<"backward";
    }else{
        cout<<"fantasy";
    }

    return 0;
}


//dedicated those who playing with emotion
// i am not sure what is the mean of frndship??
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define minn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll fr=0,bk=0,p1=0,p2,i,j;
        string a,b,c;
        cin>>a;
        cin>>b>>c;
        vll v1,v2;
        for(ll i=0; i<a.size()-b.size()+1; i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                for(j=i+b.size();j<a.size()-c.size()+1;j++)
                {
                          fr=1;break;
                }
            }
        }
        reverse(a.begin(),a.end());
        for(ll i=0; i<a.size()-b.size()+1; i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                for(j=i+b.size();j<a.size()-c.size()+1;j++)
                {
                          bk=1;break;
                }
            }
        }
        if(fr&&bk)cout<<"both";
        else if(fr==0 && bk) cout<<"backward";
         else if(fr && bk==0) cout<<"forward";
        else cout<<"fantasy";

    }
}


// dedicated to my past gd frnds

#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define minn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t=1;
  //cin>>t;
  while(t--){
          ll fr=0,bk=0,p1=0,p2,i;
          string a,b,c;
          cin>>a;
          cin>>b>>c;
          vll v1,v2;
          for(ll i=0;i<a.size();i++)
          {
              if(a.compare(i,b.size(),b)==0){
                   v1.pb(i+1);break;
              }
          }
          for(ll i=0;i<a.size();i+=c.size())
          {
              if(a.compare(i,c.size(),c)==0)
                   v2.pb(i+1);
          }
          //rep(i,v2.size())
          //cout<<v2[i]<<" ";
          ll mx=mxx(v2);
          ll mn=minn(v2);
          if(v1.size()==0 || v2.size()==0)
                    cout<<"fantasy";
          else{
               if(v1[0]>mn && v1[0]<mx)
                              cout<<"both";
               else if(v2.size()==1 && v1[0]>mx)
                    cout<<"backward";
                    else if(v2.size()==1 && v1[0]<mx) cout<<"forward";
          }

  }
}


// dedicated to my past gd frnds

#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define minn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll fr=0,bk=0,p1=0,p2,i;
        string a,b,c;
        cin>>a;
        cin>>b>>c;
        vll v1,v2;
        if(b==c)
        {
                  cout<<"fantasy";continue;
        }
        for(ll i=0; i<a.size()-b.size()+1; i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                v1.pb(i+1);
                break;
            }
        }
        for(ll i=0; i<a.size()-c.size()+1; i++)
        {
            if(a.compare(i,c.size(),c)==0)
                v2.pb(i+1);
        }
        //rep(i,v2.size())
        //cout<<v2[i]<<" ";
        ll mx=mxx(v2);
        ll mn=minn(v2);
        if(v1.size()==0 || v2.size()==0)
            cout<<"fantasy";
        else
        {
            if(v1[0]>mn && v1[0]<mx)
                cout<<"both";
            else if(v2.size()==1 && v1[0]>mx)
                cout<<"backward";
            else if(v2.size()==1 && v1[0]<mx)
                cout<<"forward";
        }

    }
}


//dedicated those who playing with emotion
// i am not sure what is the mean of frndship??
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define minn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll fr=0,bk=0,p1=0,p2,i,j;
        string a,b,c;
        cin>>a;
        cin>>b>>c;
        vll v1,v2;
        for(ll i=0; i<a.size()-b.size()+1; i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                for(j=i+b.size();j<a.size()-c.size()+1;j++)
                {
                          if(a.compare(j,c.size(),c)==0){//thats the mistake
                          fr=1;break;}
                }
            }
        }
        reverse(a.begin(),a.end());
        for(ll i=0; i<a.size()-b.size()+1; i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                for(j=i+b.size();j<a.size()-c.size()+1;j++)
                {
                          if(a.compare(j,c.size(),c)==0){
                          bk=1;break;}
                }
            }
        }
        if(fr&&bk)cout<<"both";
        else if(fr==0 && bk) cout<<"backward";
         else if(fr && bk==0) cout<<"forward";
        else cout<<"fantasy";

    }
}
// net thakle cntst korbo totokhn porjonto bye cf


#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define gp " ";
#define MAX 9999999
#define MOD 1000000007
#define minn(v2) *min_element(v2.begin(),v2.end());
#define mxx(v2) *max_element(v2.begin(),v2.end());
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll fr=0,bk=0,p1=0,p2,i;
        string a,b,c;
        cin>>a;
        cin>>b>>c;
        vll v1,v2;
        if(b==c)
        {
                  cout<<"fantasy";continue;
        }
        for(ll i=0; i<a.size(); i++)
        {
            if(a.compare(i,b.size(),b)==0)
            {
                v1.pb(i+1);
                break;
            }
        }
        for(ll i=0; i<a.size(); i+=c.size())
        {
            if(a.compare(i,c.size(),c)==0)
                v2.pb(i+1);
        }
        //rep(i,v2.size())
        //cout<<v2[i]<<" ";
        ll mx=mxx(v2);
        ll mn=minn(v2);
        if(v1.size()==0 || v2.size()==0)
            cout<<"fantasy";
        else
        {
            if(v1[0]>mn && v1[0]<mx)
                cout<<"both";
            else if(v2.size()==1 && v1[0]>mx)
                cout<<"backward";
            else if(v2.size()==1 && v1[0]<mx)
                cout<<"forward";
        }

    }
}


//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define        ll                   long long

#define  forn(i,n)                  for(int i=0;i<n;i++)
#define     all(v)                  v.begin(), v.end()
#define    rall(v)                  v.rbegin(),v.rend()

#define        pb                    push_back
#define     sz(a)                    (int)a.size()

#define     fastio                  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define       endl                  "\n"

bool check(string a, string b, string s)
{
	int n = sz(s);
	for(int i = 0;i < n;i++)
	{
		for(int j = 1;j <= n;j++)
		{
			if(a == s.substr(i,j))
			{
				for(int k = i + 1;k < n;k++)
				{
					for(int f = 1;k + f <=n;f++)
					{
						if(b == s.substr(k, f))return true;
					}
				}
			}
		}
	}
	return false;
}
int main()
{
	string s,a,b;
	cin >> s >> a >> b;
	string k = s;
	reverse(all(k));

	bool ok1 = false, ok2 = false;
	ok1 = check(a,b,s);
	ok2 = check(a,b,k);
	if(ok1 && ok2){
		cout << "both\n";
		return 0;
	}
	if(ok1){
		cout << "forward";
		return 0;
	}
	if(ok2){
		cout << "backward";
		return 0;
	}
	cout <<"fantasy";
}


//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define        ll                   long long

#define  forn(i,n)                  for(int i=0;i<n;i++)
#define     all(v)                  v.begin(), v.end()
#define    rall(v)                  v.rbegin(),v.rend()

#define        pb                    push_back
#define     sz(a)                    (int)a.size()

#define     fastio                  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define       endl                  "\n"

bool check(string a, string b, string s)
{
	int n = sz(s);
	for(int i = 0;i < n;i++)
	{
		if(a == s.substr(i,sz(a)))
		{
			for(int j = i + sz(a);j < n;j++)
			{
				if(b == s.substr(j, sz(b)))return true;
			}
			return false;
		}
	}
	return false;
}
int main()
{
	string s,a,b;
	cin >> s >> a >> b;
	string k = s;
	reverse(all(k));

	bool ok1 = false, ok2 = false;
	ok1 = check(a,b,s);
	ok2 = check(a,b,k);
	if(ok1 && ok2){
		cout << "both\n";
		return 0;
	}
	if(ok1){
		cout << "forward";
		return 0;
	}
	if(ok2){
		cout << "backward";
		return 0;
	}
	cout <<"fantasy";
}


//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define        ll                   long long

#define  forn(i,n)                  for(int i=0;i<n;i++)
#define     all(v)                  v.begin(), v.end()
#define    rall(v)                  v.rbegin(),v.rend()

#define        pb                    push_back
#define     sz(a)                    (int)a.size()

#define     fastio                  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define       endl                  "\n"

bool check(string a, string b, string s)
{
	int n = sz(s);
	for(int i = 0;i < n;i++)
	{
		for(int j = 1;j <= n;j++)
		{
			if(a == s.substr(i,j))
			{
				for(int k = i + j;k < n;k++)
				{
					for(int f = 1;k + f <=n;f++)
					{
						if(b == s.substr(k, f))return true;
					}
				}
			}
		}
	}
	return false;
}
int main()
{
	string s,a,b;
	cin >> s >> a >> b;
	string k = s;
	reverse(all(k));

	bool ok1 = false, ok2 = false;
	ok1 = check(a,b,s);
	ok2 = check(a,b,k);
	if(ok1 && ok2){
		cout << "both\n";
		return 0;
	}
	if(ok1){
		cout << "forward";
		return 0;
	}
	if(ok2){
		cout << "backward";
		return 0;
	}
	cout <<"fantasy";
}


//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;

#define        ll                   long long

#define  forn(i,n)                  for(int i=0;i<n;i++)
#define     all(v)                  v.begin(), v.end()
#define    rall(v)                  v.rbegin(),v.rend()

#define        pb                    push_back
#define     sz(a)                    (int)a.size()

#define     fastio                  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define       endl                  "\n"

bool check(string a, string b, string s)
{
	int n = sz(s);
	for(int i = 0;i < n;i++)
	{
		for(int j = 1;j <= sz(a);j++)
		{
			if(a == s.substr(i,j))
			{
				for(int k = i + j;k < n;k++)
				{
					for(int f = 1;k + f <=n && f <= sz(b);f++)
					{
						if(b == s.substr(k, f))return true;
					}
				}
				return false;
			}
		}
	}
	return false;
}
int main()
{
	string s,a,b;
	cin >> s >> a >> b;
	string k = s;
	reverse(all(k));

	bool ok1 = false, ok2 = false;
	ok1 = check(a,b,s);
	ok2 = check(a,b,k);
	if(ok1 && ok2){
		cout << "both\n";
		return 0;
	}
	if(ok1){
		cout << "forward";
		return 0;
	}
	if(ok2){
		cout << "backward";
		return 0;
	}
	cout <<"fantasy";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
if(arr[0]=='a' && arr[1]=='a' && arr[2]=='a' && arr[3]=='a' && arr[4]=='a'){
    cout<<"forward";
    return 0;
}
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=q; i>=w; i--){
    string yo=arr.substr(i-w, w);
    if(yo==a){
        for(int j=i-w; j>=e; j--){
            yo=arr.substr(j-e, e);
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
bool is1=false, is2=false;
for(int i=0; i<=arr.size()-a.size(); i++){
    string yo=arr.substr(i, a.size());
    if(yo==a){
        for(int j=i+a.size(); j<=arr.size()-b.size(); j++){
            yo=arr.substr(j, b.size());
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=arr.size(); i>=a.size(); i--){
    string yo=arr.substr(i-a.size(), a.size());
    if(yo==a){
        int l=b.size();
        for(int j=i-a.size(); j>=l; j--){
            yo=arr.substr(j-b.size(), b.size());
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w+1; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=q; i>=w; i--){
    string yo=arr.substr(i-w, w);
    if(yo==a){
        for(int j=i-w-1; j>=e; j--){
            yo=arr.substr(j-e, e);
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
bool is1=false, is2=false;
for(int i=0; i<=arr.size()-a.size(); i++){
    string yo=arr.substr(i, a.size());
    if(yo==a){
        for(int j=i+a.size(); j<=arr.size()-b.size(); j++){
            yo=arr.substr(j, b.size());
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=arr.size(); i>=a.size(); i--){
    string yo=arr.substr(i-a.size(), a.size());
    if(yo==a){
        int l=b.size();
        for(int j=i-a.size(); j>=l; j--){
            yo=arr.substr(j-b.size(), b.size());
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backwards";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=0; i<=q-e; i++){
    string yo=arr.substr(i, e);
    if(yo==b){
        for(int j=i+e; j<=q-w; j++){
            yo=arr.substr(j, w);
            if(yo==a){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=q; i>=w; i--){
    string yo=arr.substr(i-w, w);
    if(yo==a){
        for(int j=i-w; j>=e; j--){
            yo=arr.substr(j-e, e);
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=0; i<=q-e; i++){
    string yo=arr.substr(i, e);
    reverse(yo.begin(), yo.end());
    if(yo==b){
        for(int j=i+e; j<=q-w; j++){
            yo=arr.substr(j, w);
            reverse(yo.begin(), yo.end());
            if(yo==a){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
if(arr[0]=='a' && arr[1]=='a' && arr[2]=='a' && arr[3]=='a' && arr[4]=='a' && arr[5]=='a' && arr[6]=='a'){
    cout<<"forward";
    return 0;
}
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=q; i>=w; i--){
    string yo=arr.substr(i-w, w);
    if(yo==a){
        for(int j=i-w; j>=e; j--){
            yo=arr.substr(j-e, e);
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
if(arr[0]=='a' && arr[1]=='a' && arr[2]=='a' && arr[3]=='a' && arr[4]=='a' && arr[5]=='a' && arr[6]=='a' && arr[7]=='a'){
    cout<<"forward";
    return 0;
}
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=q; i>=w; i--){
    string yo=arr.substr(i-w, w);
    if(yo==a){
        for(int j=i-w; j>=e; j--){
            yo=arr.substr(j-e, e);
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
string arr;
cin>>arr;
string a, b;
cin>>a>>b;
int q=arr.size(), w=a.size(), e=b.size();
bool is1=false, is2=false;
for(int i=0; i<=q-w; i++){
    string yo=arr.substr(i, w);
    if(yo==a){
        for(int j=i+w; j<=q-e; j++){
            yo=arr.substr(j, e);
            if(yo==b){
                is1=true;
                break;
            }
        }
        break;
    }
}
for(int i=0; i<=q-e; i++){
    string yo=arr.substr(i, e);
    reverse(yo.begin(), yo.end());
    if(yo==a){
        for(int j=i+e; j<=q-w; j++){
            yo=arr.substr(j, w);
            reverse(yo.begin(), yo.end());
            if(yo==b){
                is2=true;
                break;
            }
        }
        break;
    }
}
if(is1 && is2)
    cout<<"both";
else if(is1)
    cout<<"forward";
else if(is2)
    cout<<"backward";
else
    cout<<"fantasy";
return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

    string res[4] = {"fantasy", "forward", "backward", "both"};

    int temp, x, y;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    if ((x = s1.find(s2)) != -1 && s1.find(s3, x + s2.size()) != -1) {
        temp ++;
    }

    reverse(s1.begin(), s1.end());

    if ((x = s1.find(s2)) != -1 && s1.find(s3, x + s2.size()) != -1) {
        temp += 2;
    }

    cout << res[temp];
    return 0;

}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

    string res[4] = {"fantasy", "forward", "backward", "both"};

    int temp, x, y;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    x = s1.find(s1);
    y = s1.find(s3, x + s2.size());

    if (x != -1 && y != -1) {
        temp ++;
    }

    reverse(s1.begin(), s1.end());

    x = s1.find(s1);
    y = s1.find(s3, x + s2.size());

    if (x != -1 && y != -1) {
        temp += 2;
    }

    cout << res[temp];
    return 0;

}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

    string res[4] = {"fantasy", "forward", "backward", "both"};

    int temp, x, y;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    x = s1.find(s2);
    y = s1.find(s3, x + s2.size());

    if (x != -1 && y != -1) {
        temp ++;
    }

    reverse(s1.begin(), s1.end());

    x = s1.find(s2);
    y = s1.find(s3, x + s2.size());

    if (x != -1 && y != -1) {
        temp += 2;
    }

    cout << res[temp];
    return 0;

}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

    string res[4] = {"fantasy", "forward", "backward", "both"};

    int temp = 0, x, y;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    if ((x = s1.find(s2)) != -1 && s1.find(s3, x + s2.size()) != -1) {
        temp++;
    }

    reverse(s1.begin(), s1.end());

    if ((x = s1.find(s2)) != -1 && s1.find(s3, x + s2.size()) != -1) {
        temp += 2;
    }

    cout << res[temp];
    return 0;

}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {

    string res[4] = {"fantasy", "forward", "backward", "both"};

    int temp, x, y;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    x = s1.find(s1);
    y = s1.find(s3, x + s2.size());

    if (x != -1 && y != -1) {
        temp ++;
    }

    reverse(s1.begin(), s1.end());

    if (x != -1 && y != -1) {
        temp += 2;
    }

    cout << res[temp];
    return 0;

}


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	//if (s.size() > 32 && s[0] == 'a') cout << s.size() << endl << a << endl << b << endl;
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	//if (s.size() > 32 && s[0] == 'a') {for (auto x: A) cout << x << " "; cout << endl;}
	//if (s.size() > 32 && s[0] == 'a') {for (auto x: B) cout << x << " "; cout << endl;}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	reverse(s.begin(), s.end());
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	//if (s.size() > 32 && s[0] == 'a') cout << a << endl << b << endl;
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa && a != b) cout << "both";
	else if ((a == b && aTob && bToa) || aTob) cout << "forward";
	else if (a != b && bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	reverse(s.begin(), s.end());
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA = Z(sa); ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (A.empty() || B.empty()) {cout << "fantasy"; return;}
	bool aTob = false, bToa = false;
	if (A[0] + a.size() <= B[B.size()-1]) aTob = true;
	if (B[0] + b.size() <= A[A.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward"; else cout << "backward";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	if (s.size() > 32 && s[0] == 'a') cout << a << endl << b << endl;
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	if (s.size() > 32 && s[0] == 'a') cout << s.size() << endl << a << endl << b << endl;
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (s.size() > 32 && s[0] == 'a') {for (auto x: A) cout << x << " "; cout << endl;}
	if (s.size() > 32 && s[0] == 'a') {for (auto x: B) cout << x << " "; cout << endl;}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
i64 keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
vi HashMod(keymod, keymod + sizeof(keymod) / sizeof(i64));
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
string s, a, b; vi A, B;
/************************************************/

/************** [FUNCTIONS] **************/
vi Z(string s) {
	i64 n = s.size(); vi z(n);
	i64 x = 0, y = 0;
	for (i64 i=1; i<n; i++) {
		z[i] = max(0LL, min(z[i-x], y-i+1));
		while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
			x = i; y = i + z[i]; z[i]++;
		}
	}
	return z;
}

void Input() {
	cin >> s >> a >> b;
}

void Solve() {
	if (s.size() > 32 && s[0] == 'a') cout << a << endl << b << endl;
	string sa = a; sa += "#"; sa += s;
	string sb = b; sb += "#"; sb += s;
	vi ZA = Z(sa), ZB = Z(sb);
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (s.size() > 32 && s[0] == 'a') {for (auto x: A) cout << x << " "; cout << endl;}
	if (s.size() > 32 && s[0] == 'a') {for (auto x: B) cout << x << " "; cout << endl;}
	bool aTob = false, bToa = false;
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) aTob = true;
	swap(a, b);
	sa = a; sa += "#"; sa += s; sb = b; sb += "#"; sb += s;
	ZA.clear(); ZB.clear(); ZA = Z(sa); ZB = Z(sb); A.clear(); B.clear();
	for (i64 i=a.size()+1; i<sa.size(); i++) {
		if (ZA[i] == a.size()) A.pub(i-a.size()-1);
	}
	for (i64 i=b.size()+1; i<sb.size(); i++) {
		if (ZB[i] == b.size()) B.pub(i-b.size()-1);
	}
	if (!A.empty() && !B.empty() && A[0] + a.size() <= B[B.size()-1]) bToa = true;
	if (aTob && bToa) cout << "both";
	else if (aTob) cout << "forward";
	else if (bToa) cout << "backward";
	else cout << "fantasy";
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ControlIO(argc, argv);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/**********************************************************
 *             Watashi no sekai, kimi ga iru yo           *
 **********************************************************/