#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long int linf = 1LL << 50;
const double EPS = 1e-10;
int main(int argc, char const* argv[]) {
  string s, p[2];
  cin >> s >> p[0] >> p[1];
  bool atob = false, btoa = false;
  int at = -1;
  for (int i = (0); i < (s.size()); ++i) {
    bool flag = true;
    for (int j = (0); j < (p[0].size()); ++j) {
      if (s[i + j] != p[0][j]) flag = false;
    }
    if (flag) {
      at = i + p[0].size();
      break;
    }
  }
  if (at != -1) {
    for (int i = at; i + p[1].size() <= s.size(); i++) {
      bool flag = true;
      for (int j = (0); j < (p[1].size()); ++j) {
        if (s[i + j] != p[1][j]) flag = false;
      }
      if (flag) {
        atob = true;
        break;
      }
    }
  }
  at = -1;
  reverse(p[0].begin(), p[0].end());
  reverse(p[1].begin(), p[1].end());
  for (int i = (0); i < (s.size()); ++i) {
    bool flag = true;
    for (int j = (0); j < (p[1].size()); ++j) {
      if (s[i + j] != p[1][j]) flag = false;
    }
    if (flag) {
      at = i + p[1].size();
      break;
    }
  }
  if (at != -1) {
    for (int i = at; i + p[0].size() <= s.size(); i++) {
      bool flag = true;
      for (int j = (0); j < (p[0].size()); ++j) {
        if (s[i + j] != p[0][j]) flag = false;
      }
      if (flag) {
        btoa = true;
        break;
      }
    }
  }
  if (atob && btoa)
    cout << "both" << endl;
  else if (atob)
    cout << "forward" << endl;
  else if (btoa)
    cout << "backward" << endl;
  else
    cout << "fantasy" << endl;
  return 0;
}
