#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
bool can(string s, string a, string b) {
  int f = -1, l = -1;
  for (int i = 0; i < int(s.size()); i++) {
    if (s.substr(i, a.size()) == a) {
      if (f == -1) f = i;
    }
    if (s.substr(i, b.size()) == b) {
      l = i;
    }
  }
  return (f != -1 && l != -1 && f + a.size() <= l);
}
int main() {
  string s;
  string a, b;
  getline(cin, s);
  getline(cin, a);
  getline(cin, b);
  bool f1 = can(s, a, b);
  reverse(s.begin(), s.end());
  bool f2 = can(s, a, b);
  if (f1) {
    if (f2)
      printf("both\n");
    else
      printf("forward\n");
  } else {
    if (f2)
      printf("backward\n");
    else
      printf("fantasy\n");
  }
  return 0;
}
