#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool ok(string const& a, string const& b, string const& c) {
  int p = a.find(b);
  if (p == -1) return false;
  p += b.size();
  return a.find(c, p) != -1;
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  string colors;
  string seen;
  string line;
  getline(cin, colors);
  getline(cin, seen);
  getline(cin, line);
  int q = ((!!ok(colors, seen, line)) << 1);
  reverse((colors).begin(), (colors).end());
  q |= !!ok(colors, seen, line);
  char const* msg[] = {"fantasy", "backward", "forward", "both"};
  printf("%s\n", msg[q]);
  return 0;
}
