#include <bits/stdc++.h>
using namespace std;
bool GO(string s, string Go, string Back) {
  int Len = s.length(), LenGo = Go.length(), LenBack = Back.length();
  for (int i = 0; i <= Len - LenGo - LenBack; i++) {
    if (s.substr(i, LenGo) == Go) {
      for (int j = i + LenGo; j <= Len - LenBack; j++) {
        if (s.substr(j, LenBack) == Back) return true;
      }
      return false;
    }
  }
  return false;
}
bool BACK(string s, string Go, string Back) {
  int Len = s.length(), LenGo = Go.length(), LenBack = Back.length();
  reverse(s.begin(), s.end());
  for (int i = 0; i <= Len - LenGo - LenBack; i++) {
    if (s.substr(i, LenGo) == Go) {
      for (int j = i + LenGo; j <= Len - LenBack; j++) {
        if (s.substr(j, LenBack) == Back) return true;
      }
      return false;
    }
  }
  return false;
}
int main() {
  string s, Go, Back;
  cin >> s;
  cin >> Go;
  cin >> Back;
  if (GO(s, Go, Back) && BACK(s, Go, Back))
    cout << "both" << endl;
  else if (!GO(s, Go, Back) && BACK(s, Go, Back))
    cout << "backward" << endl;
  else if (GO(s, Go, Back) && !BACK(s, Go, Back))
    cout << "forward" << endl;
  else
    cout << "fantasy" << endl;
  return 0;
}
