#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool is_forward(const string &s, const string &a, const string &b) {
  int i = s.find(a);
  if (i != string::npos) {
    return s.find(b, i + a.length()) != string::npos;
  }
  return false;
}
void inout_train_and_peter(istream &in) {
  string colors;
  string before;
  string after;
  in >> colors >> before >> after;
  bool forward = is_forward(colors, before, after);
  reverse(colors.begin(), colors.end());
  bool backward = is_forward(colors, before, after);
  if (forward && backward) {
    cout << "both";
  } else if (forward) {
    cout << "forward";
  } else if (backward) {
    cout << "backward";
  } else {
    cout << "fantasy";
  }
}
int main() {
  ifstream in("test.txt");
  inout_train_and_peter(cin);
  return 0;
}
