#include <bits/stdc++.h>
using namespace std;
string str;
string fstr;
string sstr;
int main() {
  unsigned in, fin;
  int f_endpos, f_length, s_length;
  int frward, revese;
  while (cin >> str) {
    cin >> fstr >> sstr;
    frward = 0;
    revese = 0;
    in = str.find(fstr);
    fin = str.find(sstr);
    if (in == string::npos) {
      frward = 0;
    } else {
      f_length = fstr.size();
      f_endpos = str.find(fstr) + f_length - 1;
      s_length = sstr.size();
      if (s_length + f_endpos > (str.size() - 1)) {
        frward = 0;
      } else if ((str.substr(f_endpos + 1)).find(sstr) != string::npos) {
        frward = 1;
      } else
        frward = 0;
    }
    str = string(str.rbegin(), str.rend());
    fin = str.find(sstr);
    in = str.find(fstr);
    if (in == string::npos) {
      revese = 0;
    } else {
      f_length = fstr.size();
      f_endpos = in + f_length - 1;
      s_length = sstr.size();
      if (s_length + f_endpos > (str.size() - 1)) {
        revese = 0;
      } else if ((str.substr(f_endpos + 1)).find(sstr) != string::npos) {
        revese = 1;
      } else
        revese = 0;
    }
    if (frward == 1 && revese == 1)
      cout << "both\n";
    else if (frward == 1 && revese == 0)
      cout << "forward\n";
    else if (frward == 0 && revese == 1)
      cout << "backward\n";
    else if (frward == 0 && revese == 0)
      cout << "fantasy\n";
  }
  return 0;
}
