#include <bits/stdc++.h>
using namespace std;
string s, a, b, st_rev, second;
vector<pair<int, int> > v_a, v_b;
inline void calc(string s, string a, vector<pair<int, int> > &v) {
  for (int i = 0; i <= s.size() - a.size(); i++) {
    second = "";
    for (int j = i; j < i + a.size(); j++) second += s[j];
    if (second == a) v.push_back(make_pair(i, i + a.size() - 1));
  }
}
int main() {
  cin >> s >> a >> b;
  for (int i = s.size() - 1; i >= 0; i--) st_rev += s[i];
  if (a.size() <= s.size()) calc(s, a, v_a);
  if (b.size() <= s.size()) calc(s, b, v_b);
  bool mark1 = 0;
  for (int i = 0; i < v_a.size(); i++)
    for (int j = 0; j < v_b.size(); j++)
      if (v_a[i].first < v_b[j].first && v_b[j].first > v_a[i].second) {
        mark1 = 1;
        break;
      }
  v_a.clear();
  v_b.clear();
  if (a.size() <= s.size()) calc(st_rev, a, v_a);
  if (b.size() <= s.size()) calc(st_rev, b, v_b);
  bool mark2 = 0;
  for (int i = 0; i < v_a.size(); i++)
    for (int j = 0; j < v_b.size(); j++)
      if (v_a[i].first < v_b[j].first && v_b[j].first > v_a[i].second) {
        mark2 = 1;
        break;
      }
  if (mark1 && mark2) {
    printf("both\n");
    return 0;
  }
  if (mark1 && !mark2) {
    printf("forward\n");
    return 0;
  }
  if (!mark1 && mark2) {
    printf("backward\n");
    return 0;
  }
  printf("fantasy\n");
  return 0;
}
