#include <bits/stdc++.h>
using namespace std;
template <typename T>
T nextInt() {
  int x = 0, p = 1;
  char c;
  do {
    c = getchar();
  } while (c <= 32);
  if (c == '-') {
    p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c - '0');
    c = getchar();
  }
  return x * p;
}
const int maxN = (int)3e2 + 10;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const long long LLINF = (long long)1e18;
string s;
string a, b;
string rev(string s) {
  reverse(s.begin(), s.end());
  return s;
}
bool equal(const string &a, const string &b) { return a == b; }
int getLeftPos(const string &a, const string &b) {
  int n = (int)a.length();
  int m = (int)b.length();
  for (int i = 0; i < m; ++i) {
    if (i + n >= m) return +100500;
    if (equal(b.substr(i, n), a)) {
      return i + n - 1;
    }
  }
}
int getRightPos(const string &a, const string &b) {
  int n = (int)a.length();
  int m = (int)b.length();
  for (int i = m - 1; i >= 0; --i) {
    if (i - n + 1 < 0) return -100500;
    if (equal(b.substr(i - n + 1, n), a)) {
      return i - n + 1;
    }
  }
}
int main() {
  cin >> s;
  cin >> a;
  cin >> b;
  bool canForward = false;
  bool canBackward = false;
  int leftPos = getLeftPos(a, s);
  int rightPos = getRightPos(b, s);
  if (leftPos < rightPos) {
    canForward = true;
  }
  int leftPosRev = getLeftPos(a, rev(s));
  int rightPosRev = getRightPos(b, rev(s));
  if (leftPosRev < rightPosRev) {
    canBackward = true;
  }
  if (canForward == true && canBackward == true) {
    puts("both");
  }
  if (canForward == false && canBackward == false) {
    puts("fantasy");
  }
  if (canForward == false && canBackward == true) {
    puts("backward");
  }
  if (canForward == true && canBackward == false) {
    puts("forward");
  }
  return 0;
}
