#include <bits/stdc++.h>
using namespace std;
int main() {
  string reader;
  string flagA, flagB;
  size_t posic;
  bool forward;
  bool backward;
  cin >> reader >> flagA >> flagB;
  posic = reader.find(flagA, 0);
  if (posic != string::npos) {
    posic = reader.find(flagB, posic + flagA.size());
    if (posic != string::npos) {
      forward = true;
    } else {
      forward = false;
    }
  } else {
    forward = false;
  }
  reverse(reader.begin(), reader.end());
  posic = reader.find(flagA, 0);
  if (posic != string::npos) {
    posic = reader.find(flagB, posic + flagA.size());
    if (posic != string::npos) {
      backward = true;
    } else {
      backward = false;
    }
  } else {
    backward = false;
  }
  if (forward && backward) {
    cout << "both" << endl;
  } else {
    if (forward) {
      cout << "forward" << endl;
    } else {
      if (backward) {
        cout << "backward" << endl;
      } else {
        cout << "fantasy" << endl;
      }
    }
  }
  return 0;
}
