#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& first) {
  return first * first;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const double EPS = 1 - 9;
char TEMPORARY_CHAR;
const int INF = 1e9;
inline void input(int& a) {
  a = 0;
  while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') &&
         (TEMPORARY_CHAR != '-')) {
  }
  char neg = 0;
  if (TEMPORARY_CHAR == '-') {
    neg = 1;
    TEMPORARY_CHAR = getchar();
  }
  while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {
    a = 10 * a + TEMPORARY_CHAR - '0';
    TEMPORARY_CHAR = getchar();
  }
  if (neg) a = -a;
}
inline void out(int a) {
  if (!a) putchar('0');
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  char s[10];
  int i;
  for (i = 0; a; ++i) {
    s[i] = '0' + a % 10;
    a /= 10;
  }
  for (int j = (i)-1; j >= 0; j--) putchar(s[j]);
}
inline int nxt() {
  int(ret);
  input((ret));
  ;
  return ret;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string s, a, b;
  cin >> s >> a >> b;
  size_t pos;
  bool ok1 = true;
  pos = s.find(a);
  if (pos == string::npos) {
    ok1 = false;
  } else {
    pos += a.length();
    pos = s.find(b, pos);
    if (pos == string::npos) {
      ok1 = false;
    }
  }
  reverse((s).begin(), (s).end());
  bool ok2 = true;
  pos = s.find(a);
  if (pos == string::npos) {
    ok2 = false;
  } else {
    pos += a.length();
    pos = s.find(b, pos);
    if (pos == string::npos) {
      ok2 = false;
    }
  }
  if (ok1 && ok2) {
    cout << "both" << endl;
    return 0;
  }
  if (!ok1 && !ok2) {
    cout << "fantasy" << endl;
    return 0;
  }
  if (ok1)
    cout << "forward" << endl;
  else
    cout << "backward" << endl;
  return 0;
}
