#include <bits/stdc++.h>
using namespace std;
int main() {
  string A, B, opp, now;
  bool fw = false;
  bool bw = false;
  int x = 0;
  cin >> now;
  cin >> A;
  cin >> B;
  opp = now;
  string input = now;
  for (int i = now.length() - 1; i >= 0; i--) {
    opp.at(x) = now.at(i);
    x++;
  }
  if (A.length() + B.length() > now.length())
    cout << "fantasy" << endl;
  else {
    if ((now.find(A) < now.length()) &&
        (now.erase(0, now.find(A) + A.length()).find(B) < now.length()))
      fw = true;
    if (opp.find(A) < opp.length() &&
        opp.erase(0, opp.find(A) + A.length()).find(B) < opp.length())
      bw = true;
    if (bw & !fw) cout << "backward" << endl;
    if (fw & !bw) cout << "forward" << endl;
    if (fw && bw) cout << "both" << endl;
    if (!fw && !bw) cout << "fantasy" << endl;
  }
  return 0;
}
