#include <bits/stdc++.h>
using namespace std;
string rev(string s) {
  char tmp;
  for (int i = 0; i < (s.size() / 2); i++) {
    tmp = s[i];
    s[i] = s[s.size() - i - 1];
    s[s.size() - i - 1] = tmp;
  }
  return s;
}
int main() {
  string s, a, b;
  const unsigned int max = -1;
  unsigned long long int pos = 0;
  int f = 0, se = 0;
  cin >> s >> a >> b;
  pos = s.find(a);
  if ((pos != max) && (s.find(b, pos + a.size()) != max)) {
    f = 1;
  }
  s = rev(s);
  pos = s.find(a);
  if ((pos != max) && (s.find(b, pos + a.size()) != max)) {
    se = 1;
  }
  if ((f == 1) && (se == 1)) {
    cout << "both";
  } else if ((f == 1) && (se == 0)) {
    cout << "forward";
  } else if ((f == 0) && (se == 1)) {
    cout << "backward";
  } else {
    cout << "fantasy";
  }
  return 0;
}
